PWM in Dspic

Thread Starter

firend

Joined Feb 18, 2012
44
Hello everyone!
I have a problem. I am using dspic 30f4011 to control motor. in the forward direction, I use PWM1H pin PWM mode, pin PWM1L=0. In the reserve direction, I use PWM1L in PWM mode, pin PWM1H=0. but pin PWM1H doesn't operation, only pin PWM1L operation. So motor only run counterclockwise. i use IC L298 to control. INT1 interrupt routine to change direction.
Thank everyone!

void PWM_Init(){
PTMR=0;
PTPER = MAX_PWM;
PWMCON1 = 0x0100; // disable PWMs mode ve sau chon PWM1H,PWM1L
OVDCON = 0x0200; // allow control using OVD chan PWM1H DUOC DIEU KHIEN
PDC1 = MAX_PWM; ;// duty cycle 50%
SEVTCMP = PTPER; // special trigger is 16 period values
PWMCON2 = 0x0F00; // 16 postscale values
PTCON = 0x8000;// BAT PWM
}
void __attribute__((__interrupt__,__auto_psv__)) _INT1Interrupt(void){
_INT1IF=0;
Flag.DIRECTION= !Flag.DIRECTION; // forward direction
if(Flag.DIRECTION) OVDCON=0x0200; // pwm1H
else OVDCON= 0x0100;
}
 
Top