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

PWM driver - invert pin

Hi,

I'm using nRF PWM Driver and I didn't find the way, how to invert logic of PWM. I would like to reach this behaviour:

  • If I set seq_value=0, I want to have PWM signal which is at logic zero for a whole period.
  • If I set seq_value=280, I want to have PWM signal which is at logic 1 for a whole period.
  • If I set seq_value=210, I want to have PWM signal which is at logic 1 75% of period and at logic 0 for 25 % of period.

Now I have exactly inverted behaviour and I'm not able change it. I tried set .output_pins without NRF_DRV_PWM_PIN_INVERTED and nothing changed. Where is the problem?

This is my code:

#define K_HW_GPIO_PWM_OUT1		28
#define K_HW_GPIO_PWM_OUT2		29
#define K_HW_GPIO_PWM_OUT3		30
#define K_HW_GPIO_PWM_OUT4		31

void pwm_init(void)
{
    nrf_drv_pwm_config_t const config0 =
    {
   
     .output_pins =
        {
            K_HW_GPIO_PWM_OUT1 | NRF_DRV_PWM_PIN_INVERTED,	// channel 0
            K_HW_GPIO_PWM_OUT2 | NRF_DRV_PWM_PIN_INVERTED,	// channel 1
            K_HW_GPIO_PWM_OUT3 | NRF_DRV_PWM_PIN_INVERTED,	// channel 2
            K_HW_GPIO_PWM_OUT4 | NRF_DRV_PWM_PIN_INVERTED	// channel 3
        },
        .irq_priority = APP_IRQ_PRIORITY_LOWEST,
        .base_clock   = NRF_PWM_CLK_16MHz,
        .count_mode   = NRF_PWM_MODE_UP,
        .top_value    = 280,
        .load_mode    = NRF_PWM_LOAD_INDIVIDUAL,
        .step_mode    = NRF_PWM_STEP_AUTO
    };
    // Init PWM without error handler
    APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm0, &config0, NULL));    
}
Related