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.

CCS/TMS320F28379S: PWM is not working properly

Part Number: TMS320F28379S

Tool/software: Code Composer Studio

Hi,

I am testing the motor driver application.

PWM1A is for clockwise and PWM1B is for counter-clockwise.

When I want to move the motor with CW, I turn PWM1B off and PWM1A on. For CCW, turn PWM1A off and PWM1B on

PWM initialization part is as folllow.

-----

GPIO_setPadConfig(m->pwm.gpio_num_a, GPIO_PIN_TYPE_STD);
GPIO_setPadConfig(m->pwm.gpio_num_b, GPIO_PIN_TYPE_STD);
GPIO_setPinConfig(m->pwm.pin_cfg_pwm_a);
GPIO_setPinConfig(m->pwm.pin_cfg_pwm_b);

//
// Disable sync(Freeze clock to PWM as well)
//
SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);

//
// Set-up TBCLK
//
EPWM_setTimeBasePeriod(m->pwm.base, EPWM_TIMER_TBPRD); // 50KHz. same as EPOS2
EPWM_setPhaseShift(m->pwm.base, 0U);
EPWM_setTimeBaseCounter(m->pwm.base, 0U);

//
// Set up counter mode
//
EPWM_setTimeBaseCounterMode(m->pwm.base, EPWM_COUNTER_MODE_UP);
EPWM_disablePhaseShiftLoad(m->pwm.base);
EPWM_setClockPrescaler(m->pwm.base, EPWM_CLOCK_DIVIDER_1, EPWM_HSCLOCK_DIVIDER_1);

//
// Set up shadowing
//
EPWM_setCounterCompareShadowLoadMode(m->pwm.base, EPWM_COUNTER_COMPARE_A, EPWM_COMP_LOAD_ON_CNTR_ZERO);
EPWM_setCounterCompareShadowLoadMode(m->pwm.base, EPWM_COUNTER_COMPARE_B, EPWM_COMP_LOAD_ON_CNTR_ZERO);
//
// Set actions
// high at zero, low at comp a/b
//
EPWM_setActionQualifierAction(m->pwm.base, EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
EPWM_setActionQualifierAction(m->pwm.base,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);

// PWMB off
EPWM_setActionQualifierAction(m->pwm.base,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW, // off
EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
EPWM_setActionQualifierAction(m->pwm.base,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,
EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);

//
// Set Compare values
//
EPWM_setCounterCompareValue(m->pwm.base,EPWM_COUNTER_COMPARE_A,EPWM_MIN_CMP);
EPWM_setCounterCompareValue(m->pwm.base,EPWM_COUNTER_COMPARE_B,EPWM_MIN_CMP);

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

----

Motor movement control part is as follow.


// run PID controller
M0_uk = DCL_runPID_C2(&M0_pid1, M0_rk, M0_yk, M0_lk);
Duty = abs(M0_uk) % 1001;

DBG ("%f,%f,%d,%ld,%d\n", M0_yk, M0_uk, dir, Duty, m[0].current_ADC);

if (M0_uk < 0)
{
EPWM_setActionQualifierAction(EPWM1_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
EPWM_setActionQualifierAction(EPWM1_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
EPWM_setCounterCompareValue(EPWM1_BASE,EPWM_COUNTER_COMPARE_A, (uint16_t) Duty);   // working well
dir = 0;
}
else
{
EPWM_setActionQualifierAction(EPWM1_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
EPWM_setActionQualifierAction(EPWM1_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);

EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_B, (uint16_t) Duty); // not working
dir = 1;
}

PWM1A is working well, but, PWM1B is not working, very short width pulse is generated regardless Duty is high.

When I start PWM1B first, it is working well.

How can I change PWM1A to PWM1B or other wise, exclusive on the fly?

I use H-Bridge,so PWM1A and 1B should be working exclusively.

BR

Paul