PDA

View Full Version : Change From C to PBP



savnik
- 13th February 2007, 06:10
I have the code below in C
Anyone know to change from c to PBP


void test() { //Generate test signal
while (1){
PORTB &= 0xee; // sends a ground to the SCR gate
delay_us(56); // 56 us delay
PORTB |= 0x11; // ground off the SCR
if (PORTB & 0x04) delay_ms(200); //300 rpm
else delay_ms(8); //7500 RPM
}
}

void main() {
const char tspark[]={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 5, 5, 7, 7, 9, 9, 10, 12, 12, 12, 14, 14, 14, 17, 17, 17, 20, 20, 20, 22, 23, 25, 25, 28, 28, 31, 31, 34, 34, 37, 38, 40, 41, 44, 44, 44, 48, 48, 48, 51, 52, 52, 53, 56, 56, 57, 57, 61, 61, 62, 62, 63, 63, 63,
64, 64, 68, 68, 69, 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 74, 75, 75, 79, 80, 80, 81, 81, 82, 82, 83, 83, 84, 84, 85, 85, 86, 90, 91, 91, 92, 92, 93, 93, 94, 94, 95, 96, 96, 97, 97, 98, 98, 99, 99, 100, 100, 101, 106, 106, 107, 107, 108, 108, 109, 110, 110, 111, 111, 112, 112, 113, 113, 114, 115, 115, 116, 116, 117, 117, 118, 118, 119, 120, 120, 121, 121, 122, 122, 123, 123, 124, 125, 125, 126, 126, 127, 127, 128, 128, 129, 130, 130, 131, 131, 132, 132, 133, 133, 134, 134, 135, 136, 136, 137, 137, 138, 138, 139, 140, 140, 141, 141, 142};
short int spark=0;
unsigned int tspk, t0,t1,low;
unsigned int ofc; //Holds number of overflows

const unsigned int LowDelay=25; //Delay <1832 RPM, in degrees

const unsigned int ld=360/LowDelay; //Dont change this
TRISB = 0x0E; // set RB1,2,3 for input, all others for output RB0=SCR RB4=Strobe
PORTB = 0x11; // set gate to SCR high i.e pin 6 of PIC +strobe
OPTION_REG = 0x06; // tmr0 SOURCE INT CLOCK, 1:128 PRESCALER
INTCON = 0x00; //Disable interrupts +Resets interrupt flags
TMR2 = 0; //Reset timer2
TMR0 = 0; //Reser timer0
PR2 = 255; //This is how far timer2 counts before overflow
T2CON = 0x07; // start TMR2 counter 1:16

if (PORTB.F3) test(); //If test jumper is on jump to test function

while(1){ //Loop forever
ofc=0; //Reset overflow counter
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
}
spark = 1;
} //North pole of magnet has passed
if(spark){
t0 = TMR0;
TMR0 = 0; //Start new rev count
if(ofc > 0) { //Overflow timer0, we have < 1832 RPM
if ( ofc >= 36) ofc=36; //Min RPM 50 to avoid big calculations
low=ofc*ld; //Simplified calculation, gives about 25 degrees
delay_cyc (low); //extra delay based on overflow counter
delay_cyc (low);
delay_cyc (low);
delay_cyc (low);
delay_cyc (low); //Repeat 16 times - prescaler
delay_cyc (low);
delay_cyc (low);
delay_cyc (low);
delay_cyc (low);
delay_cyc (low);
delay_cyc (low);
delay_cyc (low);
delay_cyc (low);
delay_cyc (low);
delay_cyc (low);
delay_cyc (low);
} //max255 -> 2550 cycles
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
PORTB &= 0xee; //sends a ground to the SCR gate
delay_us(56); //56 us delay
PORTB |= 0x11; //ground off the SCR
spark = 0;
} //if(spark)
} //while(1)
} //main

Jerson
- 15th February 2007, 03:53
Yes. For Starters



void test() { //Generate test signal
while (1){
PORTB &= 0xee; // sends a ground to the SCR gate
delay_us(56); // 56 us delay
PORTB |= 0x11; // ground off the SCR
if (PORTB & 0x04) delay_ms(200); //300 rpm
else delay_ms(8); //7500 RPM
}
}

converts to this

Test:
while 1
Portb = PortB & $ee
pauseus 56
Portb = PortB | $11
if Portb & 4 then
pause 200
else
pause 8
endif
wend


Jerson