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

Invert PWM Behaviour

Is there any way to invert the PWM behaviour easily? I'm trying to develop firmware that will run on the DK52 (LED active high) and my custom board (LED active low).

I'm using the nrf_drv_pwm library and have tried to simply change the .output_pins in nrf_drv_pwm_config_t to

.output_pins = { led | NRF_DRV_PWM_PIN_INVERTED },

nRF52832 SDK14.1

Parents
  • Hi,

    The the most significant bit[15] in the sequence duty cycle values sets the polarity. See this and this link.

    So if you want seq_value 0 to correspond to 0 V, you need to set bit 15 to 1. E.g. by using bitwise OR.

    seq_values->channel_0 = duty_cycle | 0x8000;
    

    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

Reply
  • Hi,

    The the most significant bit[15] in the sequence duty cycle values sets the polarity. See this and this link.

    So if you want seq_value 0 to correspond to 0 V, you need to set bit 15 to 1. E.g. by using bitwise OR.

    seq_values->channel_0 = duty_cycle | 0x8000;
    

    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

Children
Related