Interrupting on flags.

BeanieBots

Moderator
I currently have a 28X2 program which uses the dedicated hardware interrupt pins to generate an interrupt.

hintsetup %01110111 ‘ enable all 3 pins (trigger when pushed)
setintflags %00001000,%00001000 'Interrupt if ANY button is pushed

This works very well.

I'd like to ADD an interrupt call if the internal timer overflows.
That is, if any one of the buttons is pushed, OR the timer overflows, the interrupt routine will be called.

Is this possible?
 

Technical

Technical Support
Staff member
Yes, this is achieved by using NOT and inverting your condition.

So basically you interrupt if the 'hint and timer are not both 0' - which is exactly the same as saying interrupt 'if either go high'.

setintflags not %00000000, %10001000
 

MartinM57

Moderator
Why not just:

setintflags %10001000, %10001000

...as the flag byte is essentially an indication of which chip level interrupts are OR'ed together to define that a software interrupt has occurred.

Technical's
setintflags not %00000000, %10001000
is presumably equivalent to
setintflags %11111111, %10001000
...which enables every chip level interrupt but masks them with the timer and pin0/1/2 combination

...so also...in the general case, why would one want the flag and mask bytes to be different - all the manual examples and all my uses have them the same?
 

BeanieBots

Moderator
From my understanding (which not very high) that would require BOTH the button AND the overflow to cause an interrupt.
 

MartinM57

Moderator
Hmm...manual says

"If the particular inputs condition is true, a ‘gosub’ to the interrupt sub-procedure is executed immediately."

...which could be taken to imply AND, but it's not explicit either way.

So I can't see how
setintflags not %00000000, %10001000
which is (definitely?) equal to
setintflags %11111111, %10001000
particularly helps.

Bottom line - does Technicals suggestion do what you want (interrupt on pin0/1/2 OR timer)?
 

Technical

Technical Support
Staff member
setintflags not %00000000, %10001000
which is (definitely?) equal to
setintflags %11111111, %10001000
No, these lines are very different.

setintflags not %00000000, %10001000
means interrupt if timer and hint are NOT both 0
ie either goes high and the interrupt will occur

setintflags %11111111, %10001000
means interrupt if timer and hint are BOTH equal to 1
ie both must be high, not either
 
Last edited:

BeanieBots

Moderator
OK, tried it, Technical's solution does what I want.
More to the point, I've got my head around it now.

I can also testify that
setintflags not %00000000, %10001000 is most deffinitely NOT the same as
setintflags %11111111, %10001000

With my hardware setup it gave the same results (or appeared to) as
setintflags %10001000, %10001000
namely, BOTH must be active to generate an interrupt.

Either way, it now functions the way I want it to. Thanks.
However, I now have a problem with the timer function.
I'll start a new thread for that one.
 
Top