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.

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.

int finishAnalogread() {#if defined(ADCSRA) && defined(ADCL)// we have to read ADCL first; doing so locks both ADCL// and ADCH until ADCH is read. reading ADCL second would// cause the results of each conversion to be discarded,// as ADCL and ADCH would be locked when it completed.low = ADCL;high = ADCH;#else// we dont have an ADC, return 0low = 0;high = 0;#endif