91视频丝瓜-91视频完整版高清-91视频网-91视频网店-91视频网或将从此无大神-91视频网入口

您好,歡迎訪問上海現易電子元器件有限公司網站!

021-51870898
021-51870898   18019251567
4新聞資訊
您的位置: 首頁 ->  新聞資訊 -> 單片機

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

文章出處:單片機 責任編輯:上海現易電子元器件有限公司 發表時間: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);//連續轉換,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”出現如下窗口(查看相關變量的值):


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

   

運行程序可得:



 故測得STM32L15x板子的VDD=3.32291388V 


上海現易電子元器件有限公司 版權所有 未經授權禁止復制或鏡像

CopyRight 2020-2025 www.urqm.cn All rights reserved   滬ICP備2020031792號

友情鏈接:

電話

易經理

18019251567

微信

易經理

易經理

頂部

咨詢
主站蜘蛛池模板: 工口里番全彩全彩无遮挡 | 亚洲卡二卡三乱码新区 | 五月色丁香综缴合 | 欧美精品导航 | 成人人观看的免费毛片 | 国内一级黄色片 | 波多野结衣在线播放 | 欧美精品高清在线xxxx | 青草国产超碰人人添人人碱 | 在线小视频国产 | 亚洲国产精品综合久久久 | 欧美日韩国产一区二区三区 | 性色va| 中国人电影网 | 在线成人精品国产区免费 | 99成人在线| 久久久国产精品免费A片蜜芽广 | 免费A级毛片无码鲁大师 | 天天综合久久久网 | 日韩免费看 | 色吧新地址 | 我国产码在线观看AV哈哈哈网站 | 免费福利视频导航 | 美女免费视频一区二区 | 免费伦费一区二区三区四区 | 日韩在线永久免费播放 | 品色 官网 | 精品夜夜澡人妻无码AV | 久99久精品视频免费观看v | 五月天婷婷缴情五月免费观看 | 色综合精品无码一区二区三区 | 综合婷婷 | 日本黄免费 | 色情.WWW成人天堂 | 2024无码高潮喷水A片 | 视频一区在线免费观看 | 亚洲精品国产乱码AV在线观看 | 日韩色情无码一本二本三本 | 日本A级做爰午夜免费视频 日本A片成人片免费视频生活片 | 97久久精品无码一区二区欧美人 | 94成人社区|