Interrupts - various issues
Posted: Wed Oct 17, 2007 11:23 pm
I'm experimenting with 'RB Port Change' interrupts, using a Formula Flowcode Buggy. Some of the results are not quite what I expect!
Problem 1: I have very simple program, which enables the 'RB Port Change' interrupt, with a simple interrupt service macro. My main program then simply executes a holding loop, waiting for the interrupt to be triggered.
If I press one of the two switch buttons (connected to Port B, bits 4 and 5) the interrupt is triggered as expected. However... if I hold the button down, the interrupt is continually re-triggered for as long as I hold the button down. To verify this, I have added a simple counter variable which is incremented within the interrupt macro, and the LEDs are updated with the counter value. Once back in my main program loop, the LEDs are cleared. A small delay in the interrupt macro is sufficient to allow the LEDs to clearly show an increasing binary count as the interrupt macro is repeatedly called while the button is held down.
Now, I fully expect that some switch bounce will lead to several interrupt events when I first press the button. But, once the button is held down firmly, I expect the 'state' of the relevant Port B bit to be held constant and hence, without any changes, there should be no more interrupts (until I release the button, whereupon the state changes again).
I have noticed on the Buggy that Port B, bits 6 & 7 are effectively floating. Using a different diagnostic program, I observe erratic behaviour on these bits when Port B is continually read (as a byte) then written to the LEDs. This is particularly evident when either of the switch buttons are pressed. However, a workaround to prevent these bits possibly causing my repeated interrupts is to first set them as outputs, before my main program enters the holding loop. Either way, the problem with repeated interrupts persists!
Problem 2: I enable the interrupt and specify a macro to be called. Later in my program, I disable the interrupt, and then enable it again with a different macro. This works fine in the simulator, but fails on the Buggy, with the first macro being called, rather than the second one.
And one final question... how does Flowcode handle the disabling of interrupts within the interrupt macro? The PIC (I believe) generally disables an interrupt on entering the interrupt service routine to avoid recursive interrupts, (or stack overflow?). My question is simply, within Flowcode, is there ever a need to explicitly disable an interrupt within the interrupt service macro?
Any help, answers or suggestions welcome!
Problem 1: I have very simple program, which enables the 'RB Port Change' interrupt, with a simple interrupt service macro. My main program then simply executes a holding loop, waiting for the interrupt to be triggered.
If I press one of the two switch buttons (connected to Port B, bits 4 and 5) the interrupt is triggered as expected. However... if I hold the button down, the interrupt is continually re-triggered for as long as I hold the button down. To verify this, I have added a simple counter variable which is incremented within the interrupt macro, and the LEDs are updated with the counter value. Once back in my main program loop, the LEDs are cleared. A small delay in the interrupt macro is sufficient to allow the LEDs to clearly show an increasing binary count as the interrupt macro is repeatedly called while the button is held down.
Now, I fully expect that some switch bounce will lead to several interrupt events when I first press the button. But, once the button is held down firmly, I expect the 'state' of the relevant Port B bit to be held constant and hence, without any changes, there should be no more interrupts (until I release the button, whereupon the state changes again).
I have noticed on the Buggy that Port B, bits 6 & 7 are effectively floating. Using a different diagnostic program, I observe erratic behaviour on these bits when Port B is continually read (as a byte) then written to the LEDs. This is particularly evident when either of the switch buttons are pressed. However, a workaround to prevent these bits possibly causing my repeated interrupts is to first set them as outputs, before my main program enters the holding loop. Either way, the problem with repeated interrupts persists!
Problem 2: I enable the interrupt and specify a macro to be called. Later in my program, I disable the interrupt, and then enable it again with a different macro. This works fine in the simulator, but fails on the Buggy, with the first macro being called, rather than the second one.
And one final question... how does Flowcode handle the disabling of interrupts within the interrupt macro? The PIC (I believe) generally disables an interrupt on entering the interrupt service routine to avoid recursive interrupts, (or stack overflow?). My question is simply, within Flowcode, is there ever a need to explicitly disable an interrupt within the interrupt service macro?
Any help, answers or suggestions welcome!