Author Topic: [SOLVED] SAMD21 ADC 100ms delay after wakeup or you get messy readings  (Read 988 times)

0 Members and 1 Guest are viewing this topic.

Offline nemail2Topic starter

  • Regular Contributor
  • *
  • Posts: 206
  • Country: at
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!
« Last Edit: June 25, 2022, 03:31:40 pm by nemail2 »
Boron rhymes with moron
 

Offline nemail2Topic starter

  • Regular Contributor
  • *
  • Posts: 206
  • Country: at
Re: SAMD21 ADC 100ms delay after wakeup or you get messy readings
« Reply #1 on: June 25, 2022, 02:38:23 pm »
That sounds like a very long time.
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.

* 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.
Currently I'm powering from my lab power supply which is on all the time, only the microcontroller goes to sleep.

* 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.
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.

* 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.
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... :(

* 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.
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.

* 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.
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.
Boron rhymes with moron
 

Offline nemail2Topic starter

  • Regular Contributor
  • *
  • Posts: 206
  • Country: at
Re: SAMD21 ADC 100ms delay after wakeup or you get messy readings
« Reply #2 on: June 25, 2022, 03:31:27 pm »
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.
Boron rhymes with moron
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3358
  • Country: nl
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...
 
The following users thanked this post: nemail2

Offline nemail2Topic starter

  • Regular Contributor
  • *
  • Posts: 206
  • Country: at
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...

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.
Boron rhymes with moron
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14470
  • Country: fr
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...

Can be something to really consider indeed if you drive LEDs from GPIOs directly.
All LEDs do this actually. But depending on their spectrum and whether their shell is fully transparent or colored, you'll get various results.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf