Content including 1) peripheral features, work logic and work method; 2) driver design logic and use method.
More...
Peripheral features and how this peripheral works
The Enhanced Quadrature Decoder module interfaces to position/speed sensors that are used in industrial motor control applications and decodes shaft position, revolution count, and speed. The quadrature decoder gets 8 input signals: PHASEA, PHASEB, INDEX/PRESET, TRIGGER, HOME/ENABLE and ICAP[3:1] from those position/speed sensors, and outputs 11 signals: POS_MATCH[3:0], COMP_FLG[3:0], DIR, CNT_DN, and CNT_UP for system use.
Features
- Support 32-bit position counter
- Capable of modulo counting
- Could be initialized to a predetermined value by one of 6 different methods: (if CTRL[REV]=0,then initialized to initialization register; if CTRL[REV]=1, then initialized to modulus register)
- Software-triggered event
- Positive edge transition of TRIGGER input if CTRL2[INITPOS] is set
- INDEX signal transition if CTRL2[OPMODE] bit is clear and CTRL[XIP] equals 1
- HOME signal transition if CTRL2[OPMODE] bit is clear and CTRL[HIP] equals 1
- PRESET signal positive edge transition if CTRL2[OPMODE] bit is set
- Position counter roll-over and roll-under
- When the position counter registers are read, the snapshot of position counter, revolution count, and position difference counter could be saved to their respective hold registers.
- Support 4 operation modes:
- Quadrature decode mode
- Quadrature count mode
- Signal phase count mode
- Single Phase decode mode
- Support revolution counter with or without INDEX signal
- When INDEX signal used, INDEX signal pulse increases/decreases the revolution counter.
- When INDEX signal not used, the configurable modulus counting roll-over/roll-under is used to increase/decrease revolution counter.
- Support flexible speed measurement. EQDC uses the Position Difference Counter (POSD), Last Edge Time Counter (LASTEDGE), Position Difference Period Counter (POSDPER), and Position Difference Period Buffer (POSDPERBFR) to support both high rotation speed measurement and low rotation speed measurement.
- Support position match output pulse The position match output pulse could be used to trigger other modules. It can be configured to occur when:
- The position counter matches the application defined compare value.
- Or, the position counter registers (POS, REV or POSD) are read. Optionally, the position match event triggers interrupt.
- Configurable digital filter for input signals: PHASEA, PHASEB, INDEX/PRESET, HOME/ENABLE.
- Support watchdog timer EQDC uses a watchdog timer for non rotating shaft detection.
- The watchdog timeout value is configurable.
- The watchdog could be disabled.
- Watchdog timeout could trigger interrupt.
- Supports Interrupts.
- Input signal interrupts: HOME/ENABLE transition interrupt, INDEX/PRESET pulse interrupt, PHASEA and PHASEB simultaneous change interrupt.
- Watchdog timeout interrupt.
- Position compare event interrupt.
- Position counter interrupts: Roll over interrupt, roll under interrupt.
- Count direction change interrupt.
- Supports Double-set Registers Loading Operation. Eqdc uses Double-set Registers Loading Operation to re-configure register settings when the quadrature decoder is working. The following registers are "double-set" for this purpose:
- Compare registers (UCOMP0/LCOMP0,UCOMP1/LCOMP1,UCOMP2/LCOMP2,UCOMP3/LCOMP3)
- Initial registers (UINIT/LINIT)
- Modulus registers (UMOD/LMOD)
How this peripheral works
- Initialize the module clock, configure the input pins (PHASEA, PHASEB, INDEX/PRESET, HOME/ENABLE) based on use case, configure the TRIGGER and POSMATCH ICAP[3:1] signal if necessary.
- After configured, EQDC's Revolution Counter, Position Counter, Position Difference Counter, Last Edge Time Counter, and Position Difference Period Counter start to work based on configurations. Input signal PHASEA, PHASEB, INDEX/PRESET, HOME/ENABLE are filtered by digital glitch filter before feeding EQDC counters. The EQDC counters values are saved to each hold registers at the proper time, taking a snapshot of the counters' values allows a consistent view of a system's position and the velocity to be attained.
How this driver is designed to make this peripheral works
EQDC driver's initialize function EQDC_Init initializes the EQDC based on configuration structure eqdc_config_t. This function convers all the EQDC configurations. Generally EQDC is ready to work after calling this function. The function EQDC_GetDefaultConfig helps to fill the eqdc_config_t with default values.
Besides EQDC_Init for the whole module configuration, there are smaller flexible functions used for runtime setting, including:
- Watchdog: EQDC_EnableWatchdog, EQDC_SetWatchdogTimeout.
- Interrupt and status: EQDC_GetStatusFlags, EQDC_ClearStatusFlags, EQDC_GetSignalStatusFlags, EQDC_EnableInterrupts, and EQDC_DisableInterrupts.
- Counter value: EQDC_SetInitialPositionValue, EQDC_SetPositionCounterValue, EQDC_SetPositionModulusValue, EQDC_SetPositionCompareXValue, EQDC_SetPositionCompare1Value, EQDC_SetPositionCompare2Value and EQDC_SetPositionCompare3Value.
When EQDC is working, EQDC driver provides functions to get the counter registers value, revolution count value, position difference value, last edge time, position difference period.
How to use this driver
- Prepare the module clock, configure the input pins according to real use case, configure output pin if it is used.
- Prepare the configuration eqdc_config_t, initialize the EQDC using EQDC_Init.
- When EQDC started running, call the value get APIs to get the required register value to calculate position and speed.