标题:
基于STM32F103RCT6的内部两路DAC其中一路不正常
[打印本页]
作者:
TANGYAOYI
时间:
2018-7-13 17:47
标题:
基于STM32F103RCT6的内部两路DAC其中一路不正常
为什么通道一输出正常,但是通道二输出总比设定值大啊?而且我给通道二设定初始值为零时,测量该引脚电压始终等于0.67V
单片机源程序如下:
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "lcd.h"
#include "adc.h"
#include "key.h"
#include "dac.h"
int main(void)
{
u16 adcx;
u16 dacx=0;
u8 key;
float iwant[3]={1,1.5,2};
float temp1;
u16 temp2;
int i=0;
delay_init();
uart_init(9600);
LED_Init();
LCD_Init();
KEY_Init();
// Adc_Init();
Dac1_Init();
Dac2_Init();
Dac1_Set_Vol(1000);
Dac2_Set_Vol(1500);
POINT_COLOR=BLACK;
LCD_ShowString(30,40,200,16,16,"Mini STM32 ^_^");
LCD_ShowString(30,60,200,16,16,"2018/7/9");
LCD_ShowString(30,90,200,16,16,"DAC_VOL:");
LCD_ShowString(30,110,200,16,16,"DAC_VAL:0.000");
LCD_ShowString(30,130,200,16,16,"ADC_VOL:");
LCD_ShowString(30,150,200,16,16,"ADC_VAL:0.000");
while(1){
key=KEY_Scan(0);
delay_ms(10);
if(key==KEY0_PRES){
dacx=1.5/(3.3/4096);
DAC_SetChannel1Data(DAC_Align_12b_R,dacx);
DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
//adcx=Get_Adc_Average(ADC_Channel_1,10);
/*while(((iwant[i]/(3.3/4096))-adcx>5)||((adcx-(iwant[i]/(3.3/4096))>5)))
{
if(adcx-(iwant[i]/(3.3/4096))>100){
dacx-=50;
DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
}
else if(( (iwant[i]/(3.3/4096))-adcx)>100){
dacx+=50;
DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
}
else if((adcx-(iwant[i]/(3.3/4096))<=100)&&(adcx-(iwant[i]/(3.3/4096))>=20)){
dacx-=20;
DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
}
else if(((iwant[i]/(3.3/4096))-adcx<=100)&&((iwant[i]/(3.3/4096))-adcx>=20)){
dacx+=20;
DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
}
else if((adcx-(iwant[i]/(3.3/4096))<20)&&(adcx-(iwant[i]/(3.3/4096))>5)){
dacx-=2;
DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
}
else if(((iwant[i]/(3.3/4096))-adcx<20)&&((iwant[i]/(3.3/4096))-adcx>5)){
dacx+=2;
DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
}
adcx=Get_Adc_Average(ADC_Channel_1,10);
LCD_ShowxNum(94,90,dacx,4,16,0);
temp1=(float)dacx*(3.3/4096);
temp2=temp1;
LCD_ShowxNum(94,110,temp2,1,16,0);
temp1-=temp2;
temp1*=1000;
LCD_ShowxNum(110,110,temp1,3,16,0X80);//显示DAC的实际值
LCD_ShowxNum(94,130,adcx,4,16,0);
temp1=(float)adcx*(3.3/4096);
temp2=temp1;
LCD_ShowxNum(94,150,temp2,1,16,0);
temp1-=temp2;
temp1*=1000;
LCD_ShowxNum(110,150,temp1,3,16,0X80);//显示ADC的实际值
delay_ms(10);
LED0=!LED0;
}*/
LCD_ShowxNum(94,90,dacx,4,16,0);
temp1=(float)dacx*(3.3/4096);
temp2=temp1;
LCD_ShowxNum(94,110,temp2,1,16,0);
temp1-=temp2;
temp1*=1000;
LCD_ShowxNum(110,110,temp1,3,16,0X80);//显示DAC的实际值
/*LCD_ShowxNum(94,130,adcx,4,16,0);
temp1=(float)adcx*(3.3/4096);
temp2=temp1;
LCD_ShowxNum(94,150,temp2,1,16,0);
temp1-=temp2;
temp1*=1000;
LCD_ShowxNum(110,150,temp1,3,16,0X80);//显示ADC的实际值
if(i<2)
i++;
else i=0;*/
}
}
}
复制代码
所有资料51hei提供下载:
两路DA1.rar
(338.97 KB, 下载次数: 43)
2018-7-14 01:58 上传
点击文件名下载附件
作者:
plyl
时间:
2020-5-25 11:38
我也是一样的问题,通道二PA5输出最低电压一直不为0
作者:
b114025
时间:
2021-5-6 13:03
同样的芯片我也是同样的写法,楼主解决了吗?
作者:
b114025
时间:
2021-5-6 13:04
plyl 发表于 2020-5-25 11:38
我也是一样的问题,通道二PA5输出最低电压一直不为0
您好,我和楼主同样的芯片,我也是同样的写法,请问你解决了吗?
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1