nRF5 SDK is not maintained anymore
More Info: Consider nRF Connect SDK for new designs

PWM output frequency or prescaler change and configuration

Dear ,

I am using the nRF52833-DK development board with the NCS1.7.0 SDK.

I am trying to get a PWM waveform output at 50% duty cycle with 409.6kHz frequency based on the blinky_pwm and fade_led sample projects. However, it was unsuccessful.

Could you please kindly advise and help? How could I config/change the clock frequency for PWM peripheral? Currently, it seems to be 1MHz.

Thanks and regards, Kevin

  • Dear Øivind,

    Please see the zip file as attached. It was tested on nRF52833dk configured as nRF52833dk-nRF52820.

    In the main.c, if line108 - 113 are commented, you won't get the console printout string from the button_pressed callback. This problem disappears as long as these lines remain commented.

    Please kindly help.

    Thanks and kind regards, Kevin

  • The nRF52820 does not have a hardware PWM peripheral, only an implementation using the TIMER peripheral.

    It is disabled by default, try adding this file to your project and see if that works.

  • Dear Øivind,

    Thanks a lot for your reply.

    As for now, I do not have any issue with the PWM output on the desired pin, which has been checked with an oscilloscope.

    However, once the PWM function output is enabled, the button interrupt callback stopped working. I've also attached the nRF terminal output for your reference.

    Below showing the console output when PWM is off.

    *** Booting Zephyr OS build v2.6.99-ncs1  ***
    Set up button at GPIO_0 pin 11
    Set up LED at GPIO_0 pin 13
    Press the button
    Button pressed at 306246
    Button pressed at 320278
    Button pressed at 332251

    Below showing the console output when PWM is on.

    *** Booting Zephyr OS build v2.6.99-ncs1  ***
    Set up button at GPIO_0 pin 11
    Set up LED at GPIO_0 pin 13
    [00:00:00.319,458] <dbg> pwm_nrf5_sw.pwm_nrf5_sw_pin_set: PWM 13, period 320, pulse 160
    Press the button

    As you may see, there is no button_pressed console print info even though I've pressed the button multiple times.

    Could you please kindly help?

    Thanks and regards, Kevin

  • Can you try increasing the value of SLEEP_TIME_MS, 100 maybe, and commenting out the other content of the while loop?

  • Dear Øivind,

    I tried different values of SLEEP_TIME_MS and commenting out all other contents in the while loop as you suggested, but still with no luck.

    Please kindly advise and let me know if there are any other possible solutions I could try.

    Thanks and regards, Kevin

Related