PWM not working when CONFIG_PM_DEVICE_RUNTIM is enabled on nRF52840

Hi folks,

I am working on an nRF52840-based custom board using nRF Connect SDK v3.2.4 and have observed an issue related to runtime power management and PWM.

Environment

  • SoC: nRF52840
  • NCS Version: v3.2.4
  • PWM Instance: pwm0
  • Use Case: Motor control

The motor control works as expected when runtime power management is disabled.

However, when I enable:

CONFIG_PM=y
CONFIG_PM_DEVICE=y
CONFIG_PM_DEVICE_RUNTIME=y

PWM0 no longer generates the expected output and the motor does not operate correctly.

Q: What is the recommended approach for keeping PWM active for continuous motor control while still benefiting from runtime power management ?

Thank you for your support.

Parents
  • Hi,

    When CONFIG_PM_DEVICE_RUNTIME=y is enabled, the PWM device starts in PM_DEVICE_STATE_SUSPENDED and thus automatically suspends whenever it is considered "not in use."
    If your driver does not explicitly call pm_device_runtime_get() before using the PWM, the device might be suspended mid-operation, which could be the reason why the motor does not operate correctly. LINK

    For continuous motor control, the PWM must remain active for the entire duration of motor operation.
    The recommended approach for keeping PWM active for continuous motor control pattern is: Since the device runtime PM API uses reference counting where the device stays active as long as the usage count is greater than zero.

    #include <zephyr/pm/device_runtime.h> # add in main.c
    CONFIG_STDOUT_CONSOLE=y
    CONFIG_PRINTK=y
    CONFIG_PWM=y
    CONFIG_LOG=y
    CONFIG_LOG_PRINTK=y
    CONFIG_LOG_MODE_IMMEDIATE=y
    CONFIG_PWM_LOG_LEVEL_DBG=y
    CONFIG_PWM_NRFX_NO_GLITCH_DUTY_100=n
    CONFIG_PM_DEVICE=y
    CONFIG_PM_DEVICE_RUNTIME=y
    #add in prj.conf

    1. Call pm_device_runtime_get() once when the motor starts → increments usage count, resumes PWM device.
    2. Call pm_device_runtime_put() once when the motor stops → decrements usage count, PM subsystem suspends PWM device.

     Can you please share your code, so we can try it at our end and provide you a solution.

    Regards
    Pallavi

Reply
  • Hi,

    When CONFIG_PM_DEVICE_RUNTIME=y is enabled, the PWM device starts in PM_DEVICE_STATE_SUSPENDED and thus automatically suspends whenever it is considered "not in use."
    If your driver does not explicitly call pm_device_runtime_get() before using the PWM, the device might be suspended mid-operation, which could be the reason why the motor does not operate correctly. LINK

    For continuous motor control, the PWM must remain active for the entire duration of motor operation.
    The recommended approach for keeping PWM active for continuous motor control pattern is: Since the device runtime PM API uses reference counting where the device stays active as long as the usage count is greater than zero.

    #include <zephyr/pm/device_runtime.h> # add in main.c
    CONFIG_STDOUT_CONSOLE=y
    CONFIG_PRINTK=y
    CONFIG_PWM=y
    CONFIG_LOG=y
    CONFIG_LOG_PRINTK=y
    CONFIG_LOG_MODE_IMMEDIATE=y
    CONFIG_PWM_LOG_LEVEL_DBG=y
    CONFIG_PWM_NRFX_NO_GLITCH_DUTY_100=n
    CONFIG_PM_DEVICE=y
    CONFIG_PM_DEVICE_RUNTIME=y
    #add in prj.conf

    1. Call pm_device_runtime_get() once when the motor starts → increments usage count, resumes PWM device.
    2. Call pm_device_runtime_put() once when the motor stops → decrements usage count, PM subsystem suspends PWM device.

     Can you please share your code, so we can try it at our end and provide you a solution.

    Regards
    Pallavi

Children
No Data
Related