interrupts in simulation mode don't seem to be working

#1
should an interrupt run in simulator mode as it should normaly. I mean my interrupt does not seem to do anything in simulator mode. Does this mean i did something wrong? Should i be able to see it work step by step?
 

Flenser

Senior Member
#2
rmitch,

Interrupts do work in simulation, I've recently used them, but your program will run much slower in simulation than on the chip.
To see an interrupt do something in simulation you will need to change your code to make the interrupt run more often.

On the 20X2 I set the simulation delay to 30ms and changed my code like this so that I could see the interrupt work in simulation:
Code:
; Set timer0 so that it occurs frequently during simulation
SETTIMER t1s_4
timer=65534
If you post your code then the forum can also investigate how you have setup your interrupt.
 
Last edited:
#3
im going to try to use the interrupt command to monitor 3 or four buttons. I have my program already written, I just want to play with the interrupt command to simplify it if i can. Im going to try a simple code to test the interrupt command to make sure i am doing it correctly this evening when i get home. I will respond after my experiment.
 

hippy

Technical Support
Staff member
#4
If you cannot get things to work it might be worth posting your code for others to take a look at.

Here's an example which simulates a 20X2 with interrupts when any of the C.x left-side pins are set -
Code:
#Picaxe 20X2
#Terminal 9600

Gosub Interrupt_Enable
Do
  Pause 10
Loop

Interrupt:
  SerTxd( "Interrupt = ", #pinsC, CR, LF )
  Do : Loop until pinsC = %00000000

Interrupt_Enable:
  SetInt Or %11111111, %11111111, C
  Return
 
#5
It appears that i had done something wrong, i did get it to work last night. I think the problem was i was missing a digit in the setinit input, mask line. Im not sure if the interrupt command will work well in my situation in monitoring 4 buttons that control different functions. it Looks like my code will work better the way its written in real time than in simulator mode. If not, i now have other options.
 

hippy

Technical Support
Staff member
#6
I think the problem was i was missing a digit in the setinit input, mask line
That's not an uncommon problem. It can be easy to lose a digit here or there, and it's not always easy to spot.

One trick is to define the input pins and the levels expected using SYMBOL, and then use those in the code, for example -
Code:
;                      76543210
Symbol SETINT_MASK  = %10101010
Symbol SETINT_MATCH = %10101010
One can then modify the code in Post #4 with that to only interrupt when an odd numbered C pin is activated -
Code:
#Picaxe 20X2
#Terminal 9600

;                      76543210
Symbol SETINT_MASK  = %10101010
Symbol SETINT_MATCH = %10101010

Gosub Interrupt_Enable
Do
  Pause 10
Loop

Interrupt:
  SerTxd( "Interrupt = ", #pinsC, CR, LF )
  Do 
    b0 = pinsC & SETINT_MASK
  Loop until b0 = 0

Interrupt_Enable:
  SetInt Or SETINT_MATCH, SETINT_MASK, C
  Return
 
Top