Part Number: TMS320F28379D
Tool/software: Code Composer Studio
Most of the time, when I press debug and watch the registers, I notice that even though my code may explicitly set the epwm period to be 5000 counts, the register will not update and just say 0. Or sometimes it'll be the phase that doesn't get set or both. Sometimes, the CMPA will also not set.
Is there something wrong with my InitEPwm code? I do call InitEPwm() and InitEPwmGpio() in the main function.
void InitEPwm2(void)
{
EALLOW;
// Setup TBCLK
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm2Regs.TBPRD = PWM5_PERIOD ; // Same period as PWM5
EPwm2Regs.TBCTL.bit.PHSEN = 1; // Enable phase loading
EPwm2Regs.TBPHS.bit.TBPHS = 500; // Phase
EPwm2Regs.TBCTR = 0x0000; // Clear counter
EPwm2Regs.TBCTL.bit.HSPCLKDIV = 1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = 0;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // SYNC output on CTR = 0
// Setup shadow register load on ZERO
EPwm2Regs.CMPCTL.bit.SHDWAMODE = 0;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = 0;
EPwm2Regs.CMPCTL.bit.LOADAMODE = 0;
EPwm2Regs.CMPCTL.bit.LOADBMODE = 0;
// Set Compare values
EPwm2Regs.CMPA.bit.CMPA = dutyCycle ; // Set compare A value
// Set actions
EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET; // Set PWM2A on Zero
EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR; // Clear PWM2A on event A, up count
EDIS;
}