Microchip® Advanced Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XMEGA Quadrature Decoder (QDEC)

This is a driver for the AVR XMEGA Quadrature Decoder module (QDEC).

It provides functions for enabling, disabling and configuring the QDEC module.

See Quick Start Guide for the XMEGA QDEC Driver

Modules

 Quick Start Guide(s)
 In this section you can find a list of all Quick Start guides related to the XMEGA Quadrature Decoder (QDEC).
 

Data Structures

struct  qdec_config
 

Typedefs

typedef struct qdec_config qdec_config_t
 

Enumerations

enum  QDec_index_rec_state {
  QDEC_STATE_NO_PH0_NO_PH90 = (0x00 << 0),
  QDEC_STATE_NO_PH0_PH90 = (0x01 << 0),
  QDEC_STATE_PH0_NO_PH90 = (0x02 << 0),
  QDEC_STATE_PH0_PH90 = (0x03 << 0)
}
 

Functions

void qdec_config_disable_index_pin (qdec_config_t *config)
 Disables index line. More...
 
void qdec_config_enable_freq (qdec_config_t *config, uint32_t unit)
 Defines frequency option. More...
 
void qdec_config_enable_index_pin (qdec_config_t *config, bool pin_invert, enum QDec_index_rec_state state)
 Defines index line to enable the automaticaly position reset. More...
 
void qdec_config_event_channel (qdec_config_t *config, uint8_t event_channel)
 Selects the event channel to use for quadrature decoder. More...
 
void qdec_config_freq_event_channel (qdec_config_t *config, uint8_t event_channel)
 Selects the event channel to use for frequency quadrature decoder. More...
 
void qdec_config_freq_tc (qdec_config_t *config, volatile void *timer)
 Selects the event channel to use for frequency quadrature decoder. More...
 
void qdec_config_phase_pins (qdec_config_t *config, PORT_t *port, uint8_t pins_base, bool pins_invert, uint16_t filter_us)
 This function set up the needed configuration to the port, used for the quadrature decoding. More...
 
void qdec_config_revolution (qdec_config_t *config, uint16_t revolution)
 Defines the revolution of quadrature decoder. More...
 
void qdec_config_tc (qdec_config_t *config, volatile void *timer)
 Selects the event channel to use for quadrature decoder. More...
 
void qdec_enabled (qdec_config_t *config)
 Loads and enables QDec system. More...
 
void qdec_get_config_defaults (qdec_config_t *config)
 This function initializes the configuration structure with the identified as commonly use case. More...
 
bool qdec_get_direction (qdec_config_t *config)
 Returns the direction of the quadrature decoding counter. More...
 
uint16_t qdec_get_frequency (qdec_config_t *config)
 Returns the frequency of quadrature encoder. More...
 
uint16_t qdec_get_position (qdec_config_t *config)
 Returns the position of quadrature encoder. More...
 
void qdec_reset_position (qdec_config_t *config)
 Returns the position of quadrature encoder. More...
 

typedef struct qdec_config qdec_config_t

Quadrature encoder configuration structure

Recognition states of index pin

Enumerator
QDEC_STATE_NO_PH0_NO_PH90 
QDEC_STATE_NO_PH0_PH90 
QDEC_STATE_PH0_NO_PH90 
QDEC_STATE_PH0_PH90 

void qdec_config_disable_index_pin ( qdec_config_t config)

Disables index line.

Parameters
configHandle on a QDec configuration structure

References qdec_config::enabled, and qdec_config::index.

void qdec_config_enable_freq ( qdec_config_t config,
uint32_t  unit 
)

Defines frequency option.

This option allows to compute automaticaly through an event and timer the frequency rotation. The system will be configurated with a resolution at least as high as the one specified. The resolution of a TC is synonymous with its clock frequency.

Parameters
configHandle on a QDec configuration structure
unitDesired unit used by qdec_get_frequency() in mHz.

References qdec_config::enabled, qdec_config::freq_opt, and qdec_config::unit.

void qdec_config_enable_index_pin ( qdec_config_t config,
bool  pin_invert,
enum QDec_index_rec_state  state 
)

Defines index line to enable the automaticaly position reset.

Parameters
configHandle on a QDec configuration structure
pin_invertTrue if IO pins should be inverted
stateRecognition states of index pin

References qdec_config::enabled, qdec_config::index, qdec_config::pin_invert, and qdec_config::rec_state.

void qdec_config_event_channel ( qdec_config_t config,
uint8_t  event_channel 
)

Selects the event channel to use for quadrature decoder.

Parameters
configHandle on a QDec configuration structure
event_channelWhich event channel to use for quadrature decoder XMEGA B, E authorizes channel 0. XMEGA D authorizes channel 0, 2. XMEGA A, C authorizes channel 0, 2, 4.

References qdec_config::event_channel.

void qdec_config_freq_event_channel ( qdec_config_t config,
uint8_t  event_channel 
)

Selects the event channel to use for frequency quadrature decoder.

Parameters
configHandle on a QDec configuration structure
event_channelWhich event channel to use for frequency QDec XMEGA B, E authorizes channel 0. XMEGA D authorizes channel 0, 2. XMEGA A, C authorizes channel 0, 2, 4. Note: If

References qdec_config::event_channel, and qdec_config::freq_opt.

void qdec_config_freq_tc ( qdec_config_t config,
volatile void *  timer 
)

Selects the event channel to use for frequency quadrature decoder.

Parameters
configHandle on a QDec configuration structure
timerPointer to timer module used for frequency QDec XMEGA E authorizes &TC4 or &TC5. other XMEGA authorizes &TC0, ...

References qdec_config::freq_opt, and qdec_config::timer.

void qdec_config_phase_pins ( qdec_config_t config,
PORT_t *  port,
uint8_t  pins_base,
bool  pins_invert,
uint16_t  filter_us 
)

This function set up the needed configuration to the port, used for the quadrature decoding.

Parameters
configHandle on a QDec configuration structure
portPointer to PORT module, which is used for quadrature
pins_baseFirst pin number to be used for QDPH0 input from port pins_base+1 for QDPH90 and pins_base+2 for QDINDX
pins_invertTrue if IO pins should be inverted
filter_usPin stable timing requested to validate level

References qdec_config::phases, qdec_config::pins_base, qdec_config::pins_filter_us, qdec_config::pins_invert, and qdec_config::port.

void qdec_config_revolution ( qdec_config_t config,
uint16_t  revolution 
)

Defines the revolution of quadrature decoder.

Parameters
configHandle on a QDec configuration structure
revolutionNumber of position for a revolution

References Assert, and qdec_config::revolution.

void qdec_config_tc ( qdec_config_t config,
volatile void *  timer 
)

Selects the event channel to use for quadrature decoder.

Parameters
configHandle on a QDec configuration structure
timerPointer to timer module used for Quadrature decoding XMEGA E authorizes &TC4 or &TC5. other XMEGA authorizes &TC0, ...

References qdec_config::timer.

void qdec_enabled ( qdec_config_t config)

Loads and enables QDec system.

Parameters
configHandle on a QDec configuration structure

References Assert, qdec_config::enabled, qdec_config::event_channel, qdec_config::freq_opt, qdec_config::port, qdec_enabled_evsys(), qdec_enabled_pins(), qdec_enabled_tc(), qdec_enabled_tc_freq(), and qdec_config::rotary.

void qdec_get_config_defaults ( qdec_config_t config)

This function initializes the configuration structure with the identified as commonly use case.

Parameters
configHandle on a QDec configuration structure

References qdec_config::enabled, qdec_config::event_channel, qdec_config::freq_opt, qdec_config::index, qdec_config::phases, qdec_config::pins_base, qdec_config::pins_filter_us, qdec_config::pins_invert, qdec_config::port, qdec_config::revolution, qdec_config::rotary, qdec_config::timer, and qdec_config::unit.

bool qdec_get_direction ( qdec_config_t config)

Returns the direction of the quadrature decoding counter.

Parameters
configHandle on a QDec configuration structure
Returns
if true, counter increment

References qdec_config::timer.

uint16_t qdec_get_frequency ( qdec_config_t config)

Returns the frequency of quadrature encoder.

Parameters
configHandle on a QDec configuration structure
Returns
frequency, the unit is defined by qdec_config_enable_freq()

References qdec_config::coef, qdec_config::freq_opt, qdec_config::last_freq, TC_CCA, tc_is_cc_interrupt(), tc_read_cc(), and qdec_config::timer.

uint16_t qdec_get_position ( qdec_config_t config)

Returns the position of quadrature encoder.

Parameters
configHandle on a QDec configuration structure
Returns
position

Note: The origin position is reseted:

References tc_read_count(), and qdec_config::timer.

void qdec_reset_position ( qdec_config_t config)

Returns the position of quadrature encoder.

Parameters
configHandle on a QDec configuration structure

References tc_write_count(), and qdec_config::timer.