Hardware Interrupts - 40X2

techElder

Well-known member
Referencing this thread and according to the manual,

The hintsetup command enables the hardware setting of the flags only, it does not trigger an actual PICAXE program interrupt.
Is there any advantage to hint0 / flag0 / hint0flag compared to monitoring B.0 on a 40X2 in a really tight loop?
 

Goeytex

Senior Member
Yes,

Once the flag b it is set. it will remain set until cleared in software. Unlike monitoring a pin in a tight loop, this allows detection of very short pulses. Even in a tight loop a short pulse could easily be missed. For example, the loop checks the pin every 200 us and a 20 us pulse is applied to the pin. IT will most likely be missed.

With hintsetup, a 20 us pulse will set the flag bit and the program can test at any time if the flag bit was set. No need for a tight loop, allowing the processor to do other things.
 

techElder

Well-known member
So, is the middle ground to monitor the flag0 in a really tight loop ... without generating the interrupt? (There is nothing more important to do until pulse happens.)

In a timing app its just as important to know when the "20 us pulse" happens as it is to detect that it did happen.
 

Buzby

Senior Member
So, is the middle ground to monitor the flag0 in a really tight loop ... without generating the interrupt? (There is nothing more important to do until pulse happens.)

In a timing app its just as important to know when the "20 us pulse" happens as it is to detect that it did happen.
No.

If your pulse is 20uS long, then only the hardware interrupt will tell you that the pulse has been seen, even if the pulse is gone by the time the PICAXE executes the relevant code.

The PICAXE checks, for either kind of interrupt, at the end of each PICAXE each instruction.

If each instruction in a loop takes, say, 100uS, then with 'hint' you can tell that a pulse happened within the last 100uS. With 'int' you will only get an interrupt if the pulse is actually active at the end of an instruction.
 

techElder

Well-known member
IWP suggested this text be added to the manual:

"The hardware interrupt is a two stage process where the edge detection, configured via the hIntSetup command, sets the appropriate bits in the 'flags' byte. The SetIntFlags command configures how the polling detects the a changed flag state and results in the Interrupt routine being executed when required."

I was surmising that if the "edge detection" sets the bit in the 'flags' byte, then I could monitor that flag byte to detect the edge (in time.)

EDIT: Something like ... WAITFORPULSE: if flag5 = 0 then WAITFORPULSE
 
Last edited:

hippy

Technical Support
Staff member
I was surmising that if the "edge detection" sets the bit in the 'flags' byte, then I could monitor that flag byte to detect the edge (in time.)
Not sure what the "in time" part means.

Using direct pin monitoring you will continue to the next statement only if the input is asserted at the time it is tested.

Using hardware interrupt flags you will continue to the next statement if the input is or has been asserted prior to the time it is tested.

It allows you to not miss short activations of the input or activations which are no longer present when the test executes, but it won't do anything to guarantee continuing any sooner after the input has activated.

Interrupt flags are like telephone answering machines noting you have had a call even when not there.
 

Buzby

Senior Member
I was surmising that if the "edge detection" sets the bit in the 'flags' byte, then I could monitor that flag byte to detect the edge (in time.)
That's exactly what the PICAXE firmware is doing at the end of each instruction, checking to see if the flag has been set. You can't do it any faster than that.
 

techElder

Well-known member
Thanks, guys. Just trying to make sure that I've covered all avenues of detection before I stop looking for "the best" way.

All good info.
 
Top