This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to control the two channels in one PWM instance separately in nRF52840?

Hi

How to control two channels separately with one PWM instance?

I want to turn on/off the PWM output of each channel with any interrupt process.

app_pwm_disable() and app_pwm_enable() seem to only be able to turn the instances on and off.(Can't each channel be turned on/off?).

Since the nRF52840 has a limit of 3 PWM instances, I don't want to use 2 instances to control them (I plan to control the 4 channels separately).

Other information is as follows
Device: nRF52840-DK
Example: pwm_library
Soft device: S140
nRF SDK: 17.0.2

Thanks for your help!

  • Hi,

    Could you give me some more details about what you are trying to achieve? As I am reading this, it seems to me that maybe setting the duty cycle of the channel to zero would be sufficient?

  • Thank you for your reply.

    I want to output PWM only when an interrupt is generated by BLE to save power consumption during standby (sleep mode?).

    I also thought about setting the duty ratio to 0.But in that case, the timer is always running(?), so I thought it might consume too much power.

    Is this understanding correct?

  • Channels on the same instance use the same timer, so that is not something you should have to worry about.

    For power saving, setting unused channels to 0 duty cycle, and disabling the instance if you are not using any of the channels is what I recommend.

  • I have a few more questions about power saving and example selection.

    • Power Saving

    What do you recommend for disabling the instance in sleep mode?
    I thought of two ways to do it.

    1. Do you mean to initialize the PWM instance using app_pwm_init(), and then disable it using app_pwm_disable()?
    Then, when an interrupt is triggered, it could output PWM by enabling it and changing the duty ratio.

    2. Or, when an interrupt is triggered, create an instance, initialize and enable it, and output PWM.
    Then, just before the process is over and the system goes into sleep mode, the instance is destroyed, is that right?

    My understand about the CPU's behavior during sleep mode may be insufficient.

    • Example Selection

    To output PWM from four independent channels with power saving, which example from PWM library, PWM driver, or Low-Power PWM would be appropriate to select?

    I'm confused because I just learned that Low-Power PWM can have any number of instances.

    I will use PWM signals to control motors. Also, the example I'm currently using is a PWM library.

    Your help is very powerful. Thank you!

  • The app_pwm library is pretty old, so I recommend that you switch to PWM driver. Then you can try using nrfx_pwm_uninit() when you aren't using the motor. I don't think Low-Power PWM will meet the frequency requirement for use with motors.

Related