i write a code of bldc motor using (TMS320F28027) with BOOStXL-DRV8301 REVB
the pwm setting function was written as following
void HAL_setupPwms(HAL_Handle handle,uint16_t halfPeriod_cycles)
{
HAL_Obj *obj = (HAL_Obj *)handle;
uint_least8_t cnt;
// first step to synchronize the pwms
CLK_disableTbClockSync(obj->clkHandle);
//Enable pwm1 module clock
CLK_enablePwmClock(obj->clkHandle, PWM_Number_1);
CLK_enablePwmClock(obj->clkHandle, PWM_Number_2);
CLK_enablePwmClock(obj->clkHandle, PWM_Number_3);
for(cnt=0;cnt<3;cnt++)
{
// setup the Time-Base Period Register (TBPRD)
// set to zero initially
PWM_setPeriod(obj->pwmHandle[cnt],halfPeriod_cycles);
// 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);
//set compare values
PWM_setCmpA(obj->pwmHandle[cnt], HAL_EPWM1_MIN_CMPA);
PWM_setCmpB(obj->pwmHandle[cnt], HAL_EPWM1_MIN_CMPA);
// 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 Counter-Compare Control Register (CMPCTL)
// Setup shadowing
PWM_setShadowMode_CmpA(obj->pwmHandle[cnt],PWM_ShadowMode_Shadow);
PWM_setShadowMode_CmpB(obj->pwmHandle[cnt],PWM_ShadowMode_Shadow);
PWM_setLoadMode_CmpA(obj->pwmHandle[cnt],PWM_LoadMode_Zero);
PWM_setLoadMode_CmpB(obj->pwmHandle[cnt],PWM_LoadMode_Zero);
// 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);
PWM_setActionQual_CntUp_CmpB_PwmB(obj->pwmHandle[cnt],PWM_ActionQual_Set);
PWM_setActionQual_CntDown_CmpB_PwmB(obj->pwmHandle[cnt],PWM_ActionQual_Clear);
// setup the Dead-Band Generator Control Register (DBCTL)
PWM_setDeadBandOutputMode(obj->pwmHandle[cnt],PWM_DeadBandOutputMode_Bypass);
PWM_setDeadBandPolarity(obj->pwmHandle[cnt], PWM_DeadBandPolarity_EPWMxB_Inverted);
// setup the Dead-Band Rising Edge Delay Register (DBRED)
PWM_setDeadBandRisingEdgeDelay(obj->pwmHandle[cnt],1);
// setup the Dead-Band Falling Edge Delay Register (DBFED)
PWM_setDeadBandFallingEdgeDelay(obj->pwmHandle[cnt],1);
// setup the PWM-Chopper Control Register (PCCTL)
PWM_disableChopping(obj->pwmHandle[cnt]);
// setup the Trip Zone Select Register (TZSEL)
PWM_disableTripZones(obj->pwmHandle[cnt]);
}
// last step to synchronize the pwms
CLK_enableTbClockSync(obj->clkHandle);
PWM_setCmpA(obj->pwmHandle[0],0);
PWM_setCmpB(obj->pwmHandle[0],0);
PWM_setCmpA(obj->pwmHandle[1],0);
PWM_setCmpB(obj->pwmHandle[1],0);
PWM_setCmpA(obj->pwmHandle[2],0);
PWM_setCmpB(obj->pwmHandle[2],0);
return;
} // end of HAL_setupPwms() function
and when i made the migration to TIVAC
i wrote the code as following
//! \brief Sets up the PWMs (Pulse Width Modulators)
//! \param[in] uint32_t base base is the base address value of required timer
//! \param[in] PwmFreq_MHz The Pwm frequency in MHZ
//! \param[in] desiredFreq_KHz The PWM desired frqquency in KHz
extern void HAL_Pwm_setup(uint32_t base,
const uint32_t PwmFreq_MHz,
const uint32_t desiredFreq_KHz)
{
uint32_t halfPeriod_cycles=((PwmFreq_MHz*1000)/desiredFreq_KHz)-1;
/*Make PB4,5,6,7, PE4,5 Pins as PWM*/
ROM_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
ROM_GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5);
ROM_GPIOPinConfigure(GPIO_PB6_M0PWM0);
ROM_GPIOPinConfigure(GPIO_PB7_M0PWM1);
ROM_GPIOPinConfigure(GPIO_PB4_M0PWM2);
ROM_GPIOPinConfigure(GPIO_PB5_M0PWM3);
ROM_GPIOPinConfigure(GPIO_PE4_M0PWM4);
ROM_GPIOPinConfigure(GPIO_PE5_M0PWM5);
/*Configure PWM
* 1)configure Gen 0,1,2
* 2) Sync Comparators, load regsiters , DB registers*/
ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_GEN_NO_SYNC | PWM_GEN_MODE_NO_SYNC | PWM_GEN_MODE_DB_NO_SYNC);
ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_GEN_NO_SYNC | PWM_GEN_MODE_NO_SYNC | PWM_GEN_MODE_DB_NO_SYNC);
ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_GEN_NO_SYNC | PWM_GEN_MODE_NO_SYNC | PWM_GEN_MODE_DB_NO_SYNC);
//Set the Period (expressed in clock ticks)
ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, halfPeriod_cycles);
ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, halfPeriod_cycles);
ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, halfPeriod_cycles);
//Set PWM duty
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, HAL_MIN_DUTY);
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, HAL_MIN_DUTY);
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, HAL_MIN_DUTY);
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, HAL_MIN_DUTY);
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_4, HAL_MIN_DUTY);
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5, HAL_MIN_DUTY);
/*Sysnc PWM time base clock */
ROM_PWMSyncTimeBase(PWM0_BASE , PWM_GEN_0_BIT | PWM_GEN_1_BIT | PWM_GEN_2_BIT);
/*Set up the dead band*/
ROM_PWMDeadBandEnable(base, PWM_GEN_0, 100 , 100);
ROM_PWMDeadBandEnable(base, PWM_GEN_1, 100 , 100);
ROM_PWMDeadBandEnable(base, PWM_GEN_2, 100 , 100);
// Turn on the Output pins
ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT , true);
// Enable the PWM generator
ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0);
ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_1);
ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_2);
return;
} // end of HAL_Pwm_setup() function
but i didnt get the same results , the motor torque was too weak compared when i had written the code on C2000.
I dont know where is the problem ?? its on the new software i wrote for TIVAC or in the connection between TIVAC board and BOOStXL-DRV8301 REVB (hence Tivac and BOOSTXL-DRV8301 are not compatible in pins so i had to use jumper to connect the pwm signals and ground and EN-Gate).
Thanks in Advance.