(1)原理介绍
F280049C的PWM模块功能强大,可以比较容易的实现移相控制。 本节主要向大家讲述用DSP如何编程实现移相控制,如下图所示为移相全桥变换器的移相控制示意图,其中EPWM1A和EPWM1B为占空比50%的互补信号,EPWM2A和EPWM2B也为占空比50%的互补信号。通过控制EPWM1A和EPWM2B的移相角来实现移相控制。
如上图标注所示,控制上以PWM1的计数时基为基准信号,在PWM1的计数器为零(宏:EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO)时PWM1发出同步脉冲SyncOut,同时配置PWM2的同步信号来源为Syncln(宏:EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN)。相关的宏定义如下所示:
typedef enum
{
//! sync pulse is generated by software
EPWM_SYNC_OUT_PULSE_ON_SOFTWARE = 0,
//! sync pulse is passed from EPWMxSYNCIN
EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN = 0,
//! sync pulse is generated when time base counter equals zero
EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO = 1,
//! sync pulse is generated when time base counter equals compare B value.
EPWM_SYNC_OUT_PULSE_ON_COUNTER_COMPARE_B = 2,
//! sync pulse is disabled
EPWM_SYNC_OUT_PULSE_DISABLED = 4,
//! sync pulse is generated when time base counter equals compare D value.
EPWM_SYNC_OUT_PULSE_ON_COUNTER_COMPARE_C = 5,
//! sync pulse is disabled.
EPWM_SYNC_OUT_PULSE_ON_COUNTER_COMPARE_D = 6
}EPWM_SyncOutPulseMode;
当PWM1的时基计数到零数发出同步脉冲,此时,PWM2接收到同步脉冲后将相位寄存器TBPHS中的值加载到时基计数器TBCTR中。也就是说,当PWM1从零开始计数时,PWM2此时从TBPHS寄存器中的值开始计数。因此,PWM1和PWM2实现了移相,改变TBPHS寄存器中的值可以改变移相控制的移相角。
(2)相关寄存器配置
如上图所示,PWM1只需要配置其何时发出同步脉冲即可,相关配置如下所示:
EPWM_setSyncOutPulseMode(EPWM1_BASE,EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO); //计数到零时发出同步脉冲
PWM2需要配置其同步脉冲输入源和相位寄存器TBPHS的值,同时还需要使能相位寄存器的加载(图中的En,寄存器TBCTL中的PHSEN位),相关配置代码如下:
EPWM_enablePhaseShiftLoad(EPWM2_BASE); //使能相位寄存器
EPWM_setSyncOutPulseMode(EPWM2_BASE,EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN); //计数到零时发出同步脉冲
EPWM_setPhaseShift(EPWM2_BASE,250); //设置初始移相值
(3)PWM1和PWM2的配置
PWM1和PWM2的完整配置程序如下所示,其中包含了基本PWM输出的配置、死区时间的配置和移相控制的配置,每句程序后边都有详细的注释,方便大家阅读理解。要想实现PWM的输出,还需要配置与PWM相关的GPIO引脚,限于篇幅,在此不再列出,需要的话大家可以下载完整的实验工程(下载链接见文章末尾)。
void ePWM1_Configuration(void)
{
EPWM_setClockPrescaler(EPWM1_BASE,
EPWM_CLOCK_DIVIDER_1,
EPWM_HSCLOCK_DIVIDER_1); //ePWM 时钟为100MHZ
EPWM_setTimeBaseCounterMode(EPWM1_BASE,EPWM_COUNTER_MODE_UP); //设置计数模式(增计数)
EPWM_setTimeBaseCounter(EPWM1_BASE,0); //计数初始值设置
EPWM_setTimeBasePeriod(EPWM1_BASE,1000); //计数周期 fs=100kHz
EPWM_setPeriodLoadMode(EPWM1_BASE,EPWM_PERIOD_SHADOW_LOAD); //周期加载模式
EPWM_setCounterCompareShadowLoadMode(EPWM1_BASE,
EPWM_COUNTER_COMPARE_A,
EPWM_COMP_LOAD_ON_CNTR_ZERO_PERIOD);//比较值加载模式
EPWM_setCounterCompareValue(EPWM1_BASE,EPWM_COUNTER_COMPARE_A,500); //设定比较值
EPWM_setCounterCompareValue(EPWM1_BASE,EPWM_COUNTER_COMPARE_B,500);
EPWM_setActionQualifierAction(EPWM1_BASE,
EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_LOW,
EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA); //ePWMA的
EPWM_setActionQualifierAction(EPWM1_BASE,
EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_HIGH,
EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
EPWM_setSyncOutPulseMode(EPWM1_BASE,EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO); //计数到零时发出同步脉冲
EPWM_setRisingEdgeDeadBandDelayInput(EPWM1_BASE,EPWM_DB_INPUT_EPWMA);
EPWM_setFallingEdgeDeadBandDelayInput(EPWM1_BASE,EPWM_DB_INPUT_EPWMA); //配置死区输入模式
EPWM_setDeadBandDelayPolarity(EPWM1_BASE,EPWM_DB_RED,EPWM_DB_POLARITY_ACTIVE_HIGH);
EPWM_setDeadBandDelayPolarity(EPWM1_BASE,EPWM_DB_FED,EPWM_DB_POLARITY_ACTIVE_LOW);//配置极性
EPWM_setDeadBandDelayMode(EPWM1_BASE,EPWM_DB_RED,true);
EPWM_setDeadBandDelayMode(EPWM1_BASE,EPWM_DB_FED,true); //配置输出模式
EPWM_setDeadBandOutputSwapMode(EPWM1_BASE,EPWM_DB_OUTPUT_A,false);
EPWM_setDeadBandOutputSwapMode(EPWM1_BASE,EPWM_DB_OUTPUT_B,false); //输出不交换
EPWM_setRisingEdgeDelayCount(EPWM1_BASE,0); //上升沿延时0nS
EPWM_setFallingEdgeDelayCount(EPWM1_BASE,0); //下降沿延时0nS
EPWM_enableADCTrigger(EPWM1_BASE,EPWM_SOC_A);
EPWM_setADCTriggerSource(EPWM1_BASE,EPWM_SOC_A,EPWM_SOC_TBCTR_ZERO);
EPWM_setADCTriggerEventPrescale(EPWM1_BASE,EPWM_SOC_A,1);
}
void ePWM2_Configuration(void)
{
EPWM_setClockPrescaler(EPWM2_BASE,
EPWM_CLOCK_DIVIDER_1,
EPWM_HSCLOCK_DIVIDER_1); //ePWM 时钟为100MHZ
EPWM_setTimeBaseCounterMode(EPWM2_BASE,EPWM_COUNTER_MODE_UP); //设置计数模式(增计数)
EPWM_setTimeBaseCounter(EPWM2_BASE,0); //计数初始值设置
EPWM_setTimeBasePeriod(EPWM2_BASE,1000); //计数周期 fs=100kHz
EPWM_setPeriodLoadMode(EPWM2_BASE,EPWM_PERIOD_SHADOW_LOAD); //周期加载模式
EPWM_setCounterCompareShadowLoadMode(EPWM2_BASE,
EPWM_COUNTER_COMPARE_A,
EPWM_COMP_LOAD_ON_CNTR_ZERO_PERIOD);//比较值加载模式
EPWM_setCounterCompareValue(EPWM2_BASE,EPWM_COUNTER_COMPARE_A,500); //设定比较值
EPWM_setCounterCompareValue(EPWM2_BASE,EPWM_COUNTER_COMPARE_B,500);
EPWM_setActionQualifierAction(EPWM2_BASE,
EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_LOW,
EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA); //ePWMA的
EPWM_setActionQualifierAction(EPWM2_BASE,
EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_HIGH,
EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
EPWM_enablePhaseShiftLoad(EPWM2_BASE); //使能相位寄存器
EPWM_setSyncOutPulseMode(EPWM2_BASE,EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN); //计数到零时发出同步脉冲
EPWM_setPhaseShift(EPWM2_BASE,250); //设置初始移相值
EPWM_setRisingEdgeDeadBandDelayInput(EPWM2_BASE,EPWM_DB_INPUT_EPWMA);
EPWM_setFallingEdgeDeadBandDelayInput(EPWM2_BASE,EPWM_DB_INPUT_EPWMA); //配置死区输入模式
EPWM_setDeadBandDelayPolarity(EPWM2_BASE,EPWM_DB_RED,EPWM_DB_POLARITY_ACTIVE_HIGH);
EPWM_setDeadBandDelayPolarity(EPWM2_BASE,EPWM_DB_FED,EPWM_DB_POLARITY_ACTIVE_LOW);//配置极性
EPWM_setDeadBandDelayMode(EPWM2_BASE,EPWM_DB_RED,true);
EPWM_setDeadBandDelayMode(EPWM2_BASE,EPWM_DB_FED,true); //配置输出模式
EPWM_setDeadBandOutputSwapMode(EPWM2_BASE,EPWM_DB_OUTPUT_A,false);
EPWM_setDeadBandOutputSwapMode(EPWM2_BASE,EPWM_DB_OUTPUT_B,false); //输出不交换
EPWM_setRisingEdgeDelayCount(EPWM2_BASE,0); //上升沿延时0nS
EPWM_setFallingEdgeDelayCount(EPWM2_BASE,0); //下降沿延时0nS
}
(4)实验波形
设定移相角为90度,开关频率为100kHZ,占空比为50%。输出PWM1A和PWM2A的波形如下所示:
F280049移相控制完整的CCS工程我已经上传到了CSDN上,需要的可自行下载哈,程序中有不懂得地方都可以给我留言哈。下载链接如下:
https://download.csdn.net/download/fanxianyan1993/11110315