two stage analog read

Hello,

Is there any way in Wiring to do the kind of two stage analog read you can do on a PIC chip where you start a conversion, then keep doing something else while you test busy or wait for an interrupt, then read the final value when it's ready?

I'm currently working on a project to build a position sensitive drum pad using the arduino board, and although I don't need this function yet, I can see it would be very useful when trying to control more than one pad from the same board.

If there isn't any way to do this at the moment, are there any plans to include it in the future, or else how difficult would it be to write a library to do this?

andy

The key words are Input Capture , Mem has an example here:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1201890734/2#2

Is there a way to use the input capture pin together with the analogue inputs?

What I'm really looking for is 4 functions like this:

void AnalogStart(pin) // begins analog conversion on a pin
char AnalogBusy(pin) // tests whether conversion is complete
int AnalogResult(pin) // reads result of completed conversion
void AnalogInterrupt(pin,func) // sets func to be the interrupt handler for analog conversions on a pin.

I'm sorry, I misread. I've seen a status of analog read complete somewhere in the atmega datasheet so I'm sure it can be done.

Edit: There is a reference to an ADC Conversion Complete interrupt on page 59.

OK. Thanks for this. I had a feeling it must be possible but didn't see how to do it in wiring, so I guess the answer is to write my own library when I need it.

I guess, You can define the interrupt with
ADC_vect or SIG_ADC
(from http://www.it.lth.se/digp/Avr-libc-1.4.3/group__avr__interrupts.html)

Maybe take a look at wiring_analog.c in:
[arduino install]\hardware\cores\arduino to how the default implementation is done too.

this looks like the crucial bit.

int analogRead(uint8_t pin)
{
        uint8_t low, high, ch = analogInPinToBit(pin);

        // set the analog reference (high two bits of ADMUX) and select the
        // channel (low 4 bits).  this also sets ADLAR (left-adjust result)
        // to 0 (the default).
        ADMUX = (analog_reference << 6) | (pin & 0x0f);

        // without a delay, we seem to read from the wrong channel
        //delay(1);

        // start the conversion
        sbi(ADCSRA, ADSC);

        // ADSC is cleared when the conversion finishes
        while (bit_is_set(ADCSRA, ADSC));

        // 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;

        // combine the two bytes
        return (high << 8) | low;
}

It's pretty obvious from here how to adapt it to do what I need, so thanks for the pointer.

andy

Some interesting details here too. Not sure, but it sounds like in free-running mode you can basically poll all the different channels?