Pages: 1 [2]   Go Down
Author Topic: analogRead problem with IDE 1.5.5 libraries  (Read 3629 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12048
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I presume that delay only matters if switching channels?  It would be a shame to slow down
the common case by a factor or 2 or 3 needlessly?
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can confirm that the delay is not necessary if the channel is not switched. Hence the delay can be made conditional.

However, after thinking over night about the matter, another aspect came into my mind. What is the exact effect to the analog section of the SAM when more than one channel is enabled, even if for short time only? Does this mean that the related analog input pins are then electrically connected with low impedance? If that was the case, this way of managing the channels would not be recommendable at all, since this could then destroy the related switches in the SAM if the source impedance at those pins is sufficiently low. A usual low source impedance would be e.g. some filter capacitors at the analog input pins, which could discharge quickly over connected analog input pins.
Logged

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What is the exact effect to the analog section of the SAM when more than one channel is enabled, even if for short time only? Does this mean that the related analog input pins are then electrically connected with low impedance?

Looking at the logic diagram on the datasheet it seems that there is a multiplexer before the ADC, so theoretically only one pin at a time can be connected to the ADC.

@Embed
may you post some more information on your test setup? May the inaccuracy you're experiencing be due to high impedance on your analog source?

Logged

C.

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The inaccuracy for my test setup, noticed with the latest patch, is probably due to the high impedance.
I generate the test voltages with 100k trimmers, followed by 10k resistors in series to the analog inputs.
I guess I understand now this effect. With older libraries, the SAM introduced a startup time that was long enough to charge the input capacity of the AD converter. With the latest patch, this startup time is omitted. So there should be a note in the Arduino documentation that specifies the max. input impedance without recognizable effects on accuracy.

One question still remains even after your explanation:
Quote
Looking at the logic diagram on the datasheet it seems that there is a multiplexer before the ADC, so theoretically only one pin at a time can be connected to the ADC.
If only one pin can be connected to the ADC at a time, why is it then necessary at all to disconnect the old channel, since it should be disconnected at the time when the new one is connected?  Disconnection would then only be necessary if you want to have the ADC going to sleep as in the libraries until IDE 1.5.4. This part of the code could then be removed from the analogRead function. However, should it be necessary to disconnect the old channel in order to get correct results, then it would not be the case that only one input is connected.
Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12048
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The whole ADC architecture is designed to be able to sample any subset of the analog
channels, in any order, at any sample rate (from one of many clock sources) and write
the results direct to memory buffer via DMA.  You don't have to enable all of this
stuff, but do need to say exactly which subset of channels are active (since a sample
event causes them all to be sampled in the defined order and various status bits updated
and/or interrupts triggered and/or DMA writes performed).

If you set the enabled set to empty the ADC automatically drops into power-save
mode.  So the best way to drive it for analogRead() is enable new channel, disable old channel (if different), trigger a reading.
Logged

[ I won't respond to messages, use the forum please ]

Pages: 1 [2]   Go Up
Jump to: