08m2 interrupt

steviejay

Member
Hi
I have set up 08m2 as a timer for the baitlauncher...works fine,magnet over the hall effect moves thru 3 stages and sets the timer at that stage when I remove the magnet..that bits works..
but I have a reed switch to interrupt so I can stop the thing if I need to ..but i cant interrupt once the timer starts, only when its waiting..
My question:can I interrupt this code on the 08m2 ? Any help is appreciated. Steve

Code:
setint %00001000, %00001000,c

main:
sertxd ("back at main ",13,10) 

pause 50
high c.4
pause 50
low c.4
pause 50
high c.4
pause 50
low c.4
pause 50
high c.4
pause 50
low c.4
pause 50
high c.4
pause 50
low c.4
pause 50

wait 1
sertxd ("reading hall sensor in main",13,10)
readadc C.1,b0 ; read ADC1 into variable b0
sertxd("The value of b0 is ",#b0,13,10)
if b0 > 150 then fxtimerreadyA ;  
if b0 < 150 then goto main ;  

goto main



fxtimerreadyA:	'where if you remove magnet fxtimerA will activate but keep it and move to fxtimerreadyB

for b0 = 1 to 5	'use b0 variable memory space for a loop flash 5 times		  
high C.4		'output pin B.5 on	
pause 250		
low C.4			
pause 250			
next b0

sertxd ("reading hall sensor in fxtimerreadyA",13,10)
readadc C.1,b0 ; read ADC1 into variable b0
sertxd("The value of b0 is ",#b0,13,10)
if b0 > 150 then fxtimerreadyB  
if b0 < 150 then goto fxtimerA  		
				




fxtimerA:		'the first timer programme

sertxd ("in fxtimerA mode ",13,10)
high c.4
high c.2
for b1 = 1 to 10 ; 10 loops 
pause 60000 ; wait 60 seconds 
next b1 
wait 1
low c.4
low c.2
sertxd ("finished timer ",13,10)
pause 500

goto main		'go back to main

fxtimerreadyB:	'where if you remove magnet fxtimerB will activate

sertxd ("in fxtimerreadyB ",13,10)

for b3 = 1 to 5	'loop the LED	  
high C.4			
pause 500		
low C.4			
pause 500			
next b3

sertxd ("reading hall sensor in fxtimerreadyB",13,10)

readadc C.1,b0 ; read ADC1 into variable b0
sertxd("The value of b0 is ",#b0,13,10)
if b0 > 150 then fxtimerreadyC  
if b0 < 150 then goto fxtimerB  




fxtimerB:
sertxd ("in fxtimerb ",13,10)
high c.4
high c.2
for b1 = 1 to 20 ; 25 loops 
pause 60000 ; wait 60 seconds 
next b1 
wait 1
low c.4
low c.2
sertxd ("finished timer ",13,10)
			
wait 1
goto main

fxtimerreadyC:
sertxd ("in fxtimerreadyc ",13,10)

for b5 = 1 to 5	'use variable b5 to loop LED 	  
high C.4			
pause 1000		
low C.4			
pause 1000			
next b5

sertxd ("reading hall sensor in fxtimerreadyC",13,10)

readadc C.1,b0 ; read ADC1 into variable b0
sertxd("The value of b0 is ",#b0,13,10)
if b0 > 150 then goto main  
if b0 < 150 then goto fxtimerC  




fxtimerC:
sertxd ("in fxtimerc ",13,10)
high c.4
high c.2
for b1 = 1 to 25 ; 25 loops 
pause 60000 ; wait 60 seconds 
next b1 
wait 1
low c.4
low c.2
sertxd ("finished timer ",13,10)
pause 500			


wait 1
goto main


interrupt:		
sertxd ("interrupting ",13,10)

if pin3 = 1 then interrupt	'if reed switch on pin3 is high(on)
low C.2
low c.4


wait 2
setint %00001000, %00001000

goto main
 

Goeytex

Senior Member
You need to put a "return" at the end of the interrupt routine since it acts as a "gosub".

Code:
interrupt:		
sertxd ("interrupting ",13,10)

do while pinC.3 = 1  '// Wait for c.3 to go low 
loop 
 
low C.2
low c.4
wait 2
setint %00001000, %00001000
return
When an interrupt occurs, the program saves the current program location. When the program reaches the return command the interrupt is re enabled and the program jumps back to where the interrupt occurred. If there is no return command the interrupt will not be re enabled.

See manual 1 Page 84
 

steviejay

Member
thanks for that quick reply, I think I get the sub procedure re enabling the interrupt bit, but I have messed with it and cant go back to main: it gets hung up in the loop do... I just want to reset the whole thing back to the start which it didnt when I dropped that code in there..Im doing something wrong
kind regards steve
 

Circuit

Senior Member
thanks for that quick reply, I think I get the sub procedure re enabling the interrupt bit, but I have messed with it and cant go back to main: it gets hung up in the loop do... I just want to reset the whole thing back to the start which it didnt when I dropped that code in there..Im doing something wrong
kind regards steve
You have already stated your own solution without realising it... if you want "to reset the whole thing back to the start" then simply put a RESET command in your interrupt rather than the "go to main" that you are using at the moment. The RESET command will behave as stated in the manual Manual 2 Page 192);

"The reset command is the software equivalent of pressing the external reset switch (if present). The program is reset to the first line and all variables, stacks etc are reset."
 
Top