ZHCU753A January 2022 – October 2022
用于控制电机和 PFC 的应用参数写为 #define,可根据硬件,在 hal.h 中配置 PWM、CMPSS 和 ADC 模块基地址。压缩机电机定义的 PWM、CMPSS、ADC 如以下代码所示。
为压缩机电机驱动器配置 PWM 和 CMPSS 基地址
// 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
为压缩机电机驱动器配置 ADC 基地址和通道
// 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*
为压缩机电机驱动器控制配置外设中断
// 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
根据硬件,在 hal.h 中配置 ADC 引脚与 CMPSS 模块之间的连接,有关详细信息,请参阅 TMS320F28002x 实时微控制器技术参考手册、TMS320F28003x 实时微控制器技术参考手册或 TMS320F280013x 实时微控制器技术参考手册中的表“模拟引脚和内部连接”。
// 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
根据硬件,在 hal.h 中配置从 CMPSS 传递到 EPWM 和 GPIO 输出的跳闸信号,有关详细信息,请参阅 TMS320F28002x 实时微控制器技术参考手册、TMS320F28003x 实时微控制器技术参考手册或 TMS320F280013x 实时微控制器技术参考手册中的“ePWM X-BAR 多路复用器配置表”和“输出 X-BAR 多路复用器配置表”。
// 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
相关的 ADC 通道用于电机电流检测哪些引脚在内部连接到比较器子系统 (CMPSS),在 hal.c 文件中的 HAL_setupCMPSSs() 函数中配置 CMPSS 寄存器,代码如下所示。压缩机电机控制采用两个 CMPSS 模块,每个 CMPSS 的两个模拟比较器用于实现电机 U 相和 V 相的正负过流保护。
// 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]);
}
CMPSS 生成的信号进入 X-Bar,在此处这些信号能够以不同且独特的方式组合,以标记来自多个来源的独特跳闸事件,从而实现故障保护。故障包括来自 CMPSS 的过流信号和电源模块的故障指示灯输出。在 hal.c 文件中的 HAL_setupMtrFaults() 函数中配置 XBAR 寄存器,代码如下所示。
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)
{
}
}
在 hal.c 文件中的 HAL_setupGPIOs() 中根据硬件配置 GPIO,代码如下所示。
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
如上所述,根据硬件为风扇电机和 PFC 控制配置 PWM、ADC、CMPSS 和故障保护。PFC 使用 HAL_setupCMPSSsPFC() 和 HAL_setupPFCFaults()。
还需要根据电机和 PFC 控制使用的 CMPSS 在 hal.h 文件中的 HAL_enableMtrPWM()、HAL_enablePFCPWM()、HAL_clearMtrFaultStatus() 和 HAL_clearPFCFaultStatus() 中更改配置代码,如下面标记为粗体的代码所示。
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