本帖最后由 win2000_li 于 2011-3-18 22:40 编辑
const uint16_t Sine12bit[32] =
{
2047, 2447, 2831, 3185, 3498, 3750, 3939, 4056, 4095, 4056,
3939, 3750, 3495, 3185, 2831, 2447, 2047, 1647, 1263, 909,
599, 344, 155, 38, 0, 38, 155, 344, 599, 909, 1263, 1647
};
uint32_t DualSine12bit[32];
#define DAC_DHR12RD_Address 0x40007420
void RCC_Configuration(void)
{
// Enable GPIO_AFIO GPIOA
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);
// Enable DAC clock
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
/* TIM6 Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
/* DMA2 clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
// INPUT DAC AIN (PA4, PA5)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIO_DAC, &GPIO_InitStructure);
}
void test(void)
{
/* Init Structure definition */
DAC_InitTypeDef DAC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* TIM2 Configuration */
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 0x4;
TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* TIM2 TRGO selection */
TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);
/* DAC channel1 Configuration */
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Triangle;
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_4095;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
/* DAC channel2 Configuration */
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_4095;
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
/* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is
automatically connected to the DAC converter. */
DAC_Cmd(DAC_Channel_1, ENABLE);
/* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is
automatically connected to the DAC converter. */
DAC_Cmd(DAC_Channel_2, ENABLE);
/* Set DAC dual channel DHR12RD register */
DAC_SetDualChannelData(DAC_Align_12b_R, 4000, 2000);
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);
}
void main()
{
SystemInit();
RCC_Configuration();
test();
while(1)
{}
}
就是没有输出波形啊???????这是为什么呢????????
没有搞懂啊!!!!! |
|