RCU Forums - View Single Post - New CDI - opensource project JMJ and Bigboat
Old 05-23-2010 | 08:40 PM
  #1271  
COM
Senior Member
 
Joined: Jun 2009
Posts: 396
Received 0 Likes on 0 Posts
From: Ga, GA
Default RE: New CDI - opensource project JMJ and Bigboat

Here is Nyemi's code with the test function. However there are some things that are different. The spark is generated at the leading edge of the magnet as opposed to the trailing edge. With portB.3 held high at startup test function is entered at 7500 rpm. IF portB.2 and 3 are then 300 rpm is obtained. Also PortB pullups are disabled. So a pull up resistor is needed at portB.1 for input.





void test() { //Generate test signal
while (1){
PORTB ^= 0x11; // sends a ground to the SCR gate
Delay_us(56); // send delay 56us scr
PORTB ^= 0x11; // ground off the SCR
if (PORTB & 0x04) delay_ms(200); // 300 rpm
else delay_ms(8); // 7500 rpm
} // end while (1) loop
} // end function test
void main()
{
const char tspark[]={ 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 25, 25, 26, 27, 29, 29, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 48, 50, 50, 51, 52, 53, 54, 53, 54, 55, 53, 54, 55, 52, 52, 53, 54, 52, 53, 54, 54, 55, 50, 51, 52, 52, 53, 48, 48, 49, 50, 50, 51, 45, 45, 46, 46, 47, 47, 48, 45, 45, 46, 46, 47, 48, 48, 49, 45, 45, 46, 46, 47, 47, 48, 48, 49, 49, 50, 46, 46, 47, 47, 48, 48, 48, 49, 49, 50, 50, 51, 51, 52, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 56, 57, 57, 58, 58, 59, 59, 60,
60, 60, 61, 61, 62, 62, 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};


char tspk,spark, t0;
CMCON = 0x07; // delete comparator module
TRISA = 0x00; // delete PORTA input
PORTA = 0x00; // PORTA low signal
TRISB = 0x0E; // set RB1 for input, all others for output
PORTB = 0x00; // set gate to SCR low i.e pin 6 of PIC, set gate to Strobelight ( TCI Output) high i.e pin 10 of PIC
OPTION_REG = 0x87; // set to 07=1:256 PRESCALER, 06=1:128 PRESCALER - tmr0 SOURCE INT CLOCK, Initial RPM:07=917rpm 06=1836rpm
TMR2 = 0;
PR2 = 255; // TMR2 Maximum Value 255x16uS=4,080mS
T2CON = 0x07; // start TMR2 counter 1:16 1 Table value:16uS (07=16uS)
INTCON = 0; // clear INTCON
if (PORTB.F3) test(); //If test jumper is on jump to test function

while(1){ //Loop forever
// Delay Algorithm~ 65uS (16x4=64uS) Taken into account in completing the table!!


while(1) // loop forever
{
while(PORTB ^ 0x00) // 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; // During the initial delay. 255x16uS=4,080mS
else tspk = tspark[t0]; // use table lookup for spark delay
T2CON = 0x07; // start TMR2 counter 1:16 1 Table value:16uS (07=16uS)
TMR2= 0; // clear spark timer
while(TMR2 < tspk); // loop until timeout to send spark
PORTB ^= 0x11; // take ground off the SCR
delay_us(40); // 500 us delay ( CDI= 500uS) (TCI=3300uS)
PORTB ^= 0x11; // sends a ground to the SCR gate
spark = 0;
INTCON = 0; // clear INTCON
} // end while spark loop
} // end loop forever
} // end of program
}

//nyemi