找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4567|回復: 3
打印 上一主題 下一主題
收起左側

基于STM32F103RCT6的內(nèi)部兩路DAC其中一路不正常

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:370737 發(fā)表于 2018-7-13 17:47 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
為什么通道一輸出正常,但是通道二輸出總比設定值大?而且我給通道二設定初始值為零時,測量該引腳電壓始終等于0.67V

單片機源程序如下:
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "sys.h"
  4. #include "usart.h"
  5. #include "lcd.h"
  6. #include "adc.h"
  7. #include "key.h"
  8. #include "dac.h"

  9. int main(void)
  10. {
  11.          u16 adcx;
  12.           u16 dacx=0;
  13.          u8 key;
  14.          float iwant[3]={1,1.5,2};
  15.          float temp1;
  16.          u16 temp2;
  17.          int i=0;
  18.          delay_init();
  19.          uart_init(9600);
  20.          LED_Init();
  21.          LCD_Init();
  22.          KEY_Init();
  23.         // Adc_Init();
  24.          Dac1_Init();
  25.          Dac2_Init();
  26.          Dac1_Set_Vol(1000);
  27.                  Dac2_Set_Vol(1500);
  28.          
  29.           POINT_COLOR=BLACK;
  30.                  LCD_ShowString(30,40,200,16,16,"Mini STM32 ^_^");
  31.                  LCD_ShowString(30,60,200,16,16,"2018/7/9");
  32.                  LCD_ShowString(30,90,200,16,16,"DAC_VOL:");
  33.                  LCD_ShowString(30,110,200,16,16,"DAC_VAL:0.000");
  34.            LCD_ShowString(30,130,200,16,16,"ADC_VOL:");
  35.                  LCD_ShowString(30,150,200,16,16,"ADC_VAL:0.000");
  36.                  
  37.          
  38.        
  39.          
  40.          while(1){
  41.                  key=KEY_Scan(0);
  42.                  delay_ms(10);
  43.                  if(key==KEY0_PRES){
  44.                          dacx=1.5/(3.3/4096);
  45.                          DAC_SetChannel1Data(DAC_Align_12b_R,dacx);
  46.                          DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
  47.                          //adcx=Get_Adc_Average(ADC_Channel_1,10);
  48.          /*while(((iwant[i]/(3.3/4096))-adcx>5)||((adcx-(iwant[i]/(3.3/4096))>5)))
  49.                  {
  50.                        
  51.                                 if(adcx-(iwant[i]/(3.3/4096))>100){
  52.                                 dacx-=50;
  53.                                 DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
  54.                                
  55.                                 }
  56.                        
  57.                         else if(( (iwant[i]/(3.3/4096))-adcx)>100){
  58.                                 dacx+=50;
  59.                                 DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
  60.                                
  61.                                
  62.                         }
  63.                         else if((adcx-(iwant[i]/(3.3/4096))<=100)&&(adcx-(iwant[i]/(3.3/4096))>=20)){
  64.                                 dacx-=20;
  65.                                 DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
  66.                                
  67.                         }
  68.                         else if(((iwant[i]/(3.3/4096))-adcx<=100)&&((iwant[i]/(3.3/4096))-adcx>=20)){
  69.                                 dacx+=20;
  70.                                 DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
  71.                                
  72.                         }
  73.                         else if((adcx-(iwant[i]/(3.3/4096))<20)&&(adcx-(iwant[i]/(3.3/4096))>5)){
  74.                                 dacx-=2;
  75.                                 DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
  76.                         }
  77.                                 else if(((iwant[i]/(3.3/4096))-adcx<20)&&((iwant[i]/(3.3/4096))-adcx>5)){
  78.                                 dacx+=2;
  79.                                 DAC_SetChannel2Data(DAC_Align_12b_R,dacx);
  80.                                
  81.                         }
  82.                         adcx=Get_Adc_Average(ADC_Channel_1,10);
  83.                        
  84.    LCD_ShowxNum(94,90,dacx,4,16,0);
  85.       temp1=(float)dacx*(3.3/4096);
  86.          temp2=temp1;
  87.          LCD_ShowxNum(94,110,temp2,1,16,0);
  88.          temp1-=temp2;
  89.          temp1*=1000;
  90.          LCD_ShowxNum(110,110,temp1,3,16,0X80);//顯示DAC的實際值
  91.                        
  92.                                 LCD_ShowxNum(94,130,adcx,4,16,0);
  93.                                  temp1=(float)adcx*(3.3/4096);
  94.          temp2=temp1;
  95.          LCD_ShowxNum(94,150,temp2,1,16,0);
  96.          temp1-=temp2;
  97.          temp1*=1000;
  98.          LCD_ShowxNum(110,150,temp1,3,16,0X80);//顯示ADC的實際值
  99.                         delay_ms(10);
  100.                         LED0=!LED0;
  101.          }*/
  102.                  LCD_ShowxNum(94,90,dacx,4,16,0);
  103.       temp1=(float)dacx*(3.3/4096);
  104.          temp2=temp1;
  105.          LCD_ShowxNum(94,110,temp2,1,16,0);
  106.          temp1-=temp2;
  107.          temp1*=1000;
  108.          LCD_ShowxNum(110,110,temp1,3,16,0X80);//顯示DAC的實際值
  109.                        
  110.                                 /*LCD_ShowxNum(94,130,adcx,4,16,0);
  111.                                  temp1=(float)adcx*(3.3/4096);
  112.          temp2=temp1;
  113.          LCD_ShowxNum(94,150,temp2,1,16,0);
  114.          temp1-=temp2;
  115.          temp1*=1000;
  116.          LCD_ShowxNum(110,150,temp1,3,16,0X80);//顯示ADC的實際值
  117.                  
  118.          if(i<2)
  119.          i++;
  120.          else i=0;*/

  121. }
  122.                  }
  123.          }
  124.          
復制代碼

所有資料51hei提供下載:
兩路DA1.rar (338.97 KB, 下載次數(shù): 43)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:331360 發(fā)表于 2020-5-25 11:38 | 只看該作者
我也是一樣的問題,通道二PA5輸出最低電壓一直不為0
回復

使用道具 舉報

板凳
ID:375349 發(fā)表于 2021-5-6 13:03 | 只看該作者
同樣的芯片我也是同樣的寫法,樓主解決了嗎?
回復

使用道具 舉報

地板
ID:375349 發(fā)表于 2021-5-6 13:04 | 只看該作者
plyl 發(fā)表于 2020-5-25 11:38
我也是一樣的問題,通道二PA5輸出最低電壓一直不為0

您好,我和樓主同樣的芯片,我也是同樣的寫法,請問你解決了嗎?
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表