Rob here is the modified code. RA4 and RA5 are output and RA2 is input. Whats too fast?
void main()
{
const char tspark[]={ 0, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 11, 11, 12, 13, 13, 14, 15, 15, 16, 16, 17, 18, 18, 19, 19, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 43, 44, 44, 45, 45, 46, 46, 46, 47, 47, 48, 48, 49, 49, 49, 50, 50, 50, 51, 51, 52, 52, 52, 53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 56, 56, 57, 57, 57, 58, 58, 58, 59, 59, 59, 60, 60, 60, 60, 61, 61, 61, 62, 62, 62, 62, 63, 63, 63, 63, 64,
64, 64, 65, 65, 63, 63, 64, 64, 64, 65, 65, 66, 66, 67, 67, 68, 68, 68, 69, 69, 70, 70, 71, 71, 71, 72, 72, 73, 73, 74, 74, 75, 75, 76, 76, 76, 77, 77, 78, 78, 79, 79, 80, 80, 80, 81, 81, 82, 82, 83, 83, 83, 84, 84, 85, 85, 86, 86, 87, 87, 87, 88, 88, 89, 89, 90, 90, 91, 91, 92, 92, 92, 93, 93, 94, 94, 95, 95, 96, 96, 96, 97, 97, 98, 98, 99, 99, 100, 100, 100, 101, 101, 102, 102, 103, 103, 104, 104, 104, 105, 105, 106, 106, 107, 107, 107, 108, 108, 109, 109, 110, 110, 111, 111, 112, 112, 112, 113, 113};
char tspk,spark, t0;
OSCCON = 0b01100111; // internal OSC set to 4MHZ
ANSEL = 0; // Disable Analog channels
CMCON0 = 0x07; // Disable Comparitors
TRISIO = 0x0C; // set GPIO1 for input, all others for output
GPIO = 0x00; // set output to SCR low
OPTION_REG = 0x07; // set to 07=256 RE - tmr0 SOURCE INT CLOCK, 06=1:128 PRESCALER
TMR2 = 0;
PR2 = 255;
T2CON = 0x07; // start TMR2 counter 1:16
INTCON = 0; // clear INTCON
// Following table is based on 360 degree timing arc & 40 deg starting arc (South pole of magnet triggers Hall switch)
// table based on a polynomial and limits the min delay to 15 TMR2 cycles
// the spark flag is a one shot to prevent continuous sparking on a Hall low signal
while(1) // loop forever
{
while( GPIO.F2 ^ 1) // wait for high pulse on Hall switch
{
spark = 1;
} // North pole of magnet has passed
while(spark)
{
t0 = TMR0;
TMR0 = 0; // start new rev count
if(INTCON&4) tspk=255; // <<<< ADD THIS LINE TO YOUR CODE!!! 917> RPM 255x16uS=4,080mS
else tspk = tspark[t0]; // use table lookup for spark delay
T2CON = 0x07; // start TMR2 counter 1:16
TMR2= 0; // clear spark timer
while(TMR2 < tspk); // loop until timeout to send spark
GPIO ^= 0x30; // take ground off the SCR Pin GPIO4 and 6
delay_us(50); // 23 us delay
GPIO ^= 0x30; // sends a ground to the SCR gate
spark = 0;
INTCON = 0; // clear INTCON
} // end while spark loop
} // end loop forever
} // end of program
////Notes
//
// ; At a engine speed of 1200 RPM;
// ;
// ; 1200 / 60 = 20 revs per second
// ; 1 / 20 = 50mS per rev
// ; 1 rev = 360 degrees
// ;
// ; 36 degrees at 1200 RPM = (36 / 360) X 50 = 5mS
// ;
// ; 100uS loop time
// ; 4MHz clock / 4 = 1MHz instruction cycle
// ; cycle time = 1/1MHz = 100uS
// ; 100uS/100uS = 100 cycles
// ; prescaler set to divide by 4
// ; preset TMR0 = 231, when = 0 = 100uS
// ; 231 to 255 = 25 x 4(prescaler) = 100
// -O-
// VDD o o RA GND
// SCR RA5 o o RA0
// Strobelight RA4 o o RA1
// MCLR RA3 o o RA2 Hall input
//