DAC这是为什么啊????

[复制链接]
3609|9
 楼主| win2000_li 发表于 2011-3-18 22:37 | 显示全部楼层 |阅读模式
DAC, TI, IO, ST, ni
本帖最后由 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)
{}
}


就是没有输出波形啊???????这是为什么呢????????

没有搞懂啊!!!!!
DMA.JPG
 楼主| win2000_li 发表于 2011-3-18 22:43 | 显示全部楼层
以下是调试时抓的图
dac.JPG
rcc.JPG
 楼主| win2000_li 发表于 2011-3-18 22:43 | 显示全部楼层
请大家指点...............
IJK 发表于 2011-3-19 11:03 | 显示全部楼层
建议先用ST提供的DAC例子试试。
ST_ARM 发表于 2011-3-19 15:37 | 显示全部楼层
// 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);
                       ^^^^^^^^这个正确么?
 楼主| win2000_li 发表于 2011-3-19 16:16 | 显示全部楼层
为什么不正确啊!!!
 楼主| win2000_li 发表于 2011-3-19 16:17 | 显示全部楼层
00179 /**
00180   * @brief  Configures the different GPIO ports.
00181   * @param  None
00182   * @retval None
00183   */
00184 void GPIO_Configuration(void)
00185 {
00186   GPIO_InitTypeDef GPIO_InitStructure;
00187
00188   /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically
00189      connected to the DAC converter. In order to avoid parasitic consumption,
00190      the GPIO pin should be configured in analog */
00191   GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4 | GPIO_Pin_5;
00192   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
00193   GPIO_Init(GPIOA, &GPIO_InitStructure);
00194 }
00195
00196 /**

这里是ST的例子啊。。。。。。。。。

文档上也是这么说得啊
 楼主| win2000_li 发表于 2011-3-20 17:22 | 显示全部楼层
自已顶一个...................
avrilwe 发表于 2011-4-26 15:23 | 显示全部楼层
一个是GPIOA,一个是,额,貌似没有GPIO_DAC这玩意啊。应该是PA4和PA5吧,两个DA通道。
seawwh 发表于 2011-4-26 15:40 | 显示全部楼层
你的GPIO_Mode_AIN 没有错,我也是这样使用的。
你是想用DMA工作吗?但是你好像根本就没有使用DMA的初始化代码。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

142

主题

718

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部