Interrupt Problems

v8surf

New Member
Hi all.

Not sure if what I am trying to do is at all possible, but here goes.

I am wanting to control a spa heater & pump with a PICAXE 18X. There is a button on the spa that I am using as an interrupt (with SETINT) to change between auto,off & manual modes.

Code:
Interrupt:
   SOUND buzzer,(100,5,75,5,125,5)
   LOW buzzer
   IF b4 = 1 then let b4 = 2 		'increase spa mode
   ELSEIF b4 = 2 then let b4 = 3 
   ELSEIF b4 = 3 then let b4 = 4
   ELSEIF b4 = 4 then let b4 = 1 
   ENDIF
   IF b4 = 1 then goto autostart 	'auto startup routine
   IF b4 = 2 then goto notonstart 	'off startup routine
   IF b4 = 3 then goto manualstart 	'manual ON startup routine
   IF b4 = 4 then goto notonstart	'off startup routine
  SETINT %00000001,%00000001
RETURN
My problem is that I don't want the program to return to where it was interrupted as I now want it to be running a seperate subroutine (auto>off>manual>off>auto>off... etc. etc.), so the code never gets to the RETURN and therefore never resets the interrupt.

I am reasonably new to this and have tried a few different ways arround this but am stumpped now.
The first interrupt works as expected and turns everything into the OFF mode. But that is where it stays.

The program simulates exactly the way I want it to, but not in the real world sadly.


Hope you understand what I'm after, and I really hope there is a solution other than checking the interrupt input every few lines of code.



Cheers for the help,

V8surf
 

BeanieBots

Moderator
You need to build what's known as a "state machine".
In simple terms, you have a variable which holds the "state" of your program.

The main loop of your program checks the "state" each time it goes around and does whatever is required for that "state".
(see "BRANCH" or "SELECT CASE" for options depending on state)

Your interrupt routine could for example, increment the value of that "state" every time a button is pressed or maybe just toggle between two values.

This is a very common method used for building up large complex menu systems.
 

v8surf

New Member
Thanks for this quick reply. I hope to get a few hours this afternoon to look into your suggestions. Cheers
 

manie

Senior Member
Could you post an example of the code with interrupt and branch sequences please ? It could be of use to all of us.
Thanks
 

v8surf

New Member
I will post the code up here when I can get some time to clean it up a little and make it easier for others to understand. I'm still ironing out a couple of bugs at the moment and don't want to mislead anyone.

Hope to get it up by this weekend.
 

inglewoodpete

Senior Member
I wrote a state-driven engine for my PICAXE-based home theatre controller (erroneously called a "Tuner" in the technology market today). The hardware included a 9-button keypad (arranged as 3 rows x 3 columns) and a 2 x 16 LCD.

To elaborate a little on BeanieBots' description, the state-driven engine runs in a loop. The code in the loop constantly checks a number of variables, compares their values and implements any requirements on the outputs. The inputs could be from a keypad or IR remote. The input value is compared with the current state (Eg what menu or menu item is current) and action is taken to move to a new state, which may involve changing outputs or sending text to the LCD.

In my case, the keypad causes interrupts and the interrupt routine determines what key or combination of keys has been pressed. The result is placed in a variable and then the interrupt routine returns control to the state engine loop (that was interrupted). When the engine loop gets to its relevant piece of code, it checks the keyboard variable, sees the keypress data and then implements the request depending on its current 'state'.
 
Top