I am fairly new to the pics and trying to balance between the cell voltages. I got a circuit to drive the mosfets when the balancing in need but i stuck with program. How can i enable and disable pwm signals independently?
void init_PWM(){//P1TCON = 0x0000;
_PTMOD =0x0;// PWM Time Base Mode Select bits PWM time base operates in a Free-Running mode
_PTCKPS =0x0;// PWM Time Base Input Clock Prescale Select bits PWM time base input clock period is TCY (1:1 prescale)
_PTOPS =0x00;// PWM Time Base Output Postscale Select bits. 1:1 postscale
_PTEN =1;// PWM Time Base Timer Enable bit. PWM time base is on
PTPER =499;// PWM Time Base Period Value bits / PTPER+1 fPWM=20kHz fCY=20 MHz/*~~~~~~~~~~~~~~~~~~~~~~~ PWM1 Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
_PEN1H =0x1;/* PWM1H is controlled by PWM module */
_PEN1L =0x1;/* PWM1L is controlled by PWM module */
_PEN2H =0x1;
_PEN2L =0x1;
_PEN3H =0x1;
_PEN3L =0x1;
_PMOD1 =0x0;/* Select Independent Output PWM mode */
_PMOD2 =0x0;
_PMOD3 =0x0;
PDC1 =500;/* Initial Duty cycle PDCx/2 */
PDC2 =500;
PDC3 =500;
PTCONbits.PTEN=1;/* Enable the PWM Module */}