RE: CDI gr8flyer55
The code you posted is simply turning on the output to the SCR. It is triggered by an interrupt caused by the falling edge on GP2.
The hall sensor is normally at 5v. When the magnet passes it causes GP2 to go to 0V (low). So you could trigger on the rising edge if you want the interrupt to trigger just after the magnet passes. If you trigger on the falling edge, as I do in the code posted, you will enter the interrupt service routine when the magnet first triggers the sensor to go low. Either way will work fine, I just figure that triggering when the sensor first hits gives you a little more time.
The code section you posted is only called after the falling edge of GP2 triggers an interrupt which sets a timer. The code is called when the timer compare matches.
I probably didn' t explain that to well. Here is what happens...
1. GP2 interrupt is called when the magnet first triggers the hall sensor (falling edge since the logic voltage is reversed).
2. GP2ISR reads the timer value, which equals the time since the last sensor trigger (1 revolution). The ISR then looks up a value in the ignition advance table based on the revolution time and loads it into the compare module of the timer.
3. After the time expires the timer compare module triggers an interrupt, when the values match (the set time is reached).
4. This interrupt service routine (the code you posted) turns on the GP1 pin, which tied to the SCR. It then waits the dwell time and turns the pin back off.
That is the basic flow of the code. It is entirely interrupt driven. The sensor interrupt triggers and the delay time is set, when the delay time expires it triggers an interrupt where the pin is activated. And so on.
-Jake<br type="_moz" />