野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 22478|回复: 9

关于dac的问题

[复制链接]
发表于 2013-5-7 23:12:46 | 显示全部楼层 |阅读模式
野火的板子有没有dac的例程?
回复

使用道具 举报

 楼主| 发表于 2013-5-8 14:28:05 | 显示全部楼层
我刚才测试了一下dac,
程序如下
/****main.c****/
#include "stm32f10x.h"
#include "dac.h"

int main()
{
        SystemInit();
        AnalogInit();
        DAC1_update(2047);
        DAC2_update(1023);
}

/*******dac.c******/
#include "dac.h"

void AnalogInit(void)
{
     DAC_InitTypeDef  DAC_InitStructure;
     GPIO_InitTypeDef GPIO_InitStructure;

       RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE);
       /* DAC Periph clock enable */
       RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
      
     /* Configure DAC channe1 output pin */
     GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
     GPIO_Init(GPIOA, &GPIO_InitStructure);

     /* Configure DAC channe1 output pin */
     GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_5;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
     GPIO_Init(GPIOA, &GPIO_InitStructure);

     
     /* DAC channel1 Configuration */
     DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
     DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
     DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;    //输出缓冲失能   
     DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_4095;

     DAC_Init(DAC_Channel_1, &DAC_InitStructure);

     /* DAC channel2 Configuration */
     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);

}

//端口1AD值更新
void DAC1_update(u16 ch1)
{
     ch1 = (ch1 <<4) & 0xfff0;
     /* Set DAC Channel1 DHR12L register */
     DAC_SetChannel1Data(DAC_Align_12b_L, ch1);

     /* Start DAC Channel1 conversion by software */
     DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
}

void DAC2_update(u16 ch2)
{
     ch2 = (ch2 <<4) & 0xfff0;
     /* Set DAC Channel2 DHR12L register */
     DAC_SetChannel2Data(DAC_Align_12b_L, ch2);

     /* Start DAC Channel1 conversion by software */
     DAC_SoftwareTriggerCmd(DAC_Channel_2, ENABLE);
}


发现用万用表测dac的输出值,那个值不对。野火的板子参考电压为3.3v,那输出结果2.80v和0.76v与预想值有偏差
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-8 14:28:51 | 显示全部楼层
求救求救!!!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-8 15:37:41 | 显示全部楼层
后来在多次测试中,发现dac的通道2是正常的,可是通道1的值就不正常
回复 支持 反对

使用道具 举报

发表于 2013-5-8 20:12:01 | 显示全部楼层
不好意思,没这模块代码
回复 支持 反对

使用道具 举报

发表于 2013-5-8 22:13:12 | 显示全部楼层
板子上的PA4复用了,把复用器件中与PA4相连的0欧电阻拆掉试试
回复 支持 反对

使用道具 举报

发表于 2013-8-13 16:57:16 | 显示全部楼层
flyleaf 发表于 2013-5-8 22:13
板子上的PA4复用了,把复用器件中与PA4相连的0欧电阻拆掉试试

没用 啊,拆了
回复 支持 反对

使用道具 举报

发表于 2014-1-19 20:52:41 | 显示全部楼层
风中狂舞 发表于 2013-8-13 16:57
没用 啊,拆了

请问 这个问题解决没有呢,求指教 谢谢
回复 支持 反对

使用道具 举报

发表于 2014-1-19 20:53:09 | 显示全部楼层
风中狂舞 发表于 2013-8-13 16:57
没用 啊,拆了

请问 这个问题解决没有呢,求指教 谢谢强烈支持,非常感谢哥们
回复 支持 反对

使用道具 举报

发表于 2014-1-19 20:53:41 | 显示全部楼层
风中狂舞 发表于 2013-8-13 16:57
没用 啊,拆了

请问 这个问题解决没有呢,求指教 谢谢强烈支持,非常感谢哥们强烈支持,非常感谢哥们
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-9-21 01:38 , Processed in 0.034906 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表