Go Down

Topic: Analog Input conversion time (Read 2 times) previous topic - next topic

Embed

The current Arduino Library (coming with IDE 1.0.1) only has one function to read analoge inputs. Since the conversion is started with the call of AnalogRead and the function waits until the conversion is complete, it is one of the most time-consuming function calls. Reading all 12 inputs one after each other lasts therefore ca. 1ms which is a long time if the sketch needs high sample rates or performs other time critical functions that have to wait for the conversion.
It is possible by register manipulation to increase the clock speed of the A/D conversion, but at the cost of 1bit accuracy with respect to standard frequency - and the register manipulation is processor dependent.
I suggest to have an additional function that allows to start a conversion but comes back immediately (e.g. naming it "AnalogStart"). The AnalogRead should then check whether an AnalogStart has already been called (means conversion is already in progress) and wait for the result; otherwise internally call AnalogRead first if one does not care so much about speed and staying compatible with existing Sketches.
This would allow to start the conversion of numerous analog inputs before the result of the conversion is needed, and then later to quickly read all of the analog inputs.
Especially for the new Arduino Due, it would be very unsatisfying to have a 32Bit ARM CPU with 87 MHz but still have to wait such long times for analog conversions.

Groove

It took you longer to write that post than it would to implement what you suggest.
Per Arduino ad Astra

Nantonos

#2
Oct 24, 2012, 02:41 pm Last Edit: Oct 25, 2012, 09:51 am by Nantonos Reason: 1

This would allow to start the conversion of numerous analog inputs before the result of the conversion is needed, and then later to quickly read all of the analog inputs.


Just checking - you are aware that

a) although there are multiple analog input pins, they are all multiplexed to one ADC?
b) the sample and hold capacitor in the ADC takes some time to charge, and takes longer if the inputs are switched?

Embed

Thanks for the hints - I knew that there is only one ADC, but did not have this in mind when I wrote my topic. Nevertheless, my suggestion makes sense, it just means one could start a conversion for a certain pin, doing some other processing, read the result, starting conversion of the next pin, and so on. The point is, not to waste processing time while waiting for the sample and hold capacitor to charge and performing the conversion.
@Groove: I would be very happy if I could implement this in 10 Minutes.

Groove

I'd be disappointed if it took that long.
You have the source of analogRead.
Per Arduino ad Astra

Go Up