Hi community,
I have generated 2 complemental PWM signal with dead time through eFlexPWM submodule0 A&B successfully, but I don't want to output the pulses continuously. I want to output several bursts of pulses. For example, 10 pulses(10us for each pulse) and 1s delay(no pulses out) as a cycle.
How can I generate such bursts pulses? Using timer? FORCE_OUT? Fault? And How to use the FORCE_OUT to generate such signal?
Solved! Go to Solution.
My recommendation is:
With 2 PWM signals(PWM1 and PWM2), use PWM1 (which has a a longer duty cycle at a lower frequency) to trigger PWM2 (wich has faster frequency) this way, with the duty cycle of PWM1 you can control the pulses generated on PWM2.
You can use the on Chip Cross Triggers module from the RT. Chapter 60 from reference manual.
My second recommendation is to use a timer to toggle a GPIO and count the times it have been triggered and after the amount of pulses you want you can stop or disable the timer.
Best Regards, Miguel.
My recommendation is:
With 2 PWM signals(PWM1 and PWM2), use PWM1 (which has a a longer duty cycle at a lower frequency) to trigger PWM2 (wich has faster frequency) this way, with the duty cycle of PWM1 you can control the pulses generated on PWM2.
You can use the on Chip Cross Triggers module from the RT. Chapter 60 from reference manual.
My second recommendation is to use a timer to toggle a GPIO and count the times it have been triggered and after the amount of pulses you want you can stop or disable the timer.
Best Regards, Miguel.
Thanks a lot. I have used timer to control two eFlexPWM signal. But it still have some problems. when I disable the output of PWM, PWMB still output high value. As the picture shows below:
void EXAMPLE_GPT_IRQHandler(void)
{
/* Clear interrupt flag.*/
GPT_ClearStatusFlags(EXAMPLE_GPT, kGPT_OutputCompare1Flag);
PWM_StartTimer(BOARD_PWM_BASEADDR, kPWM_Control_Module_2);
PWM_OutputEnable(BOARD_PWM_BASEADDR, kPWM_PwmA, kPWM_Module_2);
PWM_OutputEnable(BOARD_PWM_BASEADDR, kPWM_PwmB, kPWM_Module_2);
for (uint32_t i = 0; i < 20000; i++) {
__NOP(); // Introduce a 100us delay
}
PWM_StopTimer(BOARD_PWM_BASEADDR, kPWM_Control_Module_2);
BOARD_PWM_BASEADDR->OUTEN = 0x00;
}
static void PWM_DRV_Init3PhPwm(void)
{
uint16_t deadTimeVal;
pwm_signal_param_t pwmSignal[2];
uint32_t pwmSourceClockInHz;
uint32_t pwmFrequencyInHz = APP_DEFAULT_PWM_FREQUENCE;
pwmSourceClockInHz = PWM_SRC_CLK_FREQ;
/* Set deadtime count, we set this to about 1000ns */
deadTimeVal = ((uint64_t)pwmSourceClockInHz * 1000) / 1000000000;
pwmSignal[0].pwmChannel = kPWM_PwmA;
pwmSignal[0].level = kPWM_HighTrue;
pwmSignal[0].dutyCyclePercent = 50; /* 1 percent dutycycle */
pwmSignal[0].deadtimeValue = deadTimeVal;
pwmSignal[0].faultState = kPWM_PwmFaultState0;
pwmSignal[0].pwmchannelenable = true;
pwmSignal[1].pwmChannel = kPWM_PwmB;
pwmSignal[1].level = kPWM_HighTrue;
/* Dutycycle field of PWM B does not matter as we are running in PWM A complementary mode */
pwmSignal[1].dutyCyclePercent = 50;
pwmSignal[1].deadtimeValue = deadTimeVal;
pwmSignal[1].faultState = kPWM_PwmFaultState0;
pwmSignal[1].pwmchannelenable = true;
/*********** PWM1_sbm2 - configuration, setup PWM AB 2channels ************/
PWM_SetupPwm(BOARD_PWM_BASEADDR, kPWM_Module_2, pwmSignal, 2, kPWM_SignedCenterAligned, pwmFrequencyInHz,
pwmSourceClockInHz);
}
int main(void)
{
/* Structure of initialize PWM */
pwm_config_t pwmConfig;
pwm_fault_param_t faultConfig;
uint32_t pwmVal = 50;
/* Board pin, clock, debug console init */
BOARD_ConfigMPU();
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
CLOCK_SetDiv(kCLOCK_AhbDiv, 0x1); /* Set AHB PODF to 0, divide by 2 */
CLOCK_SetDiv(kCLOCK_IpgDiv, 0x3); /* Set IPG PODF to 0, divede by 1 */
// CLOCK_SetDiv(kCLOCK_AhbDiv, 0x2); /* Set AHB PODF to 2, divide by 3 */
// CLOCK_SetDiv(kCLOCK_IpgDiv, 0x3); /* Set IPG PODF to 3, divede by 4 */
/* Set the PWM Fault inputs to a low value */
XBARA_Init(XBARA1);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault0);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault1);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault2);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault3);
PRINTF("FlexPWM driver example\n");
PWM_GetDefaultConfig(&pwmConfig);
/* Use full cycle reload */
pwmConfig.reloadLogic = kPWM_ReloadPwmFullCycle;
/* PWM A & PWM B form a complementary PWM pair */
pwmConfig.pairOperation = kPWM_ComplementaryPwmA;
pwmConfig.enableDebugMode = true;
#ifdef DEMO_PWM_CLOCK_DEVIDER
pwmConfig.prescale = DEMO_PWM_CLOCK_DEVIDER;
#endif
/* Initialize submodule 2 */
if (PWM_Init(BOARD_PWM_BASEADDR, kPWM_Module_2, &pwmConfig) == kStatus_Fail)
{
PRINTF("PWM initialization failed\n");
return 1;
}
PWM_FaultDefaultConfig(&faultConfig);
#ifdef DEMO_PWM_FAULT_LEVEL
faultConfig.faultLevel = DEMO_PWM_FAULT_LEVEL;
#endif
/* Sets up the PWM fault protection */
PWM_SetupFaults(BOARD_PWM_BASEADDR, kPWM_Fault_0, &faultConfig);
PWM_SetupFaults(BOARD_PWM_BASEADDR, kPWM_Fault_1, &faultConfig);
PWM_SetupFaults(BOARD_PWM_BASEADDR, kPWM_Fault_2, &faultConfig);
PWM_SetupFaults(BOARD_PWM_BASEADDR, kPWM_Fault_3, &faultConfig);
/* Set PWM fault disable mapping for submodule 2 */
PWM_SetupFaultDisableMap(BOARD_PWM_BASEADDR, kPWM_Module_2, kPWM_PwmA, kPWM_faultchannel_0,
kPWM_FaultDisable_0 | kPWM_FaultDisable_1 | kPWM_FaultDisable_2 | kPWM_FaultDisable_3);
PWM_SetupFaultDisableMap(BOARD_PWM_BASEADDR, kPWM_Module_2, kPWM_PwmB, kPWM_faultchannel_0,
kPWM_FaultDisable_0 | kPWM_FaultDisable_1 | kPWM_FaultDisable_2 | kPWM_FaultDisable_3);
/* Call the init function with demo configuration */
PWM_DRV_Init3PhPwm();
/* Set the load okay bit for all submodules to load registers from their buffer */
PWM_SetPwmLdok(BOARD_PWM_BASEADDR, kPWM_Control_Module_2,true);
uint32_t gptFreq = 25000000;
gpt_config_t gptConfig;
/* Board pin, clock, debug console init */
BOARD_ConfigMPU();
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
GPT_GetDefaultConfig(&gptConfig);
/* Initialize GPT module */
GPT_Init(EXAMPLE_GPT, &gptConfig);
/* Divide GPT clock source frequency by 3 inside GPT module */
GPT_SetClockDivider(EXAMPLE_GPT, 3);
/* Set both GPT modules to 100us duration */
GPT_SetOutputCompareValue(EXAMPLE_GPT, kGPT_OutputCompare_Channel1, gptFreq);
/* Enable GPT Output Compare1 interrupt */
GPT_EnableInterrupts(EXAMPLE_GPT, kGPT_OutputCompare1InterruptEnable);
EnableIRQ(GPT_IRQ_ID);
GPT_StartTimer(EXAMPLE_GPT);
while (1U)
{
}
}
Hello @ahhhhhhhhhhh ,
Could you please point to me what MPU are you using?
Is your board a custom or EVK?
Are you using a BSP?
Please, share more details.
Best regards!
I am using the RT1064 evaluation kit.
Best Regards