您好,歡迎訪問上海意泓電子科技有限責任公司網站!
      4新聞資訊
      您的位置: 首頁 ->  新聞資訊 -> 單片機

      ?STM8L使用ADC內部參考電壓通道測量VDD電壓

      文章出處:單片機 責任編輯:上海意泓電子科技有限責任公司 發(fā)表時間:
      2020
      11-10

          STM8L內部含有一個12位的ADC,擁有25個輸入通道,包括一個內部溫度傳感器,一個內部參考電壓


          由上圖可知,STM8L內部還有一個內部參考電壓,這個內部參考電壓的電壓值是可知的,且是精確的。由數據手冊可知,內部參考電壓為1.225V。


          ADC選擇內部參考電壓作為測量通道,可以測量到內部電壓的轉化值Nadc。此時,已經VDD的轉化值4096,VREFINT電壓值1.225V及對應的轉化值Nadc。這些值滿足比例關系:
          VDD/4096=VREFINT/Nadc
          VDD/4096 =1.225/Nadc
          VDD=1.225*4096/Nadc


          STM8L15x系列單片機的相關庫函數配置過程如下:
          This section provides functions allowing to enable/ disable the internal connections between the ADC and the Temperature Sensor and the Vrefint source.
          A typical configuration to get the Temperature sensor or/and Vrefint channels voltages is done following these steps :
          1. Enable the internal connection of Temperature sensor or/and Vrefint sources with the ADC channels:
            - for the Temperature sensor usingADC_TempSensorCmd() function.
            - for the Internal Voltage reference usingADC_VrefintCmd() function.
         2. Enable the ADC_Channel_TempSensor and/orADC_Channel_Vrefint channels usingADC_ChannelCmd()function.
         3. Get the voltage values, usingADC_GetConversionValue().


         (1)使能或失能內部參考電壓ADC_VrefintCmd()

                 * @brief  Enables or disables the Internal Voltage reference.

                 * @param  NewState : new state of the Internal Voltage reference.

                 *         This parameter can be: ENABLE or DISABLE.

                 * @retval None

                 void ADC_VrefintCmd(FunctionalState NewState);

                 參數:ENABLE(使能)或DISABLE(失能)

         (2)選擇內部參考電壓通道ADC_ChannelCmd()

                * @brief  Enables or disables the selected ADC channel(s).
                * @param  ADCx where x can be 1 to select the specified ADC peripheral.
                * @param  ADC_Channels: specifies the ADC channels to be initialized
                    This parameter can be one of the following values:

                     @arg ADC_Channel_0: Channel 0
                     @arg ADC_Channel_1: Channel 1
                     @arg ADC_Channel_2: Channel 2
                     @arg ADC_Channel_3: Channel 3
                     @arg ADC_Channel_4: Channel 4
                     @arg ADC_Channel_5: Channel 5
                     @arg ADC_Channel_6: Channel 6  
                     @arg ADC_Channel_7: Channel 7
                     @arg ADC_Channel_8: Channel 8
                     @arg ADC_Channel_9: Channel 9
                     @arg ADC_Channel_10: Channel 10
                     @arg ADC_Channel_11: Channel 11
                     @arg ADC_Channel_12: Channel 12
                     @arg ADC_Channel_13: Channel 13
                     @arg ADC_Channel_14: Channel 14
                     @arg ADC_Channel_15: Channel 15
                     @arg ADC_Channel_16: Channel 16
                     @arg ADC_Channel_17: Channel 17
                     @arg ADC_Channel_18: Channel 18
                     @arg ADC_Channel_19: Channel 19
                     @arg ADC_Channel_20: Channel 20
                     @arg ADC_Channel_21: Channel 21
                     @arg ADC_Channel_22: Channel 22
                     @arg ADC_Channel_23: Channel 23
                     @arg ADC_Channel_24: Channel 24
                     @arg ADC_Channel_25: Channel 25
                     @arg ADC_Channel_26: Channel 26
                     @arg ADC_Channel_27: Channel 27
                     @arg ADC_Channel_Vrefint: Vrefint Channel
                     @arg ADC_Channel_TempSensor: Temperature sensor Channel
                     @arg ADC_Channel_00To07: select from channel00 to channel07
                     @arg ADC_Channel_08To15: select from channel08 to channel15
                     @arg ADC_Channel_16To23: select from channel16 to channel23
                     @arg ADC_Channel_24To27: select from channel24 to channel27
                @param  NewState : new state of the specified ADC channel(s).
                     This parameter can be: ENABLE or DISABLE.   

                 void ADC_ChannelCmd(ADC_TypeDef* ADCx, ADC_Channel_TypeDef ADC_Channels, FunctionalState NewState);

        (3)獲得轉換數值ADC_GetConversionValue()
               u16 u16_adc1_value;
               u16_adc1_value = ADC1_GetConversionValue();

          程序:

      adc.h頭文件:
      #ifndef _adc_H
      #define _adc_H
      #include "stm8l15x.h"
      void Adc_Init(void);
      #endif 


      adc.c源文件:
      #include "adc.h"
      void Adc_Init(void)
      {
         CLK_PeripheralClockConfig(CLK_Peripheral_ADC1,ENABLE);//開啟ADC1時鐘
         
         ADC_VrefintCmd(ENABLE); //使能內部參考電壓
         ADC_Init(ADC1,ADC_ConversionMode_Continuous,ADC_Resolution_12Bit,ADC_Prescaler_1);//連續(xù)轉換,12位,轉換時鐘1分頻
         
         ADC_ChannelCmd(ADC1,ADC_Channel_Vrefint,ENABLE);//使能內部參考電壓通道
         ADC_Cmd(ADC1,ENABLE);//ADC使能
      }



      主函數:

      #include "stm8l15x.h"
      #include "adc.h"
      int main( void )

      {
          u16 adc1_value=0;
          float value=0;
          Adc_Init(); 
          while(1)
          {
               ADC_SoftwareStartConv(ADC1); //開啟軟件轉換
               while(!ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));//等待轉換結束
               ADC_ClearFlag(ADC1,ADC_FLAG_EOC);//清除對應標志
               adc1_value=ADC_GetConversionValue(ADC1); //獲取轉換值
               value=1.225*4096/adc1_value; //獲得VDD電壓,單位V
               if(value<2.8)
               {
                    GPIO_ResetBits(GPIOD,GPIO_Pin_4);
                    GPIO_ToggleBits(GPIOD,GPIO_Pin_5);
               }   
          }
      }   
       

      對上述IAR工程進行編譯,并下載到STM8L15x板子中,分別右擊變量adc1_value和變量value選擇“Add to watch”出現(xiàn)如下窗口(查看相關變量的值):


      在程序中設置相關斷點,以便查看變量值

         

      運行程序可得:



       故測得STM32L15x板子的VDD=3.32291388V 


      上海意泓電子科技有限責任公司 版權所有 未經授權禁止復制或鏡像

      CopyRight 2020-2025 m.topsschool.com All rights reserved   滬ICP備2021005866號

      亚洲精品无码va人在线观看,少妇 逼小 水多,国产区免费av,国产精品无码观看

          人人妻人人澡人人爽| 2019精品国品在线看不卡| 一本到无码在线视频观看| 无码免费又爽又高潮喷水的视频| 尤物蜜芽在线观看无码| 青草久久久国产免费观看视频| 天天爽夜夜爽人人爽曰AV| YW亚洲AV无码乱码在线观看| 国自产精品手机在线视拍| 欧美日韩国产一区二区三区| 亚洲不卡AV网在线播放| 天天中文字幕av天天爽| 99re最新在线视频精品| 中文字幕开心激情| 亚洲啪精品视频网站免费| 久久精品这里只有精品99品| 精品国产天天在线2019| 久久婷婷午夜精品二区| 国产精品无码一级毛片不卡| 日本免费一区二区三区视频| 国产人妇三级视频在线观看| 日本老熟妇乱子伦精品| 日韩精品中文在线一区二区有码动漫| 亚洲综合精品网站| 日韩av无码久久精品免费| 一级做性色α爱片久久毛片色| 99热国产这里只有精品久久| 曰韩无码一区二区三区九动漫| 99久久99这里只有免费精品|