void OC_init() {
TRISAbits.TRISA10 = 0; // OC3 OUTPUT
Nop();
OC3R = 0x8FFF;
OC3RS = 0x08FC;
OC3CON2bits.SYNCSEL = 0;
OC3CON2bits.OCMPINV = 0;
OC3CON1bits.OCTSEL = 0; //T2 clock
OC3CON1bits.OCM = 0; // CONTINIOUS pwm mode = 5, 0=off
PWM_rate=0;
}
void PWM_charge(int rate){
OC3CON1bits.OCM = 0; // STOP pwm
LATAbits.LATA10=0; // mosfet driver
LCD_print(3,0," REG @ ");
switch(rate){
case 5:
OC3R = 0xFF00;
OC3CON1bits.OCM = 5;
LCD_print(3,7," 5% PWM ");
break;
case 25:
OC3R = 0xCFFF;
OC3CON1bits.OCM = 5;
LCD_print(3,7," 25% PWM ");
break;
case 50:
OC3R = 0x8FFF;
OC3CON1bits.OCM = 5;
LCD_print(3,7," 50% PWM ");
break;
case 75:
OC3R = 0x4FFF;
OC3CON1bits.OCM = 5;
LCD_print(3,7," 75% PWM ");
break;
}