Multiple port interrupts

Coyoteboy

Senior Member
Just having a think about my pin layout for this project, feeling a bit confused with the different revisions of the 40 pin chip, there seem to be so many "applies to this but not this" exceptions and new commands that work on certain versions but not others.

I have many inputs (7 or so, User Interface buttons) that I was hoping to find with interrupts due to their fairly momentary nature and not requiring immediate response, while "manually" polling 7 other inputs (which are reed position switches with relatively long "on times" and so are easier to catch with if pinX = 1.... ) Am i right in assuming you cannot have multiple port interrupts (only one interrupt essentially)? I'm confused as to how the normal setint and the new hint pins differ in "end user" operation - the normal interrupts poll every pin between each command line, the new ones do what? Is it simply to speed up the process, how long does it take to poll the pins assuming 7 pins in the mask?

One interesting "interrupt expander", I suppose, would be have the 2 banks of 7 connected in parallel through an array of diodes, each 7 commoned together and linked to a pin in a pair of "interrupt pins", then in the interrupt identify the port and read all pins on that port.

Or possibly continuously alternate between interrupting on 2 different ports, hoping this occurs fast enough to catch either set.

What are your thoughts on the matter?
 

BCJKiwi

Senior Member
For a start, HintSetup only works on 3 pins so probably won't be much use if you need 7.

setint will work on the whole port and is either a single pin, or multiple pins in an AND manner, or, with the Chips supporting the NOT modifier, multiple pins in an OR manner.

However, the biggest issue when dealing with multiple pins in the OR manner, is to sort out which one caused the interrupt. If time is not critical, probably simpler to poll.

The let var = pins is useful as it captures the state of the pins of the port, then the var can be tested to see which one(s) were high/low.
Code:
 let Pin_State = pins
   If Pin_State = %00000001 Then
     gosub Button_0
   ElseIf Pin_State = %00000010 Then
     gosub Button_1
   ElseIf Pin_State = %00000100 Then
     gosub Button_2
   EndIf
 

inglewoodpete

Senior Member
I have found that using interrupts was a reliable way to read a keypad. I had 8 keys that were read in serially after they caused an interrupt (9 keys {3x3 matrix} to 2 input pins via a diode matrix). It is rare for a keypress to last less than 50mS on the keypad I used.

The only 'special' thing I had to do was run the PICAXE at 8MHz. 4MHz was just too slow to read the last couple of keys reliably with serial.

Get the breadboard out and experiment!
 
Top