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

turning off qdec led

In the nrf52 specification:

"The Phase A, Phase B, and LED signals are mapped to physical pins according to the configuration specified in the PSEL.A, PSEL.B, and PSEL.LED registers respectively. If the CONNECT field value 'Disconnected' is specified in any of these registers, the associated signal will not be connected to any physical pin."

There doesn't seem to be an obvious wrapper for this in the sdk. How do I access the PSEL.LED connect field to disable the LED?

Thank you

  • Hi,

    Like this

        nrf_drv_qdec_config_t qdec_cfg = 
        {
            .reportper = NRF_QDEC_REPORTPER_10,             /**< Report period in samples. */
            .sampleper = NRF_QDEC_SAMPLEPER_128us,         /**< Sampling period in microseconds. */
            .psela = GPIO_INPUT_A,                          /**< Pin number for A input. */
            .pselb = GPIO_INPUT_B,                          /**< Pin number for B input. */
            .pselled = GPIO_INPUT_LED,                      /**< Pin number for LED output. */
            .ledpre = 10,                                   /**< Time (in microseconds) how long LED is switched on before sampling. */
            .ledpol = 0,                                    /**< Active LED polarity. */
            .dbfen = false,                                 /**< State of debouncing filter. */
            .sample_inten = true,                           /**< Enabling sample ready interrupt. */
            .interrupt_priority = 3,                        /**< QDEC interrupt priority. */
        };
        
        err_code = nrf_drv_qdec_init(&qdec_cfg, qdec_event_handler);
        APP_ERROR_CHECK(err_code);
        
        // Needed for my quad enc. as I have no external pulls
        nrf_gpio_cfg_input(qdec_cfg.pselb,NRF_GPIO_PIN_PULLUP);
        nrf_gpio_cfg_input(qdec_cfg.psela,NRF_GPIO_PIN_PULLUP);
        nrf_drv_qdec_enable();
        
        while (true)
        {
            __WFI();
        }
    

    Here you can set .pselled to whatever you like, for example disconnected.

    Best regards,

    Øyvind

  • You can set the pin to 0xFFFFFFFF.

    When using the default configuration (nrf_drv_qdec_init(NULL, qdec_event_handler)) you can set the default pin in nrf_drv_config.h:

    #define QDEC_CONFIG_PIO_LED 0xFFFFFFFF
    

    When using your own config:

    nrf_drv_qdec_config_t qdec_config;
    qdec_config.pselled = 0xFFFFFFFF;
    ...
    nrf_drv_qdec_init(&qdec_config, qdec_event_handler)
    
  • Note, if you are using the nrf_drv_qdec driver in SDK 12 (at least) you can NOT set the LED-pin to 0xFFFFFFFF! (you may do that for the psel.led register directly, but not when using the driver)

    This will in best case end up in an assert in nrf_gpio_pin_port_decode(), in worst case if assert is not enabled it will actually write to reg->PIN_CNF[0xFFFFFFFF] which is way out of range..

    This happens because nrf_drv_qdec_init calls:

    nrf_gpio_cfg_input(p_config->pselled, NRF_GPIO_PIN_NOPULL);
    
    ----> nrf_gpio_cfg(pin_number, ...)
    {
        NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
        reg->PIN_CNF[pin_number] = .... // pin_number = 0xFFFFFFFF
        


    See also: https://devzone.nordicsemi.com/f/nordic-q-a/37968/nrfx_qdec-driver-quirks

Related