I am trying to give duty cycle ratio to the PWM channel 1. The duty cycle starts from 50% to 0 and it is supposed to stay off for half of fundamental cycle. In the last cycle before turning it off for half a cycle, the signal stays ON until the end of the period (Please see the picture). The blue signal is another PWM cycle with constant duty cycle. Here is my code:
rtb_Sum1 = 100U + rtDWork.UnitDelay1_DSTATE;
if (rtb_Sum1 > 4000U) {
rtb_Sum1 = 0U;
}
rtDWork.T1Ao = rtb_Sum1;
%keeps the signal off for higher duty cycles
if (rtb_Sum1 < 2000U) {
rtDWork.T1Ao = 4000U;
}
{
EvaRegs.CMPR1 = (uint16_T) (rtDWork.T1Ao / 2);
EvaRegs.CMPR2 = (uint16_T) (1638U / 2);
EvaRegs.CMPR3 = (uint16_T) (1638U / 2);
EvaRegs.ACTRA.all = 1638U;
}
rtDWork.UnitDelay1_DSTATE = rtb_Sum1;



