dear
my customer motor running speed range 1880RPM; It is planned that the PWM carrier within 1000 RPM is 10K, and that above 1000 RPM is changed to 8K;
At present, the INITIAL configuration of PWM carrier is executed once, and the motor runs normally; When the motor runs to 1000 RPM or more, the initial configuration function of PWM carrier is called again (to modify the carrier frequency), it cannot be achieved;
What needs to be solved is that when the motor speed reaches 1000 RPM, apart from modifying the carrier frequency by configuring the ePWM cycle register (PWM ->TBPRD = period), are there any other associated register configurations or logic that need to be modified? Or there are other ways;
The following is the ePWM initial configuration function, refer to InstaSPIN. and advise?thanks in advance
void HAL_setupPwms(HAL_Handle handle,
const uint_least16_t systemFreq_MHz,
const float_t pwmPeriod_usec,
const uint_least16_t numPwmTicksPerIsrTick)
{
HAL_Obj *obj = (HAL_Obj *)handle;
uint16_t halfPeriod_cycles = (uint16_t)((float_t)systemFreq_MHz*pwmPeriod_usec) >> 1;
uint_least8_t cnt;
// CLK_disableTbClockSync(obj->clkHandle);
// turns off the outputs of the EPWM peripherals which will put the power switches
// into a high impedance state.
PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_1]);
PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_2]);
PWM_setOneShotTrip(obj->pwmHandle[PWM_Number_3]);
for(cnt=0;cnt<3;cnt++)
{
// setup the Time-Base Control Register (TBCTL)
PWM_setCounterMode(obj->pwmHandle[cnt],PWM_CounterMode_UpDown);
PWM_disableCounterLoad(obj->pwmHandle[cnt]);
PWM_setPeriodLoad(obj->pwmHandle[cnt],PWM_PeriodLoad_Immediate);
PWM_setSyncMode(obj->pwmHandle[cnt],PWM_SyncMode_EPWMxSYNC);
PWM_setHighSpeedClkDiv(obj->pwmHandle[cnt],PWM_HspClkDiv_by_1);
PWM_setClkDiv(obj->pwmHandle[cnt],PWM_ClkDiv_by_1);
PWM_setPhaseDir(obj->pwmHandle[cnt],PWM_PhaseDir_CountUp);
PWM_setRunMode(obj->pwmHandle[cnt],PWM_RunMode_FreeRun);
// setup the Timer-Based Phase Register (TBPHS)
PWM_setPhase(obj->pwmHandle[cnt],0);
// setup the Time-Base Counter Register (TBCTR)
PWM_setCount(obj->pwmHandle[cnt],0);
// setup the Time-Base Period Register (TBPRD)
// set to zero initially
PWM_setPeriod(obj->pwmHandle[cnt],0);
// setup the Counter-Compare Control Register (CMPCTL)
PWM_setLoadMode_CmpA(obj->pwmHandle[cnt],PWM_LoadMode_Zero);
PWM_setLoadMode_CmpB(obj->pwmHandle[cnt],PWM_LoadMode_Zero);
PWM_setShadowMode_CmpA(obj->pwmHandle[cnt],PWM_ShadowMode_Shadow);
PWM_setShadowMode_CmpB(obj->pwmHandle[cnt],PWM_ShadowMode_Immediate);
// setup the Action-Qualifier Output A Register (AQCTLA)
PWM_setActionQual_CntUp_CmpA_PwmA(obj->pwmHandle[cnt],PWM_ActionQual_Set);
PWM_setActionQual_CntDown_CmpA_PwmA(obj->pwmHandle[cnt],PWM_ActionQual_Clear);
// setup the Dead-Band Generator Control Register (DBCTL)
PWM_setDeadBandOutputMode(obj->pwmHandle[cnt],PWM_DeadBandOutputMode_EPWMxA_Rising_EPWMxB_Falling);
PWM_setDeadBandPolarity(obj->pwmHandle[cnt],PWM_DeadBandPolarity_EPWMxB_Inverted);
// setup the Dead-Band Rising Edge Delay Register (DBRED)
PWM_setDeadBandRisingEdgeDelay(obj->pwmHandle[cnt],HAL_PWM_DBRED_CNT);
// setup the Dead-Band Falling Edge Delay Register (DBFED)
PWM_setDeadBandFallingEdgeDelay(obj->pwmHandle[cnt],HAL_PWM_DBFED_CNT);
// setup the PWM-Chopper Control Register (PCCTL)
PWM_disableChopping(obj->pwmHandle[cnt]);
// setup the Trip Zone Select Register (TZSEL)
PWM_disableTripZones(obj->pwmHandle[cnt]);
}
// setup the Event Trigger Selection Register (ETSEL)
PWM_disableInt(obj->pwmHandle[PWM_Number_1]);
PWM_setSocAPulseSrc(obj->pwmHandle[PWM_Number_1],PWM_SocPulseSrc_CounterEqualZero);
PWM_enableSocAPulse(obj->pwmHandle[PWM_Number_1]);
// setup the Event Trigger Prescale Register (ETPS)
if(numPwmTicksPerIsrTick == 3)
{
PWM_setIntPeriod(obj->pwmHandle[PWM_Number_1],PWM_IntPeriod_ThirdEvent);
PWM_setSocAPeriod(obj->pwmHandle[PWM_Number_1],PWM_SocPeriod_ThirdEvent);
}
else if(numPwmTicksPerIsrTick == 2)
{
PWM_setIntPeriod(obj->pwmHandle[PWM_Number_1],PWM_IntPeriod_SecondEvent);
PWM_setSocAPeriod(obj->pwmHandle[PWM_Number_1],PWM_SocPeriod_SecondEvent);
}
else
{
PWM_setIntPeriod(obj->pwmHandle[PWM_Number_1],PWM_IntPeriod_FirstEvent);
PWM_setSocAPeriod(obj->pwmHandle[PWM_Number_1],PWM_SocPeriod_FirstEvent);
}
// setup the Event Trigger Clear Register (ETCLR)
PWM_clearIntFlag(obj->pwmHandle[PWM_Number_1]);
PWM_clearSocAFlag(obj->pwmHandle[PWM_Number_1]);
// first step to synchronize the pwms
CLK_disableTbClockSync(obj->clkHandle);//2021.7.8
// since the PWM is configured as an up/down counter, the period register is set to one-half
// of the desired PWM period
PWM_setPeriod(obj->pwmHandle[PWM_Number_1],halfPeriod_cycles);
PWM_setPeriod(obj->pwmHandle[PWM_Number_2],halfPeriod_cycles);
PWM_setPeriod(obj->pwmHandle[PWM_Number_3],halfPeriod_cycles);
// last step to synchronize the pwms
CLK_enableTbClockSync(obj->clkHandle);
return;
} // end of HAL_setupPwms() function