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?

Parents
  • Hi all

    Please have a look at the attached example. It allows you to configure up to 3 IO's to run PWM, and gives you some different modes to pick from (varying base frequency, resolution).

    It will work with or without the SoftDevice, as long as you make sure torun the pwm_init() function before enabling the SoftDevice.

    This should not be considered an official Nordic example by the way ;)

    Best regards Torbjørn

    Simple PWM v1.0.zip

  • 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.

Reply
  • 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.

Children
No Data
Related