TIDUBE5A January 2022 – October 2022
The application parameters to control the motors and PFC are written as #define configuring the PWM, CMPSS, and ADC modules base address in hal.h according to the hardware. The PWM, CMPSS, ADC of compressor motor defines are shown in the following codes.
Configure PWM and CMPSS base address for compressor motor drive
// EPWM
#define MTR1_PWM_U_BASE EPWM3_BASE
#define MTR1_PWM_V_BASE EPWM5_BASE
#define MTR1_PWM_W_BASE EPWM6_BASE
// CMPSS
#define MTR1_CMPSS_U_BASE CMPSS1_BASE
#define MTR1_CMPSS_V_BASE CMPSS3_BASE
#define MTR1_CMPSS_W_BASE CMPSS3_BASE
Configure ADC base address and channels for compressor motor drive
// ADC
#define MTR1_ADC_TRIGGER_SOC ADC_TRIGGER_EPWM1_SOCA // EPWM1_SOCA
#define MTR1_ADC_SAMPLE_WINDOW 14
#define MTR1_IU_ADC_BASE ADCA_BASE // ADCA-A11*/C0
#define MTR1_IV_ADC_BASE ADCA_BASE // ADCA-A5*/C2
#define MTR1_IW_ADC_BASE ADCA_BASE // ADCA-A0*/C15
#define MTR1_VU_ADC_BASE ADCA_BASE // ADCA-A7*/C3
#define MTR1_VV_ADC_BASE ADCA_BASE // ADCA-A12*/C1
#define MTR1_VW_ADC_BASE ADCA_BASE // ADCA-A1*
#define MTR1_VDC_ADC_BASE PFC_VDC_ADC_BASE // ADCC-A4/C14*
#define MTR1_IU_ADCRES_BASE ADCARESULT_BASE // ADCA-A11*/C0
#define MTR1_IV_ADCRES_BASE ADCARESULT_BASE // ADCA-A5*/C2
#define MTR1_IW_ADCRES_BASE ADCARESULT_BASE // ADCA-A0*/C15
#define MTR1_VU_ADCRES_BASE ADCARESULT_BASE // ADCA-A7*/C3
#define MTR1_VV_ADCRES_BASE ADCARESULT_BASE // ADCA-A12*/C1
#define MTR1_VW_ADCRES_BASE ADCARESULT_BASE // ADCA-A1*
#define MTR1_VDC_ADCRES_BASE PFC_VDC_ADCRES_BASE // ADCC-A4/C14*
#define MTR1_IU_ADC_CH_NUM ADC_CH_ADCIN11 // ADCA-A11*/C0
#define MTR1_IV_ADC_CH_NUM ADC_CH_ADCIN5 // ADCA-A5*/C2
#define MTR1_IW_ADC_CH_NUM ADC_CH_ADCIN0 // ADCA-A0*/C15
#define MTR1_VU_ADC_CH_NUM ADC_CH_ADCIN7 // ADCA-A7*/C3
#define MTR1_VV_ADC_CH_NUM ADC_CH_ADCIN12 // ADCA-A12*/C1
#define MTR1_VW_ADC_CH_NUM ADC_CH_ADCIN1 // ADCA-A1*
#define MTR1_VDC_ADC_CH_NUM PFC_VDC_ADC_CH_NUM // ADCC-A4/C14*
#define MTR1_IU_ADC_SOC_NUM ADC_SOC_NUMBER0 // ADCA-A11*/C0-SOC0
#define MTR1_IV_ADC_SOC_NUM ADC_SOC_NUMBER1 // ADCA-A5*/C2 -SOC1
#define MTR1_IW_ADC_SOC_NUM ADC_SOC_NUMBER2 // ADCA-A0*/C15-SOC2
#define MTR1_VU_ADC_SOC_NUM ADC_SOC_NUMBER3 // ADCA-A7*/C3 -SOC3
#define MTR1_VV_ADC_SOC_NUM ADC_SOC_NUMBER4 // ADCA-A12*/C1-SOC4
#define MTR1_VW_ADC_SOC_NUM ADC_SOC_NUMBER5 // ADCA-A1* -SOC5
#define MTR1_VDC_ADC_SOC_NUM PFC_VDC_ADC_SOC_NUM // ADCC-A4/C14*
Configure peripheral interrupt for compressor motor drive control
// Interrupt
#define MTR1_ADC_INT_BASE ADCA_BASE // ADCA-A1 -SOC5
#define MTR1_ADC_INT_NUM ADC_INT_NUMBER2 // ADCA_INT2-SOC5
#define MTR1_ADC_INT_SOC ADC_SOC_NUMBER6 // ADCA_INT2-SOC5
#define MTR1_PIE_INT_NUM INT_ADCA2 // ADCA_INT2-SOC5
#define MTR1_CPU_INT_NUM INTERRUPT_CPU_INT10 // ADCA_INT2-CPU_INT10
#define MTR1_INT_ACK_GROUP INTERRUPT_ACK_GROUP10 // ADCA_INT2-CPU_INT10
Configure the connections between ADC pin and CMPSS modules in hal.h based on the hardware, the details refer to the Table, Analog Pins and Internal Connections in TMS320F28002x Real-Time Microcontrollers Technical Reference Manual, TMS320F28003x Real-Time Microcontrollers Technical Reference Manual, or TMS320F280013x Real-Time Microcontrollers Technical Reference Manual
// ADC pins connection to CMPSS
#define MTR1_IU_CMPHP_SEL ASYSCTL_CMPHPMUX_SELECT_1 //A11*/C0, CMPSS1-HP
#define MTR1_IU_CMPLP_SEL ASYSCTL_CMPLPMUX_SELECT_1 //A11*/C0, CMPSS1-LP, N/A
#define MTR1_IV_CMPLP_SEL ASYSCTL_CMPLPMUX_SELECT_3 //A5*/C2, CMPSS3-LP
#define MTR1_IW_CMPLP_SEL ASYSCTL_CMPLPMUX_SELECT_3 //A0*/C15, CMPSS3-LP, N/A
#define MTR1_IU_CMPHP_MUX 1 //A11*/C0, CMPSS1-HP
#define MTR1_IU_CMPLP_MUX 1 //A11*/C0, CMPSS1-LP, N/A
#define MTR1_IV_CMPLP_MUX 1 //A5*/C2, CMPSS3-LP, N/A
#define MTR1_IW_CMPLP_MUX 2 //A0*/C15, CMPSS3-LP, N/A
Configure the trip signals from CMPSS to be passed to EPWM and GPIO output in hal.h based on the hardware, the details refer to Table, ePWM X-BAR Mux Configuration Table and Table, OUTPUT X-BAR Mux Configuration Table in TMS320F28002x Real-Time Microcontrollers Technical Reference Manual, TMS320F28003x Real-Time Microcontrollers Technical Reference Manual, or TMS320F280013x Real-Time Microcontrollers Technical Reference Manual.
// XBARINTPUT to EPWM
#define MTR1_XBAR_TRIP_ADDRL XBAR_O_TRIP7MUX0TO15CFG
#define MTR1_XBAR_TRIP_ADDRH XBAR_O_TRIP7MUX16TO31CFG
#define MTR1_IU_XBAR_EPWM_MUX XBAR_EPWM_MUX00_CMPSS1_CTRIPH // CMPSS1-HP
#define MTR1_IV_XBAR_EPWM_MUX XBAR_EPWM_MUX05_CMPSS3_CTRIPL // CMPSS3-LP
#define MTR1_IW_XBAR_EPWM_MUX XBAR_EPWM_MUX05_CMPSS3_CTRIPL // CMPSS3-LP, N/A
#define MTR1_IU_XBAR_MUX XBAR_MUX00 // CMPSS1-HP
#define MTR1_IV_XBAR_MUX XBAR_MUX05 // CMPSS3-LP
#define MTR1_IW_XBAR_MUX XBAR_MUX05 // CMPSS3-LP
#define MTR1_XBAR_INPUT XBAR_INPUT1
#define MTR1_TZ_OSHT EPWM_TZ_SIGNAL_OSHT1
#define MTR1_XBAR_TRIP XBAR_TRIP7
#define MTR1_DCTRIPIN EPWM_DC_COMBINATIONAL_TRIPIN7
The related ADC channels are used for motor current sensing which pins are internally connected to the Comparator Subsystem (CMPSS), configure the CMPSS registers in the HAL_setupCMPSSs() function in the file of hal.c as the following codes. Compressor motor control uses two CMPSS modules, two analog comparators of each CMPSS are used to implement positive and negative overcurrent protection of U-phase and V-phase of the motor.
// HAL_setupCMPSSsMTR
void HAL_setupCMPSSsMTR(HAL_MTR_Handle handle)
{
HAL_MTR_Obj *obj = (HAL_MTR_Obj *)handle;
uint16_t cmpsaDACH;
uint16_t cmpsaDACL;
// Refer to the Table 9-2 in Chapter 9 of TMS320F28004x
// Technical Reference Manual (SPRUI33B), to configure the ePWM X-Bar
if(obj->motorNum == MTR_1)
{
cmpsaDACH = MTR1_CMPSS_DACH_VALUE;
cmpsaDACL = MTR1_CMPSS_DACL_VALUE;
ASysCtl_selectCMPHPMux(MTR1_IU_CMPHP_SEL, MTR1_IU_CMPHP_MUX);
ASysCtl_selectCMPLPMux(MTR1_IV_CMPLP_SEL, MTR1_IV_CMPLP_MUX);
// --------------- U-Phase ---------------------------------------------
// Enable CMPSS and configure the negative input signal to come from the DAC
CMPSS_enableModule(obj->cmpssHandle[0]);
}
The CMPSS-generated signals go to the X-Bar, where they can be combined in different and unique fashions to flag unique trip events from multiple sources to implement the fault protection. The faults include the over-current signals from the CMPSS and the fault indicator output from the power module. Configure the XBAR registers in HAL_setupMtrFaults() function in the file of hal.c as the following codes.
void HAL_setupMtrFaults(HAL_MTR_Handle handle)
{
HAL_MTR_Obj *obj = (HAL_MTR_Obj *)handle;
uint16_t cnt;
uint16_t tzSignal;
uint16_t dcTripIn;
if(obj->motorNum == MTR_1)
{
}
else if(obj->motorNum == MTR_2)
{
}
}
Configure the GPIOs based on the hardware in HAL_setupGPIOs() in the file of hal.c as the following codes.
void HAL_setupGPIOs(HAL_Handle handle)
{
// GPIO0->EPWM1A->M2/FAN_UH
GPIO_setPinConfig(GPIO_0_EPWM1_A);
GPIO_setDirectionMode(0, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(0, GPIO_PIN_TYPE_STD);
return;
} // end of HAL_setupGPIOs() function
As described above, to configure the PWM, ADC, CMPSS and fault protection for fan motor and PFC control based on the hardware. The PFC uses HAL_setupCMPSSsPFC(), and HAL_setupPFCFaults().
Also need to change the configuration codes in HAL_enableMtrPWM(), HAL_enablePFCPWM(), HAL_clearMtrFaultStatus(), and HAL_clearPFCFaultStatus() in hal.h file as below marked bold according to the used CMPSS for motor and PFC control.
static inline void HAL_enableMtrPWM(HAL_MTR_Handle handle)
{
HAL_MTR_Obj *obj = (HAL_MTR_Obj *)handle;
if(obj->motorNum == MTR_1)
{
// Clear any comparator digital filter output latch
CMPSS_clearFilterLatchHigh(obj->cmpssHandle[0]);
CMPSS_clearFilterLatchHigh(obj->cmpssHandle[1]);
CMPSS_clearFilterLatchLow(obj->cmpssHandle[2]);
}
else if(obj->motorNum == MTR_2)
{
// Clear any comparator digital filter output latch
CMPSS_clearFilterLatchHigh(obj->cmpssHandle[0]);
CMPSS_clearFilterLatchLow(obj->cmpssHandle[1]);
CMPSS_clearFilterLatchLow(obj->cmpssHandle[2]);
}
... ...
return;
} // end of HAL_enableMtrPWM() function
static inline void HAL_clearMtrFaultStatus(HAL_MTR_Handle handle)
{
if(obj->motorNum == MTR_1)
{
// Clear any comparator digital filter output latch
CMPSS_clearFilterLatchHigh(obj->cmpssHandle[0]);
CMPSS_clearFilterLatchHigh(obj->cmpssHandle[1]);
CMPSS_clearFilterLatchLow(obj->cmpssHandle[2]);
}
else if(obj->motorNum == MTR_2)
{
// Clear any comparator digital filter output latch
CMPSS_clearFilterLatchHigh(obj->cmpssHandle[0]);
CMPSS_clearFilterLatchLow(obj->cmpssHandle[1]);
CMPSS_clearFilterLatchLow(obj->cmpssHandle[2]);
}
... ...
return;
} // end of HAL_clearMtrFaultStatus() function