SPRUJ26A September 2021 – April 2024
The HAL module configures the PWM channels. The base addresses of the PWM channels that are used for the motor controller PWM inputs are defined in the hal.h file, and the base addresses are assigned to the PWM handles in the hal.c file. The connection diagram for the PWM signals between the LAUNCHXL-F280025C and BOOSTXL-DRV8323RS is shown in Figure 4-2.
The code to configure the PWM signals is shown below, taken from the hal.h and hal.c files that are located in the solutions\universal_motorcontrol_lab\f28002x\drivers\include and \source folder. Motor driver board dependent and MCU dependent changes are highlighted in bold.
//! \ Motor 1
#define MTR1_PWM_U_BASE EPWM1_BASE
#define MTR1_PWM_V_BASE EPWM2_BASE
#define MTR1_PWM_W_BASE EPWM6_BASE
// GPIO0->EPWM1A->M1_UH*
GPIO_setPinConfig(GPIO_0_EPWM1_A);
GPIO_setDirectionMode(0, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(0, GPIO_PIN_TYPE_STD);
// GPIO1->EPWM1B->M1_UL*
GPIO_setPinConfig(GPIO_1_EPWM1_B);
GPIO_setDirectionMode(1, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(1, GPIO_PIN_TYPE_STD);
// GPIO2->EPWM2A->M1_VH*
GPIO_setPinConfig(GPIO_2_EPWM2_A);
GPIO_setDirectionMode(2, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(2, GPIO_PIN_TYPE_STD);
// GPIO3->EPWM2B->M1_VL*
GPIO_setPinConfig(GPIO_3_EPWM2_B);
GPIO_setDirectionMode(3, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(3, GPIO_PIN_TYPE_STD);
// GPIO4->EPWM3A->M1_WH*
GPIO_setPinConfig(GPIO_4_EPWM3_A);
GPIO_setDirectionMode(4, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(4, GPIO_PIN_TYPE_STD);
// GPIO15->EPWM3B->M1_WL*
GPIO_setPinConfig(GPIO_15_EPWM3_B);
GPIO_setDirectionMode(15, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(15, GPIO_PIN_TYPE_STD);
// initialize PWM handles for Motor 1
obj->pwmHandle[0] = MTR1_PWM_U_BASE; //!< the PWM handle
obj->pwmHandle[1] = MTR1_PWM_V_BASE; //!< the PWM handle
obj->pwmHandle[2] = MTR1_PWM_W_BASE; //!< the PWM handle
void HAL_setupPWMs(HAL_MTR_Handle handle)
{
HAL_MTR_Obj *obj = (HAL_MTR_Obj *)handle;
uint16_t cnt;
uint16_t pwmPeriodCycles = (uint16_t)(USER_M1_PWM_TBPRD_NUM);
uint16_t numPWMTicksPerISRTick = USER_M1_NUM_PWM_TICKS_PER_ISR_TICK;
... ...
for(cnt=0; cnt<3; cnt++)
{
// setup the Time-Base Control Register (TBCTL)
EPWM_setTimeBaseCounterMode(obj->pwmHandle[cnt], EPWM_COUNTER_MODE_UP_DOWN);
... ...
// setup the Action-Qualifier Output A Register (AQCTLA)
EPWM_setActionQualifierAction(obj->pwmHandle[cnt], EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
EPWM_setActionQualifierAction(obj->pwmHandle[cnt], EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
EPWM_setActionQualifierAction(obj->pwmHandle[cnt], EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
EPWM_setActionQualifierAction(obj->pwmHandle[cnt], EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
... ...
// setup the Dead-Band Generator Control Register (DBCTL)
EPWM_setDeadBandDelayMode(obj->pwmHandle[cnt], EPWM_DB_RED, true);
EPWM_setDeadBandDelayMode(obj->pwmHandle[cnt], EPWM_DB_FED, true);
// select EPWMA as the input to the dead band generator
EPWM_setRisingEdgeDeadBandDelayInput(obj->pwmHandle[cnt], EPWM_DB_INPUT_EPWMA);
// configure the right polarity for active high complementary config.
EPWM_setDeadBandDelayPolarity(obj->pwmHandle[cnt], EPWM_DB_RED, EPWM_DB_POLARITY_ACTIVE_HIGH);
EPWM_setDeadBandDelayPolarity(obj->pwmHandle[cnt], EPWM_DB_FED, EPWM_DB_POLARITY_ACTIVE_LOW);
// setup the Dead-Band Rising Edge Delay Register (DBRED)
EPWM_setRisingEdgeDelayCount(obj->pwmHandle[cnt], MTR1_PWM_DBRED_CNT);
// setup the Dead-Band Falling Edge Delay Register (DBFED)
EPWM_setFallingEdgeDelayCount(obj->pwmHandle[cnt], MTR1_PWM_DBFED_CNT);
... ...
}
... ...
// setup the Event Trigger Selection Register (ETSEL)
EPWM_setInterruptSource(obj->pwmHandle[0], EPWM_INT_TBCTR_ZERO);
EPWM_enableInterrupt(obj->pwmHandle[0]);
EPWM_setADCTriggerSource(obj->pwmHandle[0], EPWM_SOC_A, EPWM_SOC_TBCTR_D_CMPC);
EPWM_enableADCTrigger(obj->pwmHandle[0], EPWM_SOC_A);
... ...
return;
} // end of HAL_setupPWMs() function
// Three-shunt
#define MTR1_ADC_TRIGGER_SOC ADC_TRIGGER_EPWM1_SOCA // EPWM1_SOCA