Interrupt?

taesoon737

New Member
I have a simple timer counting up to 60 seconds and i want it to stop counting when a button is pushed. I want this to happen every time i push the button but someone told me that i cant use the interrupt command because it will not allow the interrupt to happen again afterwards. Do you have any solutions on what command i should be using, instead.
 

Jamster

Senior Member
You can use the inturrupt command but in the interrupt routine you will need to re-initialise the interrupt as it will reset when it is triggered.
 

MartinM57

Moderator
...but someone told me that i cant use the interrupt command because it will not allow the interrupt to happen again afterwards..
Who would that be then? Interrupts wouldn't be much use if you could only initiate them once :)

What you have to do in PICAXE-land (and most other microcontroller-lands) is re-enable the interrupt at the end of the interrupt: routine

Have a read of Manual 2 SETINT command, especially the code examples at the end
 

g6ejd

Senior Member
I would make your interrupt count up to 60 in some variable providing some 'count-enabled' flag was set, and back to zero again when it overflows, it can do that in the background, then as soon as the foreground task detects a switch closure (your push-button) it clears the 'count enabled' flag so stopping the incrementing and as soon as you release the push-button, the code sets the count-enabled flag again.

init:
count_enabled = 1
SETINT ...

start:

IF push_button = closed THEN
count_enabled = 0
ELSE
count_enabled = 1
ENDIF
GOTO start

interrupt:
SETINT ... renable your interrupts ' it depends how you got here, e.g. timer time-out, or input transition
IF count_enabled = 1 then
seconds = seconds + 1
IF seconds > 60 THEN
seconds = 0
ENDIF
ENDIF
RETURN
 
Last edited:
Top