Does simulator support interrupts

lanternfish

Senior Member
Hello all.

Not sure what I have done wrong but I cannot simulate a 20X2 hardware interrupt in the programme editor simulator.

I have read the manual (many times), searched the forums, and still no success.

Code:
' Constants

SYMBOL GPSbaud = B4800_8

' Variables

SYMBOL Intflag = b0
InitialisePicaxe:

	SETFREQ m8					; Set to 8Mhz clock
	Intflag = 0
	'HSERSETUP GPSbaud,%01			; Set to GPS Baud Rate
	HINTSETUP %00000010			        ; Enable INT1 (bit5: 0 = rise 1 = fall trigger)
	SETINTFLAGS %00000010,%00000010

InitialiseGPS:

	LOW 2						; Set Rx/Tx Routing to GPS
	LOW 3						; Enable Rx/Tx Routing
	'HSEROUT 0,("$PRWIILOG,GGA,A,T,1,0")   ; GPS Tx GGA info only
	SERTXD ("$PRWIILOG,GGA,A,T,1,0")   	; GPS Tx GGA info only

	DO UNTIL Intflag>0:LOOP
Your help please.

Cheers
 

BeanieBots

Moderator
I can't answer if they are supported in the simulator, (never tried), but what are you expecting to happen that is not happening?
Your code does not have an interrupt routine!
 

hippy

Ex-Staff (retired)
Works for me ...

#Picaxe20X2

HIntSetup %00000010
SetIntFlags %00000010,%00000010
Do : Loop

Interrupt:
Do : Loop

Make sure you have Programming Editor 5.2.6 installed.

Hardware Interrupt 1 is pin B.0, you're looking for a falling edge, so run the program, click B.0 to turn it on, click again to turn it off and the interrupt is generated and caught.
 

lanternfish

Senior Member
Thanks guys.

While writing the reply, to include the Interrupt routine, I saw where my mistake was. And Hippy spotted my mistake.

The interrupt (on B.0) is meant to happen on the rising edge of a pulse, update a flag variable, then set interrupt to handle interrupt on negative edge. This pulse is approx. 24ms long and indicates that the GPS unit has output data (to scratchpad).

The picaxe then checks validity and then extracts and outputs the required GPS data to a cellphone. That is, as soon as I can get my head around the Nokia FBUS SMS and PDU coding.

Once again, thanks for your feedback.

Cheers
 

lanternfish

Senior Member
Back again.

Had no trouble getting Hippys code to work for -ve edge, however ...

I cannot get my code to work. It will not trigger on the +ve edge. Clearly I have misunderstood the manual on setting up external interrupts. Can you please check my code (below) and point me in the right direction.

Code:
#Picaxe20X2

HIntSetup %00000010
SetIntFlags %00100010,%00100010           ; Trigger on +ve edge

WaitForInterrupt:
Do : Inc b1 : Loop                                   ; Wait for interrupt

Goto WaitForInterrupt                              ; Prevent drop into Interrupt routine

Interrupt:
Inc b0                                                   ; Increment a flag
flag1 = 0                                                ; Is this necessary?
SetIntFlags %00000010,%00000010           ; Trigger on -ve edge
Return
Cheers
 
Last edited:

hippy

Ex-Staff (retired)
I think you meant ...

HIntSetup %00100010
SetIntFlags %00000010,%00000010

You set the positive edge detect in SETINTFLAGS, should be in HINTSETUP.

The following will handle bothe positive and negative edge interrupts ...

#Picaxe20X2

b0 = %00100010
HIntSetup b0
SetIntFlags %00000010,%00000010
Do : Loop

Interrupt:
hint1flag = 0
b0 = b0 ^ %00100000
HIntSetup b0
SetIntFlags %00000010,%00000010
Return
 

lanternfish

Senior Member
Thanks.

Painfully obvious when I re-read the manual in conjunction with MartinM57 post.
Have printed the posts out and stuck in my manual for future reference.

Thanks for your excellent help.
 
Top