Here is an example of code I wrote and tested that gives good resolution and very low rpm cotrol.
The expression in
bold text makes it possible to read an endless array with delay values. Code delay with this solution is 80us.
The limitation is the amount of memory. I'm running timer0 at 1:64frequency, and when I generated values down to 1000rpm, the memory wasfull.
However, on low RPM engines, there is no need to run timer0 faster than1:128, so this could actually give a good result for all engine typeswhen it comes to ignition accuracy.
The best thing would be if it was possible to rescale the rpm positionson low rpm. Now there are almost infinite number of values for low rpm.The resolution is actually rediculous on low rpm's..
Creating the enormous amount of values in Excel also demands some reworking of the sheet..
I also tried a multiplication factor on the number of tspark[255] times a constant from owerflows without enlarging the array, but I could not get it to work..
Well, just food for thought
while(1){ //Loop forever
ofc=0; // Reset overflow teller
INTCON = 0x00; // Disable interrupts + Resets interrupt flags
while(PORTB & 0x02){ //Wait for low pulse on Hall switch
if (INTCON&4) { // Overflow
ofc++; //Increase overflow counter
INTCON = 0x00; // Resets interrupt flags
} // End IF
spark = 1;
} //North pole of magnet has passed
if(spark){
t0 = TMR0;
TMR0 = 0; //Start new rev count
if(ofc > 0) t0=t0+(ofc*255); //
tspk = tspark[t0]; //use table lookup for spark delay
T1CON = 0x05; // start TMR1 counter 1:1 using internal clock 1MHz
TMR1H = 0; // Reset timer1 high
TMR1L = 0; // Reset timer1 high
do //start of timing loop
{Hi(t1)=TMR1H; // read timer1 Low bits and add to timer variable
Lo(t1)=TMR1L; } // read timer1 High bits and add to timer variable
while(t1 < tspk); // loop until timeout to send spark
PORTB &= 0xee; //sends a ground to the SCR gate
Delay_us(1650); // Calculated delay
PORTB |= 0x11; //ground off the SCR
spark = 0;
} // end if(spark)
} // end while(1)