標題:
基于STM32F103RCT6的內(nèi)部兩路DAC其中一路不正常
[打印本頁]
作者:
TANGYAOYI
時間:
2018-7-13 17:47
標題:
基于STM32F103RCT6的內(nèi)部兩路DAC其中一路不正常
為什么通道一輸出正常,但是通道二輸出總比設(shè)定值大?而且我給通道二設(shè)定初始值為零時,測量該引腳電壓始終等于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, 下載次數(shù): 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 發(fā)表于 2020-5-25 11:38
我也是一樣的問題,通道二PA5輸出最低電壓一直不為0
您好,我和樓主同樣的芯片,我也是同樣的寫法,請問你解決了嗎?
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1