Unable to get PWM Duty Cycle to change

cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get PWM Duty Cycle to change

70 Views
Contributor V

I am setting up a PWM on an iMX RT 1064.

I see the 25% duty cycle on the PWM output pin set by initialization.

The duty cycle does not change when I call PWM_UpdatePwmDutycycle().

I must have missed some setting, but I can’t seem to find it.

 

Below is my setup and update duty cycle.

[PKI_PWM_SOLENOID].base = BOARD_INITPINS_SOLENOID_OUT_PERIPHERAL,
[PKI_PWM_SOLENOID].subModule = kPWM_Module_3,
[PKI_PWM_SOLENOID].controlModule = kPWM_Control_Module_3,
[PKI_PWM_SOLENOID].mode = kPWM_EdgeAligned,
[PKI_PWM_SOLENOID].pwmSignal.pwmChannel = kPWM_PwmA,
[PKI_PWM_SOLENOID].pwmSignal.level = kPWM_HighTrue,
[PKI_PWM_SOLENOID].pwmSignal.dutyCyclePercent = 25, // Just for testing, should be '0', off
[PKI_PWM_SOLENOID].pwmFrequencyInHz = 24000

    uint32_t pwmSourceClockInHz;

    pwmSourceClockInHz = PWM_SRC_CLK_FREQ;

 

    pwm_config_t pwm_config;

    PWM_GetDefaultConfig(&pwm_config);

 

    pwm_config.reloadLogic = kPWM_ReloadPwmFullCycle;

    pwm_config.pairOperation = kPWM_Independent;

    pwm_config.enableDebugMode = true;

    pwm_config.clockSource = kPWM_BusClock;

    pwm_config.prescale = kPWM_Prescale_Divide_4;

 

    status_t status = PWM_Init(pPKIpwmconfig->base, pPKIpwmconfig->subModule, &pwm_config);

 

    pwm_signal_param_t pwmSignal;

    pwmSignal.pwmChannel       = pPKIpwmconfig->pwmSignal.pwmChannel;

    pwmSignal.level            = pPKIpwmconfig->pwmSignal.level;

    pwmSignal.dutyCyclePercent = pPKIpwmconfig->pwmSignal.dutyCyclePercent;

 

    status = PWM_SetupPwm(pPKIpwmconfig->base, pPKIpwmconfig->subModule, &pwmSignal, 1, pPKIpwmconfig->mode,

             pPKIpwmconfig->pwmFrequencyInHz, pwmSourceClockInHz);

 

    pwm_module_control_t controlModule = pPKIpwmconfig->controlModule;

 

    /* Set the load okay bit for all submodules to load registers from their buffer */

    PWM_SetPwmLdok(pPKIpwmconfig->base, controlModule, true);

 

    /* Start the PWM generation from Submodule */

    PWM_StartTimer(pPKIpwmconfig->base, controlModule);

 

Update duty cycle

       PWM_Type* base = pPWMConfig->base;

       pwm_submodule_t subModule = pPWMConfig->subModule;

       pwm_channels_t pwmSignal = pPWMConfig->pwmSignal.pwmChannel;

       pwm_mode_t pwmMode = pPWMConfig->currPwmMode;

 

// --- DUTY CYCLE does not change with this call ---

       PWM_UpdatePwmDutycycle(base, subModule, pwmSignal, pwmMode, pwmDuty_percent);

       PWM_SetPwmLdok(base, pPWMConfig->controlModule, true);

Labels (1)
Tags (2)
0 Kudos
1 Reply

4 Views
NXP TechSupport
NXP TechSupport

Hello Keith,

 

I highly recommend you to refer to our MCUXpresso SDK. We have some examples using PWM that updates duty cycle by using PWM_UpdatePwmDutycycle.

 

You can download our SDK examples in this link: Welcome | MCUXpresso SDK Builder 

Best regards,

Felipe

-------------------------------------------------------------------------------

Note:

- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored.

Please open a new thread and refer to the closed one, if you have a related question at a later point in time.

------------------------------------------------------------------------------ 

0 Kudos