This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Issues with PWM on nRF52

I have encountered two issues while using the NRF PWM driver on the nRF52 DK, with or without SoftDevice S132, along with SDK v11.0.0

The first one is the use of the NRF_DRV_PWM_PIN_INVERTED flag. Looking at the oscilloscope, I don't see the waveform's polarity changed, whether I OR the pin output number with the flag or not.

The second is stepping through a looped sequence. I never see the last duty value of my sequence being applied.

What could be going wrong, or what could I be missing here?

Below is the main.c I used to produce the issues without SoftDevice. It should run by just replacing main.c in peripheral\pwm_driver example. main.c

Parents
  • NRF_DRV_PWM_PIN_INVERTED only determines the idle state polarity, the 15th bit in the sequence value determines the polarity when playing the sequence, see here. To change the polarity, you have to or with 0x8000, for example:

    Value = 4 | 0x8000;
    

    The problem with the last duty not being played is a bug (or feature) in the SDK driver. When using nextstep to load new values from RAM the PWM peripheral does not know how many periods this value should be played, unlike when using RefreshCount where the number of periods is defined by the refresh field in the sequence. Therefore, the peripheral trigger the LOOPSDONE event when the last value is loaded from RAM. Since the driver sets up a short between LOOPSDONE event and SEQUENCE_START task, the sequence starts to load the first value from RAM and hence the last value have no time to be played.

    A simple workaround is to define the sequence to be one value longer, since the last value is not played when using nextstep.

    I will report this internally to see if we can fix this in future SDK.

  • Thanks Ole. The trick with making the sequence size 1 value longer is exactly what I am using instead. And the note about bit 15 determining the polarity is appreciated. I completely overlooked that piece of info.

Reply Children
No Data
Related