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

微信

易經理

易經理

頂部

咨詢
主站蜘蛛池模板: 中文字幕永久在线视频 | 免费日产乱码卡一卡2卡三卡四 | 三级毛片在线 | 最色影院| 日本一区二区三区无码苍井空 | 91免费在线观看 | 成人在免费视频手机观看网站 | 波多野结衣一区二区三区 | 自拍视频亚洲综合在线精品 | 国产又黄又硬又湿又黄的A片小说 | 91精品国产人成网站 | 丰满大码熟女在线播放 | 乌龙院在线观看免费观看完整版 | 天天操中文字幕 | 免费观看欧美成人1314w色 | 亚洲乱轮视频 | 色播在线播放 | 视频国产免费 | 在线日韩欧美一区二区三区 | 操美女国产 | 和漂亮老师做爰5中文字幕 黑巨茎大战俄罗斯白人美女 | 欧洲欧美人成视频在线 | 久久艳务乳肉豪妇荡乳A片 久久夜色噜噜噜亚洲AV0000 | 96精品视频在线播放免费观看 | 强行挺进朋友漂亮的娇妻作者 | 青青操网 | 黄页网站免费观看 | 欧美粗大| 在线成本人动漫视频网站 | 老湿机免费体十分钟 | 人人看人人艹 | 滨崎真绪 | 狠狠爱在线影院 | 房奴电视剧 | va在线| 速看网韩国伦理片 | 翁熄乩伦小说翁熄性放纵 | 免费麻豆国产黄网站在线观看 | 亚洲午夜影视 | 国产青草视频免费观看97 | 国产精品久久久久久久久99热 |