Interrupts on ADC possible?

Alright, say my micro is going along doing it's 'thing', then when i rotate a pot I want it to detect it and then react accordingly. The problem of course being I can't waste time doing the analog read all the time. Is there any way to do this with arduino? Or do you have to do it in AVR =(

I was planning to divide the pot into just 4 or 5 so I guess I could use a dual pole rotary switch, and use one of the poles to cause an interrupt each time you rotate using attachinterrupt... But this involves more hardware which I'd like to avoid!

Any help would be appreciated!

If the interrupt level was not changeable you can use the analogue comparator.

You could also change the trip point by setting a reference using PWM I would think.

But you can't interrupt on an ADC value.


Rob

You can use a rotary encoder instead of a potentiometer. These generate digital state changes every 1/N rotations (where N is typically 16 or some small number).

--
The Rugged Circuits Yellowjacket: 802.11 WiFi module with ATmega328P microcontroller, only 1.6" x 1.2", bootloader

The problem of course being I can't waste time doing the analog read all the time

What else will the board being doing?

Thanks for the replies!

Making a tap tempo LFO(low frequency oscillator). So I have a pushbutton for the tap. The micro then measures the time between two taps, that time then makes up the period of the waveform. The pot is then used to select between some waveforms sine, triangle, sawtooth etc which each have their own array, then that goes through PWM to an LED.
The waveforms will have 256 samples per period. To keep the waveform in time I'll have to do an analogRead for each sample and see if it's changed then. AnalogRead takes 100us right? So for one period it will take at least 100us*256= 25.6ms= 40Hz which i guess is more than fast enough afterall... audible range lol. I want a max speed of something like 10Hz. (I don't expect someone to push the pushbutton that fast but I possibly want to have a multiply switch where it will have 2x and 4x speeds.)

So I guess it might work after all? BUT I haven't accounted the time for the micro to do it's other operations, I'm assuming here the analogRead is the bulk of that time. Is it okay to assume that? Is there a way to figure out how many cycles it's going to take to do x y z? In a PIC it's fairly easy but with writing this in C??

AnalogRead takes 100us right?

I believe it is 125 us.

I want a max speed of something like 10Hz. (I don't expect someone to push the pushbutton that fast...

Depends on the button and the human. A good button with a fast hand will do better than that. But, your application does not have to be everything to everyone. Or does it?

So I guess it might work after all?

Seems doable. There are some things you can bring to bear that will make a very significant difference...

• It is not necessary to read the potentiometer every pass through loop. We are talking about a (relatively speaking) very slow human.

• Use the analog-to-digital converter in an asynchronous fashion.

• Configure the analog-to-digital converter to run continuously (in the background). What does Atmel call it ... there it is .. Auto Triggering.

• Use a timer interrupt to perform the time-critical tasks (updating the PWM output). I believe this has been recommended: http://www.arduino.cc/playground/Main/MsTimer2

But, I suggest you try fixing the problem after you determine there is a problem.

BUT I haven't accounted the time for the micro to do it's other operations, I'm assuming here the analogRead is the bulk of that time.

From what you've described that is very likely the case.

Is it okay to assume that?

I would.

Is there a way to figure out how many cycles it's going to take to do x y z?

Yes. But, again, I suggest you do that after you determine there is a problem.

In a PIC it's fairly easy but with writing this in C??

Like the PIC, for an AVR processor there are various techniques you can use to either measure the processing time or calculate the processing time.

Use a rotary encoder connected to pins 2 and 3 (assuming a Uno), then you will have more positive selection between waveforms and you can use interrupts 0 and 1 to service the encoder.

You could use the end of conversion interrupt to continually update readings from the ADC, and retrigger the conversion.
Then all you need to do is read the most recent value.