Is it possible to use high drive mode with PWM?

Hi,

I want to drive an RGB via PWM and need to increase the brightness.
Is it possible to configure the pins to high drive mode?
Is there a specific sequence that needs to be followed (first set the drive strength, then the PWM, or the other way around)?
There won't be any radio operation so just wanted to confirm that I can use any GPIO for this operation (PWM+high drive)

Thanks

Parents
  • Hi,

    Yes, you can select high drive for the PWM outputs. The problem is that the PWM driver does not expose the drive strength as a configuration setting, so you either have to modify the driver code, or change the drive strength after the pwm has been enabled by nrf_drv_pwm_init().

    Option 1: modify driver code

    static void configure_pins(nrfx_pwm_t const * const p_instance,
                               nrfx_pwm_config_t const * p_config)
    {
        uint32_t out_pins[NRF_PWM_CHANNEL_COUNT];
        uint8_t i;
    
        for (i = 0; i < NRF_PWM_CHANNEL_COUNT; ++i)
        {
            uint8_t output_pin = p_config->output_pins[i];
            if (output_pin != NRFX_PWM_PIN_NOT_USED)
            {
                bool inverted = output_pin &  NRFX_PWM_PIN_INVERTED;
                out_pins[i]   = output_pin & ~NRFX_PWM_PIN_INVERTED;
    
                if (inverted)
                {
                    nrf_gpio_pin_set(out_pins[i]);
                }
                else
                {
                    nrf_gpio_pin_clear(out_pins[i]);
                }
    
    #if PWM_HIGH_DRIVE
                nrf_gpio_cfg(out_pins[i], NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
                    NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
    #else 
                nrf_gpio_cfg_output(out_pins[i]);
    #endif
    
            }
            else
            {
                out_pins[i] = NRF_PWM_PIN_NOT_CONNECTED;
            }
        }
    
        nrf_pwm_pins_set(p_instance->p_registers, out_pins);
    }

    Option 2: Change drive strength after nrf_drv_pwm_init()

        APP_ERROR_CHECK(nrf_drv_pwm_init());
       NRF_P0->PIN_CNF[< pin number on port 0 >] |= (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos)

    Best regards,

    Vidar

Reply
  • Hi,

    Yes, you can select high drive for the PWM outputs. The problem is that the PWM driver does not expose the drive strength as a configuration setting, so you either have to modify the driver code, or change the drive strength after the pwm has been enabled by nrf_drv_pwm_init().

    Option 1: modify driver code

    static void configure_pins(nrfx_pwm_t const * const p_instance,
                               nrfx_pwm_config_t const * p_config)
    {
        uint32_t out_pins[NRF_PWM_CHANNEL_COUNT];
        uint8_t i;
    
        for (i = 0; i < NRF_PWM_CHANNEL_COUNT; ++i)
        {
            uint8_t output_pin = p_config->output_pins[i];
            if (output_pin != NRFX_PWM_PIN_NOT_USED)
            {
                bool inverted = output_pin &  NRFX_PWM_PIN_INVERTED;
                out_pins[i]   = output_pin & ~NRFX_PWM_PIN_INVERTED;
    
                if (inverted)
                {
                    nrf_gpio_pin_set(out_pins[i]);
                }
                else
                {
                    nrf_gpio_pin_clear(out_pins[i]);
                }
    
    #if PWM_HIGH_DRIVE
                nrf_gpio_cfg(out_pins[i], NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
                    NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
    #else 
                nrf_gpio_cfg_output(out_pins[i]);
    #endif
    
            }
            else
            {
                out_pins[i] = NRF_PWM_PIN_NOT_CONNECTED;
            }
        }
    
        nrf_pwm_pins_set(p_instance->p_registers, out_pins);
    }

    Option 2: Change drive strength after nrf_drv_pwm_init()

        APP_ERROR_CHECK(nrf_drv_pwm_init());
       NRF_P0->PIN_CNF[< pin number on port 0 >] |= (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos)

    Best regards,

    Vidar

Children
No Data
Related