Can ADC pins handle interrupts?

Mikler

Member
Hi!

(I am using a 28X1)

Forgive a newbie question. In order to monitor a push-button switch, I have the interrupt function working fine on 'In 0' (physical pin 11) on the 28X1.

However, I would dearly love to have one more output. Therefore, rather than use 'In 0' for the interrupt, is there any way that I can use one of the four unused ADC pins?

Comments appreciated.

Thanks

Mik
 

lbenson

Senior Member
To the best of my knowledge, the 28X1 ADC pins cannot be used as interrupt generators. However, if the push-button switch is not time-critical to within fractions of a second and you have a common structure where everything happens in a big loop, if you pass through the loop every second or so, you can just query the pin as an ordinary digital input on port A, for example:

if porta pin0 = 1 then
[do what you want]
endif
 

womai

Senior Member
Another option is to set up a timer interrupt which gets called, let's say, 20 times per second and checks the ADC pin's states. That way your main program does not need to bother with that and it pretty much works like the "true" Picaxe interrupt.
 

Mikler

Member
Womai

Can you be a bit more specific as to how I would set this up? (or point me an the correct direction?) - It sounds like it would do the job?

Thanks

Mik
 

Andrew Cowan

Senior Member
Womai's method (as far as I understand):

Code:
set an interrupt to get called 20 times a second

interrupt:
if ADC pin is in certain condition, then goto this routine
return

'rest of program
A
 

Mikler

Member
Thanks very much!

I will work thru it to try and understand it (confused by events_per_sec and timer_pre_load)

But this looks the way to go!

Mik
 

womai

Senior Member
Have a good read of the Picaxe Basic manual about the timer and timer interrupts. But in a nutshell:

The internal timer counter (not directly accessible to you) counts up in regular intervals. The preload value defines which value it starts (and gets re-initialized after it reaches 0xffff). So the higher a preload value you set, the faster this "fast counter" will wrap around and get re-initialized.

The timer variable in the Picaxe Basic counts the number of wraparounds that have occured. Once that "slow" counter warps around (has already reached 0xffff and thus goes back to zero at the next increment) you get an interrupt. In my sample code I initialize this counter with 0xffff (65535) so each time the "fast counter" maxes out you get an interrupt. If you set it e.g. to 0xfffe (65634) it would only create an interrupt after the second fast timer overflow.

The constant definitions in my sample code simply figure out the correct preload value so the fast counter overflows the desired number of times per second.

Wolfgang
 
Last edited:
Top