打印
[STM32F4]

STM32429的DAC

[复制链接]
715|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
iliketolearn|  楼主 | 2018-10-10 12:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
各位同学好, 这两天弄STM32的DAC,发现输出不了可变电压。 我是看了手册,之后借鉴了一下开发板的教程,但是没有完全依照教程来做。 因为按到手册里面有说,如果不设置TEN, 那么,在写入到:
0: DAC channel1 trigger disabled and data written into the DAC_DHRx register are
transferred one APB1 clock cycle later to the DAC_DOR1 register

我想,那就不用触发模式。直接写入数据寄存器,让它自己动去转换成模拟电压。

下面是我的程序,请帮忙看看,是啥问题,多谢!
void Init_DAC(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        DAC_InitTypeDef DAC_InitStructure;
       
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
                                                                                          
        GPIO_InitStructure.GPIO_Pin =GPIO_Pin_5;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_Init(GPIOA, &GPIO_InitStructure);

       
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
   
        DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
        DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
        DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
        DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_4095;
       
        DAC_Init(DAC_Channel_2, &DAC_InitStructure);
       
        DAC_Cmd(DAC_Channel_2,ENABLE);
       
}

void Feed_DAC(unsigned int val)
{
        if(val>4096)
                val=4096;
       
        DAC_SetChannel2Data(DAC_Align_12b_R,val);
}
在Main函数里,先调用Init_DAC,然后调用Feed_DAC(4096);
沙发
iliketolearn|  楼主 | 2018-10-10 12:51 | 只看该作者
Bit 2 TEN1: DAC channel1 trigger enable
This bit is set and cleared by software to enable/disable DAC channel1 trigger.
0: DAC channel1 trigger disabled and data written into the DAC_DHRx register are
transferred one APB1 clock cycle later to the DAC_DOR1 register
1: DAC channel1 trigger enabled and data from the DAC_DHRx register are transferred
three APB1 clock cycles later to the DAC_DOR1 register
Note: When software trigger is selected, the transfer from the DAC_DHRx register to the
DAC_DOR1 register takes only one APB1 clock cycle.

使用特权

评论回复
板凳
wowu| | 2018-10-10 14:36 | 只看该作者
我的怎么没有你的这么麻烦啊

使用特权

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

本版积分规则

21

主题

36

帖子

1

粉丝