QDEC driver

group nrfx_qdec

Quadrature Decoder (QDEC) peripheral driver.

Defines

NRFX_QDEC_INSTANCE(id)

Macro for creating an instance of the QDEC driver.

NRFX_QDEC_DEFAULT_CONFIG(_pin_a, _pin_b, _pin_led)

QDEC driver default configuration.

This configuration sets up QDEC with the following options:

  • report period: 10 samples

  • sampling period: 16384 us

  • LED enabled for 500 us before sampling

  • LED polarity: active high

  • debouncing filter disabled

  • sample ready interrupt disabled

Parameters:
  • _pin_a[in] Pin for A encoder channel input.

  • _pin_b[in] Pin for B encoder channel input.

  • _pin_led[in] Pin for LED output.

Typedefs

typedef void (*nrfx_qdec_event_handler_t)(nrfx_qdec_event_t event, void *p_context)

QDEC event handler.

Param event:

[in] QDEC event structure.

Param p_context:

[in] Context passed to event handler.

Functions

nrfx_err_t nrfx_qdec_init(nrfx_qdec_t const *p_instance, nrfx_qdec_config_t const *p_config, nrfx_qdec_event_handler_t handler, void *p_context)

Function for initializing QDEC.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • p_config[in] Pointer to the structure with the initial configuration.

  • handler[in] Event handler provided by the user. Must not be NULL.

  • p_context[in] Context passed to event handler.

Return values:
  • NRFX_SUCCESS – Initialization was successful.

  • NRFX_ERROR_ALREADY – The driver is already initialized.

  • NRFX_ERROR_INVALID_STATE – The driver is already initialized. Deprecated - use NRFX_ERROR_ALREADY instead.

nrfx_err_t nrfx_qdec_reconfigure(nrfx_qdec_t const *p_instance, nrfx_qdec_config_t const *p_config)

Function for reconfiguring QDEC.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • p_config[in] Pointer to the structure with the configuration.

Return values:
  • NRFX_SUCCESS – Reconfiguration was successful.

  • NRFX_ERROR_BUSY – The driver is enabled and cannot be reconfigured.

  • NRFX_ERROR_INVALID_STATE – The driver is uninitialized.

void nrfx_qdec_uninit(nrfx_qdec_t const *p_instance)

Function for uninitializing QDEC.

Note

Function asserts if module is uninitialized.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

bool nrfx_qdec_init_check(nrfx_qdec_t const *p_instance)

Function for checking if the QDEC driver instance is initialized.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

Return values:
  • true – Instance is already initialized.

  • false – Instance is not initialized.

void nrfx_qdec_enable(nrfx_qdec_t const *p_instance)

Function for enabling QDEC.

Note

Function asserts if module is uninitialized or enabled.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

void nrfx_qdec_disable(nrfx_qdec_t const *p_instance)

Function for disabling QDEC.

Note

Function asserts if module is uninitialized or disabled.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

void nrfx_qdec_accumulators_read(nrfx_qdec_t const *p_instance, int32_t *p_acc, uint32_t *p_accdbl)

Function for reading accumulated transitions from the QDEC peripheral.

Note

Function asserts if module is not enabled.

Note

Accumulators are cleared after reading.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • p_acc[out] Pointer to store the accumulated transitions.

  • p_accdbl[out] Pointer to store the accumulated double transitions.

NRFX_STATIC_INLINE uint32_t nrfx_qdec_task_address_get(nrfx_qdec_t const *p_instance, nrf_qdec_task_t task)

Function for returning the address of the specified QDEC task.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • task[in] QDEC task.

Returns:

Task address.

NRFX_STATIC_INLINE uint32_t nrfx_qdec_event_address_get(nrfx_qdec_t const *p_instance, nrf_qdec_event_t event)

Function for returning the address of the specified QDEC event.

Parameters:
  • p_instance[in] Pointer to the driver instance structure.

  • event[in] QDEC event.

Returns:

Event address.

struct nrfx_qdec_t
#include <nrfx_qdec.h>

Data structure of the Quadrature Decoder (QDEC) driver instance.

Public Members

NRF_QDEC_Type *p_reg

Pointer to a structure with QDEC registers.

uint8_t drv_inst_idx

Index of the driver instance. For internal use only.

struct nrfx_qdec_config_t
#include <nrfx_qdec.h>

QDEC driver instance configuration structure.

Public Members

nrf_qdec_reportper_t reportper

Report period in samples.

nrf_qdec_sampleper_t sampleper

Sampling period in microseconds.

uint32_t psela

Pin number for A input.

uint32_t pselb

Pin number for B input.

uint32_t pselled

Pin number for LED output.

uint32_t ledpre

Time (in microseconds) how long LED is switched on before sampling.

nrf_qdec_ledpol_t ledpol

Active LED polarity.

bool dbfen

State of debouncing filter.

bool sample_inten

Enabling sample ready interrupt.

bool reportper_inten

Enabling report ready interrupt.

uint8_t interrupt_priority

QDEC interrupt priority.

bool skip_gpio_cfg

Skip GPIO configuration of pins.

When set to true, the driver does not modify any GPIO parameters of the used pins. Those parameters are supposed to be configured externally before the driver is initialized.

bool skip_psel_cfg

Skip pin selection configuration.

When set to true, the driver does not modify pin select registers in the peripheral. Those registers are supposed to be set up externally before the driver is initialized.

Note

When both GPIO configuration and pin selection are to be skipped, the structure fields that specify pins can be omitted, as they are ignored anyway.

struct nrfx_qdec_sample_data_evt_t
#include <nrfx_qdec.h>

QDEC sample event data.

Public Members

int8_t value

Sample value.

struct nrfx_qdec_report_data_evt_t
#include <nrfx_qdec.h>

QDEC report event data.

Public Members

int32_t acc

Accumulated transitions.

uint32_t accdbl

Accumulated double transitions.

struct nrfx_qdec_event_t
#include <nrfx_qdec.h>

QDEC event handler structure.

Public Members

nrf_qdec_event_t type

Event type.

nrfx_qdec_sample_data_evt_t sample

Sample event data.

nrfx_qdec_report_data_evt_t report

Report event data.

union nrfx_qdec_event_t.[anonymous] data

Union to store event data.