ADC counts jump 10 counts or so with SAMD21

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
abear7
 
Posts: 21
Joined: Sun Jul 05, 2015 12:01 pm

ADC counts jump 10 counts or so with SAMD21

Post by abear7 »

Hello,

I've noticed the ADC readings seem to jump around 10-100 counts. I connected a 1.2V battery with a .1uf capacitor right on the ADC0 pin and it still happens. I can average it out if I take about 20 samples or so and take the average but that is slowing things down. I would prefer to find a solution to this if possible. I've tried the 3-4 different references and also 10 or 12 bit resolutions and there's not much difference. The 5V is solid too. Any one else seeing this?

Thanks

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by adafruit_support_mike »

Try putting a 1uF capacitor between the Aref pin and GND. If the input is stable, the next suspect is the reference.

User avatar
abear7
 
Posts: 21
Joined: Sun Jul 05, 2015 12:01 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by abear7 »

Thanks for the suggestion but that didn't help. I grounded the A0 pin right next to the GND pin which is the very next pin on the header and it's the same. Sometimes I get 0 then other times 20-40 counts from the ADC. I'm using the internal 2.23V internal reference now but I have tried the others and get similar results no matter what. I have another feather with M0 logger I'm going to try to see if there's any difference. I'm using the Feather LE Bluetooth now.

User avatar
abear7
 
Posts: 21
Joined: Sun Jul 05, 2015 12:01 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by abear7 »

Here's an example of the samples, taken about 1 second apart with a NiMH battery connected to A0 pin.
ADC count followed by calculated voltage. count * 2.23 / 4096;

2554 1.390
2575 1.402
2572 1.400
2573 1.401
2571 1.400
2571 1.400
2579 1.404
2572 1.400
2534 1.380
2571 1.400
2577 1.403
2562 1.395
2570 1.399
2571 1.400

Also happens on another board M0 logger and A3 input.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by adafruit_support_mike »

Hmm.. the ADC is rated for up to 15 LSB of error, but it sounds like you're seeing noise outside that.

What are you using as a power source?

User avatar
abear7
 
Posts: 21
Joined: Sun Jul 05, 2015 12:01 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by abear7 »

A computer USB port and also tried a 5V battery bank. 5V looks good and plus I would think if there was any noise that would be filtered out by the 3.3V voltage regulator.

User avatar
T_Mo
 
Posts: 91
Joined: Thu Mar 15, 2018 7:10 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by T_Mo »

I'm also doing some 1.2 volt battery testing, and see two problems:
1) Large errors in the ADC voltage readings. Typically the voltage reported by the ADC is around 10% too high compared to an accurate multimeter.
2) I have to use a 90% exponential filter to smooth out the ADC noise.

For example, I've got a program that measures the battery voltage (on input A2) and cuts off the discharge (by controlling a MOSFET in the discharge path) when the battery voltage is < 1.0 volts. When I put a volt meter on the battery, it's actually at 0.9 volts when the ADC reads 1.0 volts.

User avatar
abear7
 
Posts: 21
Joined: Sun Jul 05, 2015 12:01 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by abear7 »

T_mo,
Expect there to be a big voltage difference between load and no load measurements due to battery internal resistance mainly. I get very close dead on accuracy, my problem is just with the jumps.

The internal references have some tolerance. So the best way I found to correct for this is to do a calibrate. Use a good DVM to measure the voltage and adjust the vref value in your code so the readings match.

User avatar
T_Mo
 
Posts: 91
Joined: Thu Mar 15, 2018 7:10 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by T_Mo »

Sorry to divert the thread onto accuracy, but this is a really weird problem that I haven't been able to diagnose (I"m a 30-year experienced electrical engineer, so I am pretty familiar with these concepts). To explain what I found today:

To measure the voltages (and be compatible with both LiPo and NIMH batteries) I had been using a 2:1 voltage divider (two 30K ohm resistors in parallel). With that, I have about 10% voltage error. The voltage measured via the ADC is about 10% higher than what I measure with a good DVM. That's really horrible accuracy.

Since the Feather M0 Express schematic does the same thing (using two 100K resistors in series, with the ADC connected to the midpoint), I thought maybe the input impedance of the ADCs was a bad match for the 30K resistors. So I changed them to 130K resistors (not having an 100K's in my old parts kit). That made things even worse, now the voltage error is about 20%.

It's very strange.

User avatar
abear7
 
Posts: 21
Joined: Sun Jul 05, 2015 12:01 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by abear7 »

Hi, What VREF are you using?

User avatar
T_Mo
 
Posts: 91
Joined: Thu Mar 15, 2018 7:10 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by T_Mo »

The default Vref is the internal 3.3 volts. That's also what I get if I display the pin.reference_voltage property.
I have a 10 uF electrolytic cap connected from the Vref pin to ground, but it didn't provide any benefit. And I wouldn't expect it to, since I'm not using the external reference.

User avatar
abear7
 
Posts: 21
Joined: Sun Jul 05, 2015 12:01 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by abear7 »

You might try the 2.23V internal reference. That's what I use but I use a trimmer pot in a voltage divider and use that to calibrate against a DVM reading.

User avatar
T_Mo
 
Posts: 91
Joined: Thu Mar 15, 2018 7:10 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by T_Mo »

The 3.3 v reference should work, and a trimmer pot shouldn't be needed.
Maybe there is something broken (or not initialized correctly) in the python object constructor for the analog inputs.

User avatar
T_Mo
 
Posts: 91
Joined: Thu Mar 15, 2018 7:10 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by T_Mo »

How do you set the reference voltage? I didn't see anything about that is the library documentation.

User avatar
T_Mo
 
Posts: 91
Joined: Thu Mar 15, 2018 7:10 pm

Re: ADC counts jump 10 counts or so with SAMD21

Post by T_Mo »

Update:
I've made some progress on this issue by tearing down the circuit I was building, and just doing some basic tests of using voltage dividers with the ADC inputs.

Turns out, the larger the resistor value used in the voltage divider, the larger the magnitude of the measurement errors. The circuit is built on a solderless protoboard, which has a lot of capacitance. High value resistors and high capacitance was (I believe) causing the ADC inputs to not reach their true value during the ADC sample period.

Sadly, I don't know how to control the ADC sample time using Adafruit's CircuitPython library, that seems to be missing from the documentation. If you want to read the specs, it's Section 33 (around page 700) of the SAMD data sheet for the processor.

So, 2.2K resistors worked great, 15K resistors were sort of OK, and 130K or higher resistors gave terrible results.

Since I needed two dividers, I had to pick a value for which I had four identical parts in my junk box. So I ended up with 8.2K dividers, and the ADC measurements are now within a reasonable range of accuracy.

I still of course have the typical 7 LSB of measurement noise, but that's how this processor works.

I was a little confused by the problem with larger resistor values, because the Feather M0 Express board has a 100K voltage divider to measure the LIPo battery voltage. But since those traces are short and on the circuit board, the capacitance is low, so I think that's why the ADC readings for Vbat are fairly OK, but my similar measurements using 100K resistors on the protoboard were awful.

Lesson learned - be careful of the limitations of solderless protoboards. It's been a long time since I used mine.

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”