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?

    1. As for turning off the LED, can't you just write 0 to that PWM channel? That will disable the GPIOTE and set the output to 0 manually.
  • Hi again

    I made some change to the PWM library, and have uploaded a new version below:

    Changes include:

    1. Fixed a bug that would lead to an inverted output in certain circumstances
    2. Changed the API to be more in line with the rest of the SDK, using a config struct to initialize the driver
    3. Added a define in the header allowing the PWM library to be used in a "SoftDevice mode", where it detects whether or not the SoftDevice is enabled so that the PWM library can be initialized at any time

    I don't know if you ever solved your issue Nils?

    Best regards Torbjørn

    Simple PWM v1.2.zip

  • Hi,

    Thank you for remember my Problem. Yes after attachment i got the PWM working on my application. So thank you for your update.

    kind regards, Nils

  • Hi, I have the problem that my custom Timer controlled PWM has the same bug as yours had. I sometimes get inverted PWM output.

    Could you point out what was necessary to circumvent this??

    I try to update CC values for a timer at runtime by:

    
    void setPw(uint8_t pw) {
        gPulseW = pw;
        uint8_t period = 8 * gPeriod;
        NRF_TIMER0->CC[0] = pw;
        NRF_TIMER0->CC[1] = period/2;
        NRF_TIMER0->CC[2] = period/2+pw;
        NRF_TIMER0->CC[3] = period;
    }
    
    

    I tried to stop and start again, reset EVENTS_COMPARE Register, ... I don't seem to find the bug ...

    any help appreciated

  • Hi Andreas

    Did you figure this out?

    For questions like these I would recommend opening a new thread, otherwise it will quickly get lost. You can always refer to this thread to put your question in context.

    To answer your question, make sure you are not updating the CC registers while the timer value is at some random spot between min and max. If you look at the PWM example you can see that the CC registers are only updated while the timer is stopped and the timer value is at the max position.

    Best regards Torbjørn

Related