How to avoid setting one PWM active in complementary PWM mode before the first cycle?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to avoid setting one PWM active in complementary PWM mode before the first cycle?

943 Views
PseudoCircuit
Contributor II

Hello,

When using eFlexPWM in complementary mode, setting the OUTEN bits immediately sets PWM B to high (active) before even setting the LDOK bit or starting the timer. Here is an example of running just the PWM_SetupPwm() function which sets OUTEN bits at the end and without PWM_SetPwmLdok() and PWM_StartTimer() functions:

after_ldok.png

This results in PWM B being high before the first cycle starts. I uploaded a slightly modified PWM example from the SDK for MIMXRT1060-EVKB so you can easily test this yourself. This effect might be unnoticeable in lower PWM frequencies, but it is a big problem in higher frequencies (700Khz is set in the attached files). Here is a screenshot of the problem:

first_cylcle_original.png

PWM B (red) is high for a relatively long time before the first cycle of PWM A (blue) which is undesired behavior for our application. I managed to slightly reduce this problem by commenting out the OUTEN line in PWM_SetupPwm() and adding it just before PWM_StartTimer(). Here is the result:

enable_after_ldok.png

However, PWM B is still active before the first cycle, the time is just shorter because the operations were rearranged. I tried setting the OUTEN bits after starting the timer, but this enables the PWM outputs when the timer is already running, so they start at a random time of their cycle:

after_start_timer.png

 

Is the PWM B going high when setting the OUTEN bits (before LDOK and starting the timer) expected behavior? Is there any way to avoid it going high and have the complementary PWM start properly?

 

 

Labels (1)
0 Kudos
3 Replies

915 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I have checked your code, as you have changed the PWM driver, I think you have the following issue.

You have to use the original code to initialize kPWM_Module_0, kPWM_Module_1,kPWM_Module_2 independently, the code can not be changed, otherwise, the synchronization among three module has problem.

 

/* Use full cycle reload */
pwmConfig.reloadLogic = kPWM_ReloadPwmFullCycle;
/* PWM A & PWM B form a complementary PWM pair */
pwmConfig.pairOperation = kPWM_ComplementaryPwmA;
pwmConfig.enableDebugMode = true;

/* Initialize submodule 0 */
if (PWM_Init(BOARD_PWM_BASEADDR, kPWM_Module_0, &pwmConfig) == kStatus_Fail)
{
PRINTF("PWM initialization failed\n");
return 1;
}

/* Initialize submodule 1 */
pwmConfig.clockSource = kPWM_Submodule0Clock;
pwmConfig.initializationControl = kPWM_Initialize_MasterSync;
if (PWM_Init(BOARD_PWM_BASEADDR, kPWM_Module_1, &pwmConfig) == kStatus_Fail)
{
PRINTF("PWM initialization failed\n");
return 1;
}

/* Initialize submodule 2 the same way as submodule 1 */
if (PWM_Init(BOARD_PWM_BASEADDR, kPWM_Module_2, &pwmConfig) == kStatus_Fail)
{
PRINTF("PWM initialization failed\n");
return 1;
}

Secondly, I think it is okay to delete the base->OUTEN line in  PWM_SetupPwm() function, and add the base->OUTEN  line after the PWM_StartTimer() in main.

Pls have a try

BR

XiangJun Rong

0 Kudos

907 Views
PseudoCircuit
Contributor II

I tried using the original code, but this doesn't help to fix the issue, and I'm only using one module so synchronization between different modules does not seem relevant here. I uploaded the original PWM example from SDK, with the only change being removed clock dividers (use max available 150Mhz bus for PWM), reduced dead time and increased PWM frequency to 600khz. This is the output on PWM1 Submodule 0 pins A and B:

first_cycle_unmodified_example.png

 As you can see the issue is still very apparent.

0 Kudos

885 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I appologize for the delay.

Because I have been  working now at home for Convid-19, I can not test the PWM signals because of lack of resistor on the R278 and R280 on the EVK board.

How about putting the function PWMSigPin after the PWM module have started?

void BOARD_InitPins(void) {
CLOCK_EnableClock(kCLOCK_Iomuxc);

IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_12_LPUART1_TX, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_13_LPUART1_RX, 0U);

IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B0_12_LPUART1_TX, 0x10B0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B0_13_LPUART1_RX, 0x10B0U);

}

 

void PWMSigPin(void)

{

CLOCK_EnableClock(kCLOCK_Iomuxc);

OMUXC_SetPinMux(IOMUXC_GPIO_SD_B0_02_FLEXPWM1_PWMA01, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_SD_B0_03_FLEXPWM1_PWMB01, 0U);

IOMUXC_SetPinConfig(IOMUXC_GPIO_SD_B0_02_FLEXPWM1_PWMA01, 0x30B0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_SD_B0_03_FLEXPWM1_PWMB01, 0x30B0U);

}

Hope it can help you

BR

XiangJun Rong

0 Kudos