Electronics > Microcontrollers

[SOLVED] SAMD21 ADC 100ms delay after wakeup or you get messy readings

(1/2) > >>

nemail2:
Hi,

I'm building a device with a SAMD21 which is battery powered and sleeps obviously most of the time. It periodically wakes up, makes an ADC measurement with the internal ADC and goes back to sleep again.

Now the issue is, that it seems to take 100ms for the ADC to wake up properly, to get reliable measurements. I know that in the datasheet it says that the ADC needs SOME delay, but I wasn't able to find exact figures.

I have taken into account the source resistance for the sampling cap to charge up properly and there is even a formula for that in the datasheet.

T(sample) >= (R(source) + R(sample)) * C(sample) * (n + 1) * ln(2) where n is the ADC resoultion in bits.
R(sample) = 3.5kOhms
C(sample) = 3.5pF

ADC Clock Frequency = 48MHz / 512 = 93750Hz (512 is the prescaler value)
Therefore the ADC clock period is 10.66us (1 / 93750)
The default ADC sample time is half the ADC clock period, so normally the sample time is:
Default ADC sample time = 10.66us / 2 = 5.33us

So for 1 Meg source resistance I would need to increase sample time by 6 and that would end up in this formula for 8 bit resolution:

(6 * 5.33us) / (3.5pF * (8 + 1) * ln(2)) - 3.5kOhms = 1460785 Ohms source resistance which should be plenty.

Still, if I do not put in a delay of around 100ms before measuring, the readings are garbage (e.g. measuring 4V instead of 3V).
I also tried to increase the number of samples and accumulate and average them within the ADC and again, only if I take that many samples that a time of around 100ms passes, the measurements get useful.

So, is the delay the ADC needs really 100ms or am I doing something wrong?

Thanks!

nemail2:

--- Quote from: evb149 on June 25, 2022, 01:58:21 pm ---That sounds like a very long time.

--- End quote ---
indeed.

Now, I tried to investigate your suggestions and if I didn't go into depth with some of the topic that's not because of ignorance but of the lack of knowledge, so I apologize upfront.


--- Quote from: evb149 on June 25, 2022, 01:58:21 pm ---* If you're powering on any voltage regulators (linear, DCDC) in the process of waking stuff up, check the specified time for those supplies to become valid.

--- End quote ---
Currently I'm powering from my lab power supply which is on all the time, only the microcontroller goes to sleep.


--- Quote from: evb149 on June 25, 2022, 01:58:21 pm ---* If you're starting any crystal or other oscillators or clocks when you wake up, check the time required for the oscillators to start & stabilize, as well as for the PLL to be initialized and become stable / ready.

--- End quote ---
Also very good point! I had the ADC tied to the main oscillator which indeed goes to sleep. Instead of trying to find out the values on that, I simply tied the ADC to the internal ultra low power 32kHz crystal which is powered on all the time, even during the deepest of sleep modes. Unfortunately, that didn't resolve the issue. I was really hoping for that.


--- Quote from: evb149 on June 25, 2022, 01:58:21 pm ---* Maybe the ADC is paired with a voltage reference, amplifier, multiplexor, or not but ensure you're enabling the clocks, regulators, operation enables for all the relevant circuits are enabled, see how long that takes.

--- End quote ---
The ADC is connected to the internal 1V bandgap reference, I wasn't able to find any figures on how long it takes to stabilize after powerup or wakeup... :(


--- Quote from: evb149 on June 25, 2022, 01:58:21 pm ---* The ADC may require some amount of time or even time + samples to elapse before it is ready, maybe absolute time, maybe as a function of the clock rates associated with the ADC conversions.  So make sure the clocks are running at the correct frequencies to result in the performance you want and account for the delays.

--- End quote ---
I think I've ruled out any clock issue now with the always-on OSCULP32K and I even discard the first measurement anyway, which is usually enough, if not going to sleep. For wakeup delay after sleep, I wasn't able to find any numbers in the datasheet.


--- Quote from: evb149 on June 25, 2022, 01:58:21 pm ---* Speaking of performance maybe there's some kind of performance mode or speed category you can put the ADC et. al. device in to balance energy / speed, check that.
* And make sure you're not accidentally using a lot of oversampling or reading bursts of N-sequenced channels unexpectedly.

--- End quote ---
The only thing controlling the speed of the ADC is AFAIK 1) the clock and 2) the sample time, which I have adjusted to be long enough for the 1M source resistance. There is a continuous mode and a single shot mode too, but I'm using single-shot, obviously.
I've tried to do mutliple readings and oversampling as well as doing only a single reading but the result remained the same. No matter what I do, if 100ms pass (by sampling or waiting doesn't matter) the readings get useful.

nemail2:
OK, turns out, I am a stoopid idiot.

I had set all pins which are inputs to input pullups during sleep, so they don't float and draw unnecessary current.
Obviously with the analog pin being high at 3V and having a 100n capacitor as a filter on that pin, it takes some time for that cap to discharge.

YIKES.

Doctorandus_P:
Long time ago I read a story for a low power application that also had some LED's.
When the leds were off, the pins were switched to input to save some uA from the battery.

And then the circuits started failing by premature battery drain...

It tuns out that some LED's work as photocells and can generate a voltage when enough light shines on them, and this was enough to get the input stage of the uC into it's linear region where it shunts current from the power input to GND...

nemail2:

--- Quote from: Doctorandus_P on June 25, 2022, 05:05:49 pm ---Long time ago I read a story for a low power application that also had some LED's.
When the leds were off, the pins were switched to input to save some uA from the battery.

And then the circuits started failing by premature battery drain...

It tuns out that some LED's work as photocells and can generate a voltage when enough light shines on them, and this was enough to get the input stage of the uC into it's linear region where it shunts current from the power input to GND...

--- End quote ---

NICE! Fortunately I have a buffer between the IO pins and the LEDs and also I'm taking measurements regularly to make sure there is no unexpected power drain.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod