This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is there an example code for using PWM on the nRF51822 with a SoftDevice?

I'm looking to add PWM functionality to my design to drive an LED. Examples exist for other devices, and those don't use the SoftDevice. Is there an example or some reference design for making the PWM module work with the nRF51822 and SD?

  • with this function you can choose the pwm output pins nrf_pwm_init (8,9,10,PWM_MODE_MTR_100);

  • Something strange is happening with this code. When I use PWM_NUM_CHANNELS 3 and use nrf_pwm_init(14, 8, 10, PWM_MODE_MTR_100); I get output on pin 14. But when I use PWM_NUM_CHANNELS 3 and nrf_pwm_init(14, PWM_MODE_MTR_100); for some reason the output is on pin 19! (LED_1 on the Evaluation Kit.) This is with the example above (not my own code).

  • What's the easiest way to disable the PWM and set the pin to 'OFF'. There's seems to have so many options for disabling stuff, but nothing seems to turn the LED OFF! Any hint is appreciated.

  • Basically, I'm trying to implement a pwm_stop() and pwm_start() functions (the pwm is used for pulsing an LED, which works). But after a few hours trying to make that work, I'm looking for help here ;) Frustrating.

  • Hi all

    1. I agree an example like this would be useful in the SDK. Maybe we can get something like it in the future ;)

    2. If you try to run pwm_init after enabling the SoftDevice it will trigger an exception. The reason for this is that pwm_init accesses the PPI peripheral directly, without going through the SoC Library API defined by the SoftDevice. It is possible to modify the PWM library to use the SoC Library, but then it will not work without the SD. This was the easiest way to make it work both with or without the SD.

    3. The PWM output is assigned to actual pins a couple of times in the code, each time it is using the PIN configuration stored in the pwm_io_ch[] array. Please have a look in the PWM_IRQHandler function, where the pin is controlled either through the GPIOTE or by the nrf_gpio_pin_write() function.

    4. Are you calling nrf_pwm_init with just 2 parameters when PWM_NUM_CHANNELS is 3? If you want to use just one PWM channel you should change the define to 1.

Related