ESP-LiveControl  1.99.1
HTTP server, AJAX API backend and Vue.js web application implementing self-contained, zero-install WiFi remote control of hardware modules attached to the Espressif ESP32 SoC
Public Member Functions | Public Attributes | Protected Attributes | Static Protected Attributes | List of all members
ESP32ADCChannel Class Reference

ESP32 ADC 1 channel access with configurable averaging. More...

#include <esp32_adc_channel.hpp>

Inheritance diagram for ESP32ADCChannel:
Inheritance graph
[legend]

Public Member Functions

 ESP32ADCChannel (adc1_channel_t channel_num, adc_atten_t attenuation, uint32_t averaged_samples=64, adc_bits_width_t bits_width=ADC_WIDTH_BIT_12, uint32_t default_vref=1100u)
 Initialize an ESP32 ADC channel. More...
 
uint16_t get_raw_averaged ()
 Get raw ADC channel conversion value. Repeats sampling a number of times, see "averaged_samples" constructor parameter. More...
 
uint16_t get_voltage_averaged ()
 Get channel input voltage in millivolts. Repeats sampling a number of times, see "averaged_samples" constructor parameter. More...
 
int32_t calculate_raw_from_voltage (uint32_t v_in_mv)
 Calculate backwards the raw ADC reading for given input voltage, based on calibration constants from ADC initialisation, and also based on a ADC resolution setting of 12 bits.
 
void debug_print_check_efuse ()
 
void debug_print_characterisation_val_type (esp_adc_cal_value_t val_type)
 
void test_register_direct ()
 

Public Attributes

adc1_channel_t channel_num
 
adc_atten_t attenuation
 
esp_adc_cal_characteristics_t calibration_data
 

Protected Attributes

uint32_t division_shift
 

Static Protected Attributes

static auto _bits_width = adc_bits_width_t{ADC_WIDTH_MAX}
 

Detailed Description

ESP32 ADC 1 channel access with configurable averaging.

Input voltage can be read raw or as calibrated voltage value in millivolts.

Raw output is always scaled such as if the ADC was set to 12 bits mode, i.e. theoretical full-scale output is 4096 - 1

Note
For additional moving average filtering and smoothing, please see the additional templated version in class ESP32ADCChannelFiltered.

Constructor & Destructor Documentation

◆ ESP32ADCChannel()

ESP32ADCChannel::ESP32ADCChannel ( adc1_channel_t  channel_num,
adc_atten_t  attenuation,
uint32_t  averaged_samples = 64,
adc_bits_width_t  bits_width = ADC_WIDTH_BIT_12,
uint32_t  default_vref = 1100u 
)

Initialize an ESP32 ADC channel.

Parameters
channel_numAnalog input channel number
attenuationVoltage input scale setting, see ESP-IDF reference
averaged_samplesRead this many input samples at once for any trigger
bits_widthCan be less then ADC_WIDTH_BIT_12 for faster speed.
Note
The "bits_width" setting must be identical for all channels!
Parameters
default_vrefCan be manually set if hardware has no e-fuse calibration

Member Function Documentation

◆ debug_print_check_efuse()

void ESP32ADCChannel::debug_print_check_efuse ( )

Debug functions

◆ get_raw_averaged()

uint16_t ESP32ADCChannel::get_raw_averaged ( )

Get raw ADC channel conversion value. Repeats sampling a number of times, see "averaged_samples" constructor parameter.

The output is always scaled such as if the ADC was set to 12 bits mode, i.e. theoretical full-scale output is 4096 - 1

◆ get_voltage_averaged()

uint16_t ESP32ADCChannel::get_voltage_averaged ( )

Get channel input voltage in millivolts. Repeats sampling a number of times, see "averaged_samples" constructor parameter.

This takes into account the calibration constants from ADC initialisation. If there is no e-fuse calibration on-chip, this uses the default_vref setting from the constructor, default is 1100 millivolts.

Returns
Voltage in millivolts
Here is the call graph for this function:

The documentation for this class was generated from the following files: