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.
Hi,
I was trying to use the EPWM module in up count mode to produce the following output in EPWM1B,
I configured EPWM1 for 4kHz frequency (TBPERIOD=30000). CMPA as 50% of the period (15000) and CMPB as 75% of the period (22500).
For EPWM1A, AQ_HIGH at ZERO and AQ_LOW at CMPA. Hence, it is producing a 50% duty 4kHz square wave. I got this done.
But for EPWM1B, AQ_HIGH at CMPA and AQ_LOW at CMPB. It should have produced a 25% duty square wave starting from the middle of the period. However, my EPWM1B is starting from zero with a 25% duty. I want it to get HIGH when time is half the period as I set CMPA=50% of PERIOD. I am observing EPWM1B and EPWM1A parallelly to see if it is coming proper.
Giving my code here,
#include "driverlib.h"
#include "device.h"
#define PWM_PERIOD 30000 // For 4kHz PWM waveform.
uint32_t PwmDuty = 15000; // Default is 50% duty cycle.
uint32_t PwmDuty_two = 22500; // Default is 75% duty cycle.
// Lab function prototypes.
inline void InitGpio(void);
inline void InitEPwm(void);
//
// Main
//
void main(void)
{
Device_init();
Interrupt_initModule();
Interrupt_initVectorTable();
InitGpio();
InitEPwm();
EINT;
ERTM;
for (;;) {
NOP;
}
}
inline void InitGpio(void)
{
Device_initGPIO();
GPIO_setPinConfig(GPIO_0_EPWM1_A);
GPIO_setPadConfig(0, GPIO_PIN_TYPE_PULLUP);
GPIO_setDirectionMode(0, GPIO_DIR_MODE_OUT);
GPIO_setPinConfig(GPIO_1_EPWM1_B);
GPIO_setPadConfig(1, GPIO_PIN_TYPE_PULLUP);
GPIO_setDirectionMode(1, GPIO_DIR_MODE_OUT);
}
inline void InitEPwm(void)
{
SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
SysCtl_resetPeripheral(SYSCTL_PERIPH_RES_EPWM1);
EPWM_setClockPrescaler(EPWM1_BASE,
EPWM_CLOCK_DIVIDER_1,
EPWM_HSCLOCK_DIVIDER_1);
EPWM_setTimeBasePeriod(EPWM1_BASE, PWM_PERIOD);
EPWM_setPeriodLoadMode(EPWM1_BASE, EPWM_PERIOD_SHADOW_LOAD);
EPWM_setPhaseShift(EPWM1_BASE, 0);
EPWM_setCounterCompareValue(EPWM1_BASE,
EPWM_COUNTER_COMPARE_A,
PwmDuty);
EPWM_setCounterCompareShadowLoadMode(EPWM1_BASE,
EPWM_COUNTER_COMPARE_A,
EPWM_COMP_LOAD_ON_CNTR_ZERO_PERIOD);
EPWM_setCounterCompareValue(EPWM1_BASE,
EPWM_COUNTER_COMPARE_B,
PwmDuty_two);
EPWM_setCounterCompareShadowLoadMode(EPWM1_BASE,
EPWM_COUNTER_COMPARE_B,
EPWM_COMP_LOAD_ON_CNTR_ZERO_PERIOD);
EPWM_setActionQualifierAction(EPWM1_BASE,
EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_HIGH,
EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
EPWM_setActionQualifierAction(EPWM1_BASE,
EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_LOW,
EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
EPWM_setActionQualifierAction(EPWM1_BASE,
EPWM_AQ_OUTPUT_B,
EPWM_AQ_OUTPUT_HIGH,
EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
EPWM_setActionQualifierAction(EPWM1_BASE,
EPWM_AQ_OUTPUT_B,
EPWM_AQ_OUTPUT_LOW,
EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);
EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_UP);
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
}
You code looks good. Can you set the other ACTIONS for all of the OTHER EVENTs?
What I have historically seen is the actions for the other events may not be set correctly and hence your EPWM output doesn't come out correctly. Try setting the actions for ALL other EVENTS even if you think they are not used.