打印

DAC这是为什么啊????

[复制链接]
2561|9
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
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 (47.3 KB )

DMA.JPG
沙发
win2000_li|  楼主 | 2011-3-18 22:43 | 只看该作者
以下是调试时抓的图

dac.JPG (39.79 KB )

dac.JPG

rcc.JPG (85.54 KB )

rcc.JPG

使用特权

评论回复
板凳
win2000_li|  楼主 | 2011-3-18 22:43 | 只看该作者
请大家指点...............

使用特权

评论回复
地板
IJK| | 2011-3-19 11:03 | 只看该作者
建议先用ST提供的DAC例子试试。

使用特权

评论回复
5
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);
                       ^^^^^^^^这个正确么?

使用特权

评论回复
6
win2000_li|  楼主 | 2011-3-19 16:16 | 只看该作者
为什么不正确啊!!!

使用特权

评论回复
7
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的例子啊。。。。。。。。。

文档上也是这么说得啊

使用特权

评论回复
8
win2000_li|  楼主 | 2011-3-20 17:22 | 只看该作者
自已顶一个...................

使用特权

评论回复
9
avrilwe| | 2011-4-26 15:23 | 只看该作者
一个是GPIOA,一个是,额,貌似没有GPIO_DAC这玩意啊。应该是PA4和PA5吧,两个DA通道。

使用特权

评论回复
10
seawwh| | 2011-4-26 15:40 | 只看该作者
你的GPIO_Mode_AIN 没有错,我也是这样使用的。
你是想用DMA工作吗?但是你好像根本就没有使用DMA的初始化代码。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

142

主题

718

帖子

1

粉丝