turn signal interrupts

adumas

Member
Ok... I've read through the documentation on interrupts but am still having difficulty working with them.

I need to sense 2 different push buttons and in turn activate different routines. My goal is for the push buttons to behave dependably - I don't want to have to repeatedly push the button to either turn it off or on. Right now, the program is not behaving very well. I often times need to repush the button and/or it won't exit certain routines.

I've commented out the interrupts.

I have push buttons configured with a 10k resistor to ground.

Can anyone help?
 

Attachments

gbrusseau

Senior Member
After pushing a button, try pausing for about 1 second to give you and the program time to release the button before testing the buttons state in the rightlight: and leftlight: sub-routines. If you test the button state to fast, the sub-routines will think you have pressed the button again, when in fact, you haven't released the button from pressing it yet.

Also, if you are going to use the interrupt, try SETINT %00000110, %00000110. This will enable interrupt on pins 1 and 2 and be testing for a high state on both pin 1 & 2.

In the INTERRUPT: subroutine, you should not have a goto statement (IF/THEN GOTO) that exits the INTERRUPT: routine without the RETURN being executed. Interrupts without a RETURN will overflow the stack.
 
Last edited:

adumas

Member
Ok.. I modified and streamlined the program. It works fine now - but I would like to learn how to use the interrupt command.

Taking the program I'm posting, could anyone look it over and let me know how to modify it.

Lastly, I'm working with the assumption that the interrupt command would be more efficient and more sensitive to changes in state - and therefore more reliable... Let me know if that is not correct.

The latest code is attached.
 

Attachments

gbrusseau

Senior Member
Streamlined the first posted code. Will look at the second posted code later or maybe you could streamline it after looking at the first one for clues.
 

Attachments

Last edited:

hippy

Ex-Staff (retired)
I think what you have in the final version is better than using interrupts; this is a Finite State Machine which is ideally suited to the task - Basically one moves from one state ( clode block ) when some input or value changes.

It is possible to improve the state machine so it's more responsive.

Interrupts have their uses but they are often over-rated. Unless you actually need to do something and then return to where you were to continue what was being done they end up setting some flag which has to be acted on upon return to achieve anything; you may as well just poll for the event. Trying to use interrupts to change state in any other manner usually ends up with interrupts locking themselves out and/or stack overflows.
 

adumas

Member
thanks for answering.. I did streamline the code... I also experimented with changing the main routine to using the button command:
button 1,1,8,2,b2,1,leftlight
button 2,1,8,2,b2,1,rightlight

but (after commenting out the sertxd)... I noticed that the 2nd version of code I posted is running the most consistently...

Go figure...

Normally I would say ok, let's move on, ... but I would like to still try out the interrupt command and how it would integrate into this code... So, if someone could help me out, I would appreciate it...
 

adumas

Member
oops... I just got hippy's response... Which is just what I needed... Thanks for the insight!!!! I just wanted to know that I was on the right track - using the right kind of logic / set of commands.
 

gbrusseau

Senior Member
I can't help but wonder that 5 ms or even 10 or 50 ms is not enough debounce time. I was thinking along the lines of closer to 200 ms debounce time.
 

adumas

Member
Thanks for answering... 5 seemed to be fine... If I increased it too much, then it didn't respond quick enough... But thanks for the help - it was really great for debugging different scenarious!!!!
 
Top