Hi
I just posted an item on how to use an analog input correctly and what goes wrong, with spice examples.
Since the question has come up a lot, perhaps it will be of use.
Please take a look, tell me what you think.
Hi
I just posted an item on how to use an analog input correctly and what goes wrong, with spice examples.
Since the question has come up a lot, perhaps it will be of use.
Please take a look, tell me what you think.
Please, mention which Arduino and which analog channel you are handling.
This will apply to any Arduino that has a SAR type ADC. I believe that means most or all of the Arduinos, and Teensys. it applies to some degree to the Sigma Delta and flash ADC, too.
The treatment is very bare bones. I wanted to make it accessible and easy to understand for someone who is laboring with the problem.
There are lots of application notes on kickback for all of the adc architectures. Here I was trying to strip it down to the bare minimum and capture the ideas in easy to understand spice graphics
So this is about the simple business of getting the right answer from your ADC and what to do about the spikes in something like maybe 3 or 4 examples.
(I mention kT/C noise, and allude to 1/f noise problems, but only in passing.)
Sincerely, give it a perusal. I think it can be interesting and helpful.
@GolamMostafa that turned out to be a very productive question.
Attached is a spice model for a thermistor connected to the analog input of the UNO R3, using parameters from the ATmega datasheet.
Notice they put a large resistor in front of the switched capacitor network. That reduces the kickback spike, and it reduces the current needed to charge the sampling cap. So that is a kind of fool-proofing for doing things like connecting a large resistor divider to a SAR input.
But as a result, (a) it takes longer to charge the sampling cap, and (b) it limits what you can accomplish using an opamp buffer or RC to drive the ADC. I would say if you need to do precision work, use an external ADC. But this is only 10 bits anyway. Still you want it to be at least accurate to something like 10 bits and not wildly all over the map.
Anyway, here is the output from the spice model. The datasheet gives a range for the resistor, I chose something sort of load mid range.
As you can see it is a solid "miss" for the sampling cap not reaching the input voltage before the end of the sampling window.
UNOR3_SAR_voltagesource_thermistor10K.asc.zip (829 Bytes)
Are you rating the design quality of the internal ADC of the ATmega328P MCU?
I understand that the performance of the ADC agress with what has been documented in te data sheets.
Anyway, I appeciate your deep study on the ADC.
I am modeling what is in the datasheet, with some approximation and abstraction.
I am realizing, now finally, why these things are not for serious measurements, besides that this one is only 10 bits anyway.
What they have done is introduce something that is less than ideal for a sar, to support a use case that amounts to an abuse of a sar in other contexts, and at the same time, pre-empt the possibility of using it a more normal way.
In other words, normally you would take into account the kickback, and supply charge either as current from a buffer or better, a charge reservoir from the cap in an RC replenished by a well chosen opamp.
Now, that resistor inside the chip limits the current draw, so you can just sit and wait until the cap charges up and meanwhile it only draws a ma or less. On the other hand, if you decide you want to supply current so it can settle in short time, as is usually done, you are out of luck. That internal resistor will stop you in the same way that it enables that hobbyist disregard for source impedance connected to a sar input. So, it is really perverse. It means it is a toy, you shouldn't even think about using the analog inputs for measurements for a lab. You have to use an external adc. Fortunately the mcu part is pretty good.
All that you are discovering on the ADC Module of the ATmega328P MCU are its features and NOT flaws. It has been clearly mentioned in the data sheets that the error of the ADC is +/- 2 LSB.
When you say thet the MCU part is pretty good - what have you wanted to mean? It is a digital logic and has been designed to work and it works as per prescribed specifications. Could you discover if there is any undocumented opcode like the legendary 8085?
Well.... ibm used to call things "features" and document them, too.
This is a design that uses a kluge to accommodate a misuse case at the cost of most of the normal use cases. They have to document it, it is a huge exception from what you expect in a sar.
What I mean by the latter, is that the MCU is useful. Especially those boards with the newer ARM processors. You can hook this or those up over SPI to an external ADC or DAC or whatever, designed to as high a standard as you like, and build a pretty good instrument.
(That is the idea behind this: Announcing the SPI Instrumentation project)
One important result here, is to realize that we should not expect to use the internal analog interface for very much beyond a very limited sort of measurement, crude temperature, pressure etc.
I started looking at this to understand whether those $10 instrument cards sold on the hobby sites and amazon are useful for anything serious. The answer is probably not. They would have to have their own analog-digital conversion on the board, not relying on the above, and just the parts to do that, cost more than $10.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.