This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28379D: 28379D能实现PWM高精度移相吗

Part Number: TMS320F28379D

为什么我用普通精度的移相函数就可以让PWM波形移相,而使用高精度的移相函数就不行呢,下面是我的代码,我想让PWM2模块移相,使用HRPWM_setPhaseShift函数没有反应

#include "driverlib.h"
#include "device.h"
#include "board.h"

#define EPWM_TIMER_TBPRD 2000

//
// Function Prototypes
//
void initEPWM(uint32_t base);

__interrupt void epwm1ISR(void);
__interrupt void epwm2ISR(void);
__interrupt void epwm3ISR(void);
__interrupt void epwm4ISR(void);

//
// Main
//
void main(void)
{
//
// Initialize device clock and peripherals
//
Device_init();

//
// Disable pin locks and enable internal pull ups.
//
Device_initGPIO();

//
// Initialize PIE and clear PIE registers. Disables CPU interrupts.
//
Interrupt_initModule();

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
//
Interrupt_initVectorTable();

//
// Configure GPIO0/1 , GPIO2/3 and GPIO4/5 and GPIO6/7 as
// ePWM1A/1B, ePWM2A/2B, ePWM3A/3B, ePWM4A/4B pins respectively
//
Board_init();

// Disable sync(Freeze clock to PWM as well). GTBCLKSYNC is applicable
// only for multiple core devices. Uncomment the below statement if
// applicable.
//
// SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_GTBCLKSYNC);
SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);

//
// Initialize PWM1 without phase shift as master
//
initEPWM(myEPWM1_BASE);

//
// Initialize PWM2 with phase shift of 300 TBCLKs
//
initEPWM(myEPWM2_BASE);
EPWM_selectPeriodLoadEvent(myEPWM2_BASE, EPWM_SHADOW_LOAD_MODE_SYNC);
//EPWM_setPhaseShift(myEPWM2_BASE, 300);
//EPWM_setTimeBaseCounter(myEPWM2_BASE, 300);
HRPWM_setMEPEdgeSelect(myEPWM2_BASE, HRPWM_CHANNEL_A, HRPWM_MEP_CTRL_FALLING_EDGE);
HRPWM_setMEPControlMode(myEPWM2_BASE, HRPWM_CHANNEL_A, HRPWM_MEP_DUTY_PERIOD_CTRL);
float32_t count = (0.2 * (float32_t)(EPWM_TIMER_TBPRD << 8));
uint32_t compCount = (count);
HRPWM_setPhaseShift(myEPWM2_BASE, compCount);
//EPWM_setPhaseShift(myEPWM2_BASE, 300);
//
// Initialize PWM3 with phase shift of 600 TBCLKs
//
initEPWM(myEPWM3_BASE);
EPWM_selectPeriodLoadEvent(myEPWM3_BASE, EPWM_SHADOW_LOAD_MODE_SYNC);
EPWM_setPhaseShift(myEPWM3_BASE, 600);
EPWM_setTimeBaseCounter(myEPWM3_BASE, 600);

//
// Initialize PWM4 with phase shift of 900 TBCLKs
//
initEPWM(myEPWM4_BASE);
EPWM_selectPeriodLoadEvent(myEPWM4_BASE, EPWM_SHADOW_LOAD_MODE_SYNC);
EPWM_setPhaseShift(myEPWM4_BASE, 900);
EPWM_setTimeBaseCounter(myEPWM4_BASE, 900);

//
// ePWM1 SYNCO is generated on CTR=0
//
EPWM_setSyncOutPulseMode(EPWM1_BASE, EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO);

//
// ePWM2 uses the ePWM 1 SYNCO as its SYNCIN.
// ePWM2 SYNCO is generated from its SYNCIN, which is ePWM1 SYNCO
//
EPWM_setSyncOutPulseMode(myEPWM2_BASE, EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN);

//
// ePWM4 uses the ePWM 1 SYNCO as its SYNCIN.
//
SysCtl_setSyncInputConfig(SYSCTL_SYNC_IN_EPWM4, SYSCTL_SYNC_IN_SRC_EPWM1SYNCOUT);
//
// Enable all phase shifts.
//
EPWM_enablePhaseShiftLoad(myEPWM2_BASE);
EPWM_enablePhaseShiftLoad(myEPWM3_BASE);
EPWM_enablePhaseShiftLoad(myEPWM4_BASE);

HRPWM_enablePhaseShiftLoad(myEPWM2_BASE);
HRPWM_enablePhaseShiftLoad(myEPWM3_BASE);
HRPWM_enablePhaseShiftLoad(myEPWM4_BASE);

HRPWM_enableAutoConversion(myEPWM2_BASE);

//
// Enable sync and clock to PWM
//
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);

// Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
//
EINT;
ERTM;
for(;;)
{

}
}


void initEPWM(uint32_t base)
{
//
// Set-up TBCLK
//
EPWM_setTimeBasePeriod(base, EPWM_TIMER_TBPRD);
EPWM_setPhaseShift(base, 0U);
EPWM_setTimeBaseCounter(base, 0U);

//
// Set Compare values
//
EPWM_setCounterCompareValue(base,
EPWM_COUNTER_COMPARE_A,
EPWM_TIMER_TBPRD/2);
EPWM_setCounterCompareValue(base,
EPWM_COUNTER_COMPARE_B,
EPWM_TIMER_TBPRD/4);

//
// Set up counter mode
//
EPWM_setTimeBaseCounterMode(base, EPWM_COUNTER_MODE_UP);
EPWM_disablePhaseShiftLoad(base);
EPWM_setClockPrescaler(base,
EPWM_CLOCK_DIVIDER_8,
EPWM_HSCLOCK_DIVIDER_1);

//
// Set up shadowing
//
EPWM_setCounterCompareShadowLoadMode(base,
EPWM_COUNTER_COMPARE_A,
EPWM_COMP_LOAD_ON_CNTR_ZERO);
EPWM_setCounterCompareShadowLoadMode(base,
EPWM_COUNTER_COMPARE_B,
EPWM_COMP_LOAD_ON_CNTR_ZERO);

//
// Set actions
//
EPWM_setActionQualifierAction(base,
EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_HIGH,
EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
EPWM_setActionQualifierAction(base,
EPWM_AQ_OUTPUT_B,
EPWM_AQ_OUTPUT_HIGH,
EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
EPWM_setActionQualifierAction(base,
EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_LOW,
EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
EPWM_setActionQualifierAction(base,
EPWM_AQ_OUTPUT_B,
EPWM_AQ_OUTPUT_LOW,
EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);

}