Hi everyone !
I have a problem to configure my phase shift between 3 ePWM to drive 3 boost power stage.
I want 120° phase shift per EPWM (phase is an input user). I configure EPWM1 as master and EPWM2 and EPWM3 as slaves. But on my oscilloscope I see 60° per phase not 120°. Could you explain me please ? Why it doesn't work correctly ?
Thanks.
void epwm_init(uint32_t base)
{
float PWM_TBPRD_1;
float PWM_TBPRD_2;
float PWM_TBPRD_3;
float PWM_CMPA_1;
float PWM_CMPA_2;
float PWM_CMPA_3;
EPWM_ClockDivider PWM_PARAM_PRESCALER;
EPWM_HSClockDivider PWM_PARAM_HIGHSPEEDPRESCALER;
float TBCLK;
if(base == myEPWM1_BASE)
{
get_pwm_clock_from_freq(base , &PWM_TBPRD_1 , &PWM_TBPRD_2 , &PWM_TBPRD_3 , &PWM_CMPA_1 , &PWM_CMPA_2 , &PWM_CMPA_3 , &PWM_PARAM_PRESCALER , &PWM_PARAM_HIGHSPEEDPRESCALER, &TBCLK);
// Parameters
EPWM_setTimeBasePeriod(base, (uint16_t)PWM_TBPRD_1);
EPWM_setCounterCompareValue(base, EPWM_COUNTER_COMPARE_B, (uint16_t)PWM_CMPA_1);
EPWM_setPhaseShift(base, 0U);
EPWM_disablePhaseShiftLoad(base);
EPWM_setTimeBaseCounter(base, 0U);
EPWM_enableSyncOutPulseSource(myEPWM1_BASE, EPWM_SYNC_OUT_PULSE_ON_CNTR_ZERO);
}
else if (base == myEPWM2_BASE)
{
get_pwm_clock_from_freq(base , &PWM_TBPRD_1 , &PWM_TBPRD_2 , &PWM_TBPRD_3 , &PWM_CMPA_1 , &PWM_CMPA_2 , &PWM_CMPA_3 , &PWM_PARAM_PRESCALER , &PWM_PARAM_HIGHSPEEDPRESCALER, &TBCLK);
// Parameters
EPWM_setTimeBasePeriod(base, (uint16_t)PWM_TBPRD_2);
EPWM_setCounterCompareValue(base, EPWM_COUNTER_COMPARE_A, (uint16_t)PWM_CMPA_2);
EPWM_setPhaseShift(base, 0U);
EPWM_disablePhaseShiftLoad(base);
EPWM_setTimeBaseCounter(base, 0U);
EPWM_setSyncInPulseSource(base, EPWM_SYNC_IN_PULSE_SRC_SYNCOUT_EPWM1);
set_phase(base, PHI);
}
else if(base == myEPWM3_BASE)
{
get_pwm_clock_from_freq(base , &PWM_TBPRD_1 , &PWM_TBPRD_2 , &PWM_TBPRD_3 , &PWM_CMPA_1 , &PWM_CMPA_2 , &PWM_CMPA_3 , &PWM_PARAM_PRESCALER , &PWM_PARAM_HIGHSPEEDPRESCALER, &TBCLK);
// Parameters
EPWM_setTimeBasePeriod(base, (uint16_t)PWM_TBPRD_3);
EPWM_setCounterCompareValue(base, EPWM_COUNTER_COMPARE_A, (uint16_t)PWM_CMPA_3);
EPWM_setPhaseShift(base, 0U);
EPWM_disablePhaseShiftLoad(base);
EPWM_setTimeBaseCounter(base, 0U);
EPWM_setSyncInPulseSource(base, EPWM_SYNC_IN_PULSE_SRC_SYNCOUT_EPWM1);
//EPWM_enableSyncOutPulseSource(myEPWM1_BASE, EPWM_SYNC_OUT_PULSE_ON_CNTR_ZERO);
set_phase(base, PHI);
}
//EPWM_setTimeBaseCounter(base, 0U);
EPWM_setTimeBaseCounterMode(base, EPWM_COUNTER_MODE_UP_DOWN);
EPWM_setClockPrescaler(base, PWM_PARAM_PRESCALER, PWM_PARAM_HIGHSPEEDPRESCALER);
// Set up shadowing
EPWM_setCounterCompareShadowLoadMode(base, EPWM_COUNTER_COMPARE_A, EPWM_COMP_LOAD_ON_CNTR_ZERO);
// Set actions
EPWM_setActionQualifierAction(base, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
EPWM_setActionQualifierAction(base, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
EPWM_setActionQualifierAction(base, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
EPWM_setActionQualifierAction(base, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
// Trip zone
// Configure ePWM1x to output low on TZx TRIP
EPWM_setTripZoneAction(base, EPWM_TZ_ACTION_EVENT_TZA, EPWM_TZ_ACTION_LOW);
EPWM_setTripZoneAction(base, EPWM_TZ_ACTION_EVENT_TZB, EPWM_TZ_ACTION_LOW);
// Trigger event when DCBH is high
EPWM_setTripZoneDigitalCompareEventCondition(base, EPWM_TZ_DC_OUTPUT_B1, EPWM_TZ_EVENT_DCXH_HIGH);
// Configure DCBH to use TRIP4 as an input
EPWM_enableDigitalCompareTripCombinationInput(base, EPWM_DC_COMBINATIONAL_TRIPIN4, EPWM_DC_TYPE_DCBH);
// Enable DCB as OST
EPWM_enableTripZoneSignals(base, EPWM_TZ_SIGNAL_DCBEVT1);
// Configure the DCB path to be unfiltered and asynchronous
EPWM_setDigitalCompareEventSource(base, EPWM_DC_MODULE_B, EPWM_DC_EVENT_1, EPWM_DC_EVENT_SOURCE_ORIG_SIGNAL);
// Clear trip flags
EPWM_clearTripZoneFlag(base, EPWM_TZ_INTERRUPT | EPWM_TZ_FLAG_OST);
// Calculate delays
get_delays_FED_RED(myEPWM1_BASE, &TBCLK);
get_delays_FED_RED(myEPWM2_BASE, &TBCLK);
get_delays_FED_RED(myEPWM3_BASE, &TBCLK);
}void set_phase(uint32_t base, uint16_t phi)
{
uint16_t phase;
if(base == myEPWM2_BASE)
{
phase = ((float)phi * HWREGH(base + EPWM_O_TBPRD) / 360);
}
if(base == myEPWM3_BASE)
{
phase = ((float)phi * HWREGH(base + EPWM_O_TBPRD) * 2 / 360);
}
//EPWM_selectPeriodLoadEvent(base, EPWM_SHADOW_LOAD_MODE_SYNC);
EPWM_enableSyncOutPulseSource(base, EPWM_SYNC_OUT_PULSE_ON_SOFTWARE);
EPWM_forceSyncPulse(base);
EPWM_setPhaseShift(base, phase);
EPWM_setTimeBaseCounter(base, phase);
EPWM_enablePhaseShiftLoad(base);
}
Damien