This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
Hello,
I am trying to synchronize two EPWM with different frequencies. EPWM1 is used as mater to synchronize EPWM2. EPWM1 is running at 1.250 kHz and EPWM2 is running at 2.500 kHz. When I view these signals on oscilloscope, the EPWM2 signal is forced at 1.2500 kHz with duty cycle equal to EPWM1 and a random phase shift. If I disable the EPWM1 module, EPWM2 is running at the correct frequency i.e. 2.500 kHz. In addition to this, when both modules are configured at same frequencies, then I am observing correct frequency with desired phase shift. Please find below the code snippet:
void InitEpwm1()
{
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV2; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV2;
//Calculate TBPRD Value assuming EPWMCLKDIV default value equal to 2
TBPRD = 100000000/(12500* 2 *2);
// Setup TBCLK
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm1Regs.TBPRD = TBPRD;
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Enable/Disable phase loading
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Set actions
EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET; // Clear PWM2A on Down compare
EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR; // set PWM2A on Up compare
EPwm1Regs.AQCTLB.bit.ZRO = AQ_CLEAR; // Set PWM2B on Down compare
EPwm1Regs.AQCTLB.bit.CBU = AQ_SET; // Clear PWM2B on Up compare
EPwm1Regs.TBPHS.bit.TBPHS = 0; // Phase
}
void InitEpwm2()
{
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV2; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV2;
//Calculate TBPRD Value assuming EPWMCLKDIV default value equal to 2
TBPRD = 100000000/(2500* 2 *2);
// Setup TBCLK
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm2Regs.TBPRD = TBPRD;
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Enable/Disable phase loading
// Set actions
EPwm2Regs.AQCTLA.bit.ZRO = AQ_SET; // Clear PWM2A on Down compare
EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR; // set PWM2A on Up compare
EPwm2Regs.AQCTLB.bit.ZRO = AQ_CLEAR; // Set PWM2B on Down compare
EPwm2Regs.AQCTLB.bit.CBU = AQ_SET; // Clear PWM2B on Up compare
EPwm2Regs.TBCTR = 0x0000; // Clear counter
EPwm2Regs.TBPHS.bit.TBPHS = 0; // Phase
}
Hello,
I checked my code and it seems that there must have been a typo while copying the code (sorry about that). PWM1 is in fact TBPRD = 100000000/(1250* 2 *2); in my code. When I went into the online debugger, I observed that the value of TBPHS was getting more than the value of TBPRD of EPWM2. After fixing this, I am getting the correct frequency and phase shift.
Thanks for the help!
Prateek Jain