Interrupt not reseting

misellers

New Member
I set an interrupt at initialisation that works fine, however, it doesn't seem to reset. The code below works fine on the simulator but apparently not on the chip 08M.

Any thoughts.

Matthew

Interrupt:
high LED
low 1
low 2
If pin4 = 0 then Interrupt
Gosub Rl1OnTime
Gosub Rl2OnTime
Gosub RlInterval
GoSub SbCreateTimeLine

Intwait:
If pin4 = 0 then Intwait
SetInt %00000000, %00010000 'Identical to the code setting the original which works
low 0
'pause 2000
goto start
 

MartinM57

Moderator
You should have a RETURN at the bottom of the interrupt routine - not a goto start

EDIT ..and it's bit weird anyway - it loops at the top waiting for pin 4 to go high (again), calls some other unknown routines and then there's another potential wait until pin4 goes high - is that what you really want? Won't it be high already?
 
Last edited:

misellers

New Member
Reply

Thanks for the reply.

You should have a RETURN at the bottom of the interrupt routine - not a goto start

My understanding is that a RETURN will take me back to where the interrupt occurred. I need to go back to the start of the main program. But I think you may have hit on the problem in that the original interrupt is still running. Strange that the simulator has no issues

.and it's bit weird anyway - it loops at the top waiting for pin 4 to go high (again), calls some other unknown routines and then there's another potential wait until pin4 goes high - is that what you really want? Won't it be high already?

This comes straight from the David Lincoln book apparently to make sure the interrupt condition doesn't exist when reseting the interrupt.
 

MartinM57

Moderator
A normal program structure for a (pseudo) real-time interrupt driven program would be:

Code:
   Do setup stuff including interrupt setup

   Do
      periodic stuff - might be nothing
   Loop

Interrupt:
   Do interrupt stuff
   Return
So you effectively return back to the start of the program - and there's probably no point in doing the setup stuff again anyway

An even better way would normally be:
Code:
   Do setup stuff including interrupt setup

   Do
      IF interrupt_has_occured = 1 THEN
          do interrupt stuff
          interrupt_has_occured = 0
      END IF
   Loop

Interrupt:
   interrupt_has_occured = 1
   Return
...but this requires an edge triggered interrupt so that you actually get back to the main loop quickly so that you can actually make something happen in a reasonable response time - but you would need an X2 part for that, plus the hintsetup command. The reason for doing it this way is to minimise the time spent in the interrupt routine, which is good practice for a number of reasons
 
Last edited:

MartinM57

Moderator
.and it's bit weird anyway - it loops at the top waiting for pin 4 to go high (again), calls some other unknown routines and then there's another potential wait until pin4 goes high - is that what you really want? Won't it be high already?

This comes straight from the David Lincoln book apparently to make sure the interrupt condition doesn't exist when reseting the interrupt.
Good point. Well made :)
 

misellers

New Member
Reply

Once again thanks.

I was thinking along the same lines with a Do...Loop Until.

Still a little strange that the interrupt isn't reset as the SetInt statement normally comes before the Return statement.
 

inglewoodpete

Senior Member
Both Return and SetInt are required

Still a little strange that the interrupt isn't reset as the SetInt statement normally comes before the Return statement.
The SetInt command will not take effect until the Return (from interrupt) statement is executed. Ie you need both Return and SetInt, in either order, to reenable interrupts. Have another close read of the SetInt command description (Manual 2)
 
Top