Independent Interrupts on 28X2?

popchops

Well-known member
Hi there,

I am in a bit of a muddle with interrupts on Picaxe 28X2. I know there are three hardware interrupt pins: hint0, hint1 & hint3.

I also know that I can set up an interrupt response within a 'gosub' for an arbitrary Hi/Lo combination of these 3 faults.
  • Is it possible to setup a different response (different gosub) for different interrupt pins?
I will received increment (INC) and decrement (DEC) pulses from a quadrature decoder and I want to take the correct reaction in my program (increment or decrement) depending on the interrupt. Is it possible to use two interrupt pins independently?

Many thanks

Pops.
 

oracacle

Senior Member
Iirc you only have one isr. The normal routine for a encoder is to have the isr triggered on one pin and it's direction determined within the isr.

I believe it's a limit of the picaxe language.
 

AllyCat

Senior Member
Hi,

Yes, AFAIK unlike other processors/controllers, PICaxe doesn't have a "Vectored Interrupt" capability (i.e. different entry points), even though it has two separate interrupt mechanisms (SETINT and HINTSETUP) and has multiple interrupt input pins. Therefore, the first function of an Interrupt Service Routine (i.e. the code at the interrupt: label) may need identify the cause of the interrupt and branch accordingly (e.g. with ON .. GOTO ... , IF .... THEN ... or CASE ... SELECT , etc.). Or in the case of a "state machine" as might be used with a rotary encoder, a READ of a (Lookup) Table may be sufficient.

PICaxe does have the capability of being interrupted by several input pins or patterns at the same time: For M2s it's usually a group of pins on Port B, but with the X2s it seems that most Port.pins may be used to trigger an interrupt. In particular, the OR and NOT {AND} qualifiers allow an interrupt to be generated by a change on any one of several pins (by setting the mask and input parameters to the present input state before RETURNing), without the need for any additional external hardware.

Personally, I don't see much use for the "H" INT... function of the X2s, except to wake up from a SLEEP , or for internally-generated interrupts. But perhaps the three dedicated External Interrupt pins have a higher priority over (some of) the PICaxe System interrupts?

Cheers, Alan.
 

inglewoodpete

Senior Member
Personally, I don't see much use for the "H" INT... function of the X2s, except to wake up from a SLEEP , or for internally-generated interrupts. But perhaps the three dedicated External Interrupt pins have a higher priority over (some of) the PICaxe System interrupts?
The X2's "H" INT... has an added feature over the M2s. M2 interrupts are polled: the interupt condition must be valid between the execution of two BASIC commands.

For X2s, provided the firmware (internal/background) interrupts are not disabled, hardware pin interrupts will be latched during the execution of other (BASIC code) instructions. As you are probably aware, PICAXE basic instructions take tens, if not hundreds, of microseconds to execute. The HINT option allows very brief state changes to be latched/captured. You will still have to wait for the X2 to complete a (foreground) command to poll the HINT flags and generate an interrupt but at least the brief change-of-state is not lost.
 

popchops

Well-known member
You will still have to wait for the X2 to complete a (foreground) command to poll the HINT flags and generate an interrupt but at least the brief change-of-state is not lost.
Excellent. I can buy an LS7084 to perform the fast HW decoding of the optical encoder. Will transmit a 20 us pulse every 8 ms (at the highest expected rate of rotation).
I just need the PICAXE interrupt to recognise each short pulse, decode INC or DEC (from a 2nd more stable pin) and update the internal count variable quickly - then jump back into the main loop before the next pulse...
 
Top