Does PWM frequency of all 4 channels in one pwm module on an nRF52840 have to be the same?

Hi,

I am developing an application for an nRF52840 using nRF Connect SDK v2.9.0. The application currently uses the Zephyr driver for simple PWM functions on several GPIOs. Does the PWM frequency across all 4 channels (CH0, CH1, CH2, CH3) in one module (for example pwm0) have to be the same?

I think the answer is yes per the nRF52840 product specification. Correct me if I'm wrong.

However, the follow up question: Does the SDK or the Devicetree Visual Editor detect different PWM frequencies as a problem? It doesn't seem like it does, and so, if different channels of one pwm module are set to different frequencies, what frequency will prevail?

Thanks,

Ken

  • Hello Ken,

    You need to have the same PWM frequency accross all channels on the same PWM instance. You have 3 PWM instances, so that means you can have 3 separate frequencies. 

    You can also generate PWM signals withouot the PWM peripheral. One way is to use a TIMER instance, together with the GPIOTE peripheral and PPI to connect the two peripherals together. But that would also limit you to one frequency per TIMER instance. But if the case is that you need 4 different frequencies, it would be possible to acheive by using e.g. PWM0, PWM1, PWM2 and TIMERX (any timer instance not used by the SoftDevice Controller). 

    You can see that each PWM instance has it's own COUNTERTOP register:

    https://docs.nordicsemi.com/bundle/ps_nrf52840/page/pwm.html#register.COUNTERTOP

    This is the register that basically decides the frequency of the PWM instance. 

    Best regards,

    Edvin

  • Hi Edvin,

    Thanks for your response.  How about my followup questions from above:

    Does the SDK or the Devicetree Visual Editor detect different PWM frequencies as a problem? It doesn't seem like it does, and so, if different channels of one pwm module are set to different frequencies, what frequency will prevail?

    Also, why 3 and not 4 PWM instances?  SoftDevice Controller?  Is this active if using Zephyr?

    Ken

  • I haven't used the visual editor that much, but as far as I can see, it doesn't specify the frequency?

    If you look in e.g. the ncs\zephyr\samples\basic\blinky_pwm, you can see that the API that sets the PWM signal sets both the period and the duty cycle (pulse). I believe that if you have one instance running with one channel, and you try to set another channel with a different frequency, it will return an error.

    Best regards,

    Edvin

Related