Hi,
A control algorithm I need to implement in F28335 requires from 16kHz PWM1 to be synchronized with the raising and falling edges of a control variable. In other words on the raising edge PWM1A has to be set high for 4 control cycles and for falling edge has to be los also for 4 cycles.
The code below is what I implemented. However PWM1 does not behavi as I expected. Could anyone tell me please, what is wrong with my code.
The interrupt routine is given bellow.
interrupt void pwm_isr() {
pwm_reg_temp = (float) (control_data.mod_index * (PWM_FREQ - 2)) + 1;
switch (control_data.mod_state) {
case NORMAL:
if (control_data.zcd ^ control_data.zcd_prev) {
if (control_data.zcd) {
EPwm1Regs.AQCSFRC.bit.CSFA = 0x10;
} else {
EPwm1Regs.AQCSFRC.bit.CSFA = 0x01;
}
EPwm1Regs.TBCTL.bit.SWFSYNC = 1;
control_data.mod_state = FORCED;
} else {
EPwm1Regs.CMPA.half.CMPA = (Uint16) pwm_reg_temp;
control_data.mod_state_cnt = RESET;
}
break;
case FORCED:
if (control_data.mod_state_cnt++ > 2) {
EPwm1Regs.AQCSFRC.bit.CSFA = 0x00;
EPwm1Regs.TBCTL.bit.SWFSYNC = 1;
EPwm1Regs.CMPA.half.CMPA = (Uint16) pwm_reg_temp;
control_data.mod_state = NORMAL;
}
break;
}
control_data.zcd_prev = control_data.zcd;
EPwm1Regs.ETCLR.bit.INT = 1; // Clear ePWM1 Interrupt flag
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
I tried this with CC_SHADOW and CC_IMMEDIATE, no difference did not work either way.
Thanks in advance,
Dejan