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

STM8L使用ADC内部参考电压通道测量VDD电压相关推荐

  1. ADC VS参考电压在测量时和AD值的大小对应关系

    背景是这样的,用24位的ADC,外接人体电阻,进行电阻AD值采集,当VS = 2.4V时,体电阻的AD值对应值为9.86 * 10 ^ 5量级,当VS = 2.8V时,体电阻的AD值对应值为7.01 ...

  2. STM32 ADC采样使用内部参考电压

    整理也能进步!写得清楚才能理解更深. [问题背景] 在使用ADC时,通常的用法是Vref+接电源VDD3.3V,然后计算时直接用3.3V做参考电压,但是这种方法忽略了一些情况如供电电压有可能随外部一些 ...

  3. stm8L-----ADC获取芯片内部参考电压

    这次分享一个stm8L,获取内部芯片参考电压 STM8L内部含有一个12位的ADC,拥有25个输入通道,包括一个内部温度传感器,一个内部参考电压 步骤: 启用ADC采集功能 ADC驱动配置大致分为以下 ...

  4. STM8L051之通过ADC1与DMA读取内部参考电压,求取VDD电源电压---库函数版

    stm8L051芯片内部的参考电压与电源电压有一定的关系, 这在芯片供电电压变化的情况下,测量外部ADC电压输入 提供一个确定的参考电压.这里提前厘清下:该内部参考 电压VREFINT 并非ADC 的 ...

  5. 基于STM32HAL库ADC+DMA模式,高精度采集电池电量与芯片内部温度方法 (48脚 使用内部参考电压方案)

    目录 概述 1.原理图 2.在这先普及一下概念 3.通过查看STM32L0中文数据手册中301页,第14.10 小节 ,DataSheet 4.ADC通道转换模式的理解 5.STM32CubeMx工具 ...

  6. STM32芯片ADC内部的CH17参考电压的用途

    每个STM32芯片都有一个内部的参照电压,相当于一个标准电压测量点,在芯片内部连接到ADC1的通道17. 根据数据手册中的数据,这个参照电压的典型值是1.20V,最小值是1.16V,最大值是1.24V ...

  7. STM32使用内部参考电压提高ADC采集准确度

    我们在使用ADC采集外部电压时,一般默认参考电压为MCU的供电电压,例如单片机供电电压为3.3V时,我们计算采集电压的公式为: 假设12位ADC 采集电压=(AD值/4096)*3.3: 但是如果因为 ...

  8. STM32L4系列单片机ADC通过内部参考电压精确计算输入电压

    以STM32L476为例,VREFINT与内部ADC1_INP0相连 当VDDA与VREF+引脚连在一起时,该电压可能波动,这将导致ADC转换误差很大,因此可通过利用单片机内部的参照电压来算出该时刻的 ...

  9. stm32 精确电压测量法(内部参考电压)

    芯片型号:stm32l051c8(其它型号请参考datasheet,仅供参考) 使用ADC采集电压时若使用外部参考电压,如果外部电压变化,且低于正常LDO工作电压时,输出的电压将发生改变,导致基准电压 ...

最新文章

  1. php调用restful接口_jzq_sdk_php
  2. 【电影】美丽心灵的永恒阳光
  3. python web框架基础
  4. birt什么意思中文翻译_ECTN是什么意思
  5. floquet端口必须沿z轴设置_Ansys Workbench 振动给料机偏心轴的模态分析
  6. 02241107班编程题 切片逆序大小写等
  7. java final修改器_Java中的“ final”关键字如何工作?(我仍然可以修改对象。)...
  8. boost 静态库命名规则
  9. Xshell5安装 即 使用过程
  10. Java 十大必读经典书籍推荐
  11. Ubuntu系统搜狗拼音无法输出
  12. 计算机重命名怎样操作,如何对计算机/电脑进行重命名操作?
  13. 处理安卓机不支持backdrop-filter毛玻璃效果样式
  14. 如何在命令行卸载mysql_如何彻底卸载MySQL
  15. 全国计算机互联网城市排名,中国互联网+城市排名:杭州第一 北京仅排第八
  16. linux scp 排除文件夹,scp复制文件时排除指定文件
  17. 理解CTP/XTP柜台对接
  18. 微信自动跳转领支付宝红包JS实践
  19. dns 劫持什么意思、dns 劫持原理及几种解决方法
  20. flashback六大技术之flashback drop

热门文章

  1. 老厉害了!2600亿,紫光集团南京再投半导体生产线
  2. Android 上传头像(文件)到服务器
  3. Python爬取20w+表情包,微信斗图谁怕谁!
  4. java中复数_Java中的复数
  5. matlabapp窗口图像_matlab的App designer使用
  6. 如何ping网站的IP地址
  7. 斑马打印机测试demo,一维码、二维码、字符串。可以保存创建模板以便于后续使用
  8. 知乎:月薪2~3万,码农怎样度过一天
  9. 笔记本禁用键盘的方法(已试过win10/win11均可生效)
  10. 安装Win11找不到固态硬盘如何解决?