RAK4631 Analog Read after Deep Sleep Issue

I am reading my battery voltage after i wakeup from deep sleep.

I have noticed when i do a series of reads, to calculate a smoothed average, the first read is always about 7-8% lower than the rest of the reads.

Thinking it might be the nrf52 settling after wakeup, i added a delay before the first read. But the first read still is low.

Can anybody shed any light on this?

For now, i am simply throwing away the first reading…

Hi,
It’s a “common” issue with MCU’s ADC : capacitances exists in ADC entries and need to be charged before getting a right reading. You can find a better detailed response here : ADC - First read is always wrong - Nordic Q&A - Nordic DevZone - Nordic DevZone

I didn’t take a look at the code behind analogRead(), basically (but it’s not true for everything about MCU) it’s hard to write a code which works in every situation. For ADCs for example you can specify a resolution, a bitrate etc … And Arduino is for the most common usages. So sometimes it’s not perfect … But it works with some tweaks :slight_smile:

Welcome back to RAK forum @Batto .

When it comes to ADCs, there are many factors involve. Some ideas are generic and some are specific to the chip.

If the application where ADC reading is critical, an external one is recommend. Otherwise, built-in can be considered and should work ok.

Also, another critical aspect is the evaluation on the end-product since ADC can be affected highly by the PCB layout and externally induced noise.

Thx for the replies.

I did some more detailed testing.

There seems to be significant difference in the analog (vbat) read behavior of the 4631 after waking from deep sleep, depending on the power source and serial output!

When on bat and using “MAX_SAVE” in the deep sleep example, readings are ok. Only the very first reading after the first wakeup after a mcu reboot is way off! Subsequent wakeups, the analog read is fine! This can be handled by doing a few analog reads in the setup after boot before going to sleep.

When the mcu is on bat and usb, even when the bat is fully charged, the first couple reads after wakeup are more noisy.

What is really interesting, removing MAX_SAVE ( enabling serial output and LEDs) while debugging on usb, things get ridiculously noisey and addition of long delays after wake dont help, the analog reads are really unreliable even after delays.

Even if the battery is fully charged, the battery charger chip is still active when USB is plugged in. I guess that’s why you get the fluctuating values.