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

微信

易經理

易經理

頂部

咨詢
主站蜘蛛池模板: 性戏达人 | 国产精品69白浆在线观看免费 | 性欧美高清videosex | 亚洲中文无码永久免费 | 少妇真人直播免费视频 | 国产九九九九九九九A片 | 久久riav.com | 手机av在线播放 | 最近最新日本中文字幕MV2024 | 一本色道亚洲精品久久 | 色视频亚洲| 日本黄A级A片国产免费 | 丁香色婷婷 | 狠狠操欧美 | 伊人成人久久 | 日本韩国一区二区三区 | 中文字幕无码无卡视频 | 久久成人做爰电影图片 | 国产精品人人爽人人做我的可爱 | 国产成人亚洲欧美激情 | 五月亭亭六月丁香 | 欧美日韩一卡2卡三卡4卡新区 | 免费超级淫片日本高清视频 | 免费国产视频 | 国产精品福利影院 | 中文字幕乱码人在线视频1区 | 久综合网 | 天天干天天天天 | 国产精品高潮呻吟AV久久床戏 | 亚洲AV久久无码精品九号 | 日韩操穴| 国产麻豆9l精品三级站 | 亚洲爽爽爽爽爽A片黄漫画 亚洲天天干 | 在线观看免费电影 | 久久国产天堂福利天堂 | 久久国产精品-久久精品 | 天天操天天弄 | 狠狠影院 | 国产精品久久久久久久久99热 | 三级韩国日本三级在线 | 好爽毛片一区二区三区色欲 |