What I really need at the moment- is some simple foolproof method of determining whether the pointer returns from the interrupt handler code to the main loop. I am having problems when two similar modules (Input capture in this case) both have an identical pulse train (in time) on there input pin - the problem is the pointer never seems to return to the main code.
The means I have come up with to show whether the pointer has returned to the main loop is shown in the code below. Basically a loop that alternately enables and disables the two input capture modules (IC1 and IC3). The interrupt handler code for both of these turn on an LED whereas the main loop turns it off (if there is a return of the pointer from the IRH). IF my concept is valid the LED should blink as the pointer alternates between the IRH code and the main loop.
It does this (LED blinks), but only when one module is active. IF two are active (with pulse train on both input pin) then the LED simply stays on and never blinks.
So these leads me to conclude either that:
1. The pointer never returns to the main loop and therefore the LED never goes off
2. My approach is flawed and does not convey accurately whether the pointer has returned or not.
Naturally, if my "test" of the pointer returning to the main loop is flawed then all of my conclusions drawn from my experimenting are flawed.
my main loop
Code: Select all
var Empty_buf:dword;
...
...
EnableInterrupts() //Globally enable interrupts (EI)
repeat //Main Loop
delay_MS(100);
//Enable IC modules for interrupt and turn on LED in IRH code when interrupt occurs
IEC0.IC1IE := 1; //Enable Interrupt
IFS0.IC1IF := 0; //clear any spurious Flag
IEC0.IC3IE := 1; //Enable Interrupt
IFS0.IC3IF := 0; //clear any spurious Flag
Delay_MS(100); //Leave LED on for a time
//Now if pointer returns from IRH to Main loop then code disables further Interrupts until the LED turns off
//This turns off the LED, otherwise the pointer stays hung in the IRH with repeated interrupts
//NOTE: To check this code, IF interrupt flag is not cleared in IRH code, the pointer never returns
//to this main loop. Otherwise, if it does return, it causes LED to blink
IEC0.IC1IE := 0; //Disable Interrupt
Empty_buf := IC1buf; //clear cause of Persistent Interrupt
IFS0.IC1IF := 0; // clear flag
IEC0.IC3IE := 0; //Disable Interrupt
Empty_buf := IC3buf; //clear cause of Persistent Interrupt
IFS0.IC3IF := 0; // clear flag
PORTBclr := 0x00002000; // LED Should blink if pointer returns from IRH otherwise
//if it does not then the pointer never returns from IRH
//Repeat loop by Re-Enabling Interrupts
until 1 = 2;
I thought of simpler means such as simple loop with or without a delay, but decided that it might be alternating too fast for my eyeball to see it - or the delay may well get shortened by having an interrupt occur while it was delaying. So I ended up with the above.
Repeat
PORTB.RB13 := 0; //Turn OFF LED
Delay_MS(200);
until 1 = 2;
So if anyone has a fool proof (and simple) method for testing whether the pointer has return to the main loop, I would appreciate it greatly if you would share it.
Thanks