ESP32-C3 Power sensor measurement exceeds ADC range ?

Started by winfried, July 11, 2023, 10:30:23 PM

Previous topic - Next topic

winfried

Hi,

Soldered Power_sens jumpers and read voltages.

When I use a voltage divider:
220k:470k => (220.0 + 470.0)/470.0 = 1.468

on 5V power I should measure 5V/1.468 = 3,4 V,
 
but ADC range max setting Attenuation of 11dB: range is 150 mV ~ 2450 mV as noted in the library documentation of `analogReadMillivolts()` in Arduino libs:

- https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/api/adc.html

Indeed, I measure only 4069 mV (read 2772 mV).

What am I missing, measuring the power voltage correctly ?

Anyway, battery measurement is also limited:
values 470k:470k => (470+470)/470 = 2 which means officially 4.9V which is fine.

mfg winfried
---- Atelier Algorythmics --- [url="http://algo.mur.at/"]http://algo.mur.at/[/url] ----

LubOlimex

In ESP32-C3-DevKit-Lipo you need to close three jumpers in total to enable both power sense and battery level - PWR_SENS_E1, BAT_PWR_E1, BAT_SENS_E1. Maybe our code for power and battery sense for ESP32-POE and ESP32-POE-ISO can help you:

https://github.com/OLIMEX/ESP32-POE/blob/master/SOFTWARE/ARDUINO/ESP32_PoE_PowerReading/ESP32_PoE_PowerReading.ino

In C3 case it should be GPIO4 and GPIO3.
Technical support and documentation manager at Olimex

winfried

Thanks for the hints and yes, all jumpers are soldered.

I do the same with ESP32-S2-Wrover-Devkit-LiPo and ESP32-Devkit-Lipo and it works.

As I understand, you don't measure the power you look if it is digital high, but I need the voltage(, since maybe powered by solar-usb etc. and control it.)

My code is in here:
https://git.iem.at/uC/LEMiotLib/-/blob/main/src/ui.cpp

shortend:
#define LEMIOT_ADC_POWER_PIN GPIO_NUM_4
// Set Calibration 220k:470k => (220.0 + 470.0)/470.0
#define LEMIOT_ADC_POWER_CALC(x) (uint32_t)((690.0 / 470.0) * (float)(x)
static int32_t voltage_power = 0;
...
analogSetAttenuation(ADC_11db);
...
static uint32_t voltage_raw_power = analogReadMilliVolts(LEMIOT_ADC_POWER_PIN);
voltage_power = LEMIOT_ADC_POWER_CALC(voltage_raw_power);
...

If the resistors were vice versa R8:R9 = 470k:220k instead of 220k:470k it would be fine and up to 5.5V in the ADC range.

On battery measurement I could add a resistor instead of solder-jumper BAT_PWR_E1, but on the power I have to solder a parallel Resistor to R9 e.g. 100k.

What is best practice, any other ideas ?

mfg winfried
---- Atelier Algorythmics --- [url="http://algo.mur.at/"]http://algo.mur.at/[/url] ----

LubOlimex

QuoteAs I understand, you don't measure the power you look if it is digital high, but I need the voltage(, since maybe powered by solar-usb etc. and control it.)

We measure the battery voltage. Which voltage do you want to measure?
Technical support and documentation manager at Olimex

winfried

Quote from: LubOlimex on July 12, 2023, 03:08:27 PMWe measure the battery voltage. Which voltage do you want to measure?

On an ESP32-C3DevKit-LiPo the 5V rail, which is Solder-Jumper PWR_SENS_E1 and GPIO 4 measured with ADC one shot (with calibrated read of  analogReadMillivolts(GPIO_NUM_4).

The battery measurement with voltage divider 470k:470k is fine.
---- Atelier Algorythmics --- [url="http://algo.mur.at/"]http://algo.mur.at/[/url] ----