Driver API for Quadrature Decoder.
The functions and other declarations used in this part of the driver are in cy_tcpwm_quaddec.h. You can also include cy_pdl.h to get access to all functions and declarations in the PDL.
A quadrature decoder is used to decode the output of a quadrature encoder. A quadrature encoder senses the position, velocity, and direction of an object (for example a rotating axle, or a spinning mouse ball). A quadrature decoder can also be used for precision measurement of speed, acceleration, and position of a motor's rotor, or with a rotary switch to determine user input.
The Quadrature Decoder has the following features:
- 16- or 32-bit Counter.
- Period Register. This is only available in TCPWM Version 2.
- Range 0, Range 0 Compare, Range 1 capture, Range 1 Compare Quadrature modes. This is only available in TCPWM Version 2.
- Counter Resolution of x1, x2, x4, and up/down rotary the frequency of the phiA (Count) and phiB (Start) inputs. Up/Down rotary resolution is only available in TCPWM Version 2
- Interrupt on Terminal Count and Compare or Capture 0. Interrupt on Compare or Capture 1 is only available in TCPWM Version 2.
- Index Input to determine absolute position
- A positive edge on phiA increments the counter when phiB is 0 and decrements the counter when phiB is 1
- Two programmable trigger outputs, trig_out0 and trig_out1 that generate a trigger on one of the following events Overflow, Underflow, Terminal Count, and Compare Match 0/1. The available triggers are dependent on the QuadDec mode. All these features are only available in TCPWM Version 2.
- TC (cc_match) trigger output is only available in TCPWM Version 1.
- Second Compare Match (CC_MATCH1) event is only available in TCPWM Version 2.
Configuration Considerations
The QuadDec configuration can be divided to number of sequential steps listed below:
Configure Quadrature
To configure Quadrature, provide the configuration parameters in the cy_stc_tcpwm_quaddec_config_t structure. The Configuration structure can be modified through software, but if the configurator in ModusToolbox is used then the configuration structure will be updated with the users input. To initialize the driver, call Cy_TCPWM_QuadDec_Init function providing a pointer to the populated cy_stc_tcpwm_quaddec_config_t structure.
For TCPWM V1 Configuration
{
};
#define MY_TCPWM_CNT_NUM (0UL)
{
}
Quadrature Decoder configuration structure.
Definition: cy_tcpwm_quaddec.h:121
@ CY_TCPWM_SUCCESS
Successful.
Definition: cy_tcpwm.h:399
__STATIC_INLINE void Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM_Type *base, uint32_t cntNum)
Triggers a software reload event (or index 0 in QuadDec mode) on selected TCPWM.
Definition: cy_tcpwm.h:913
__STATIC_INLINE void Cy_TCPWM_QuadDec_Enable(TCPWM_Type *base, uint32_t cntNum)
Enables the counter in the TCPWM block for the QuadDec operation.
Definition: cy_tcpwm_quaddec.h:306
cy_en_tcpwm_status_t Cy_TCPWM_QuadDec_Init(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_quaddec_config_t const *config)
Initializes the counter in the TCPWM block for the QuadDec operation.
Definition: cy_tcpwm_quaddec.c:58
#define CY_TCPWM_INT_ON_TC
Interrupt on Terminal count(TC)
Definition: cy_tcpwm.h:303
#define CY_TCPWM_QUADDEC_X1
X1 mode.
Definition: cy_tcpwm_quaddec.h:202
For TCPWM V2 Configuration
{
CY_TCPWM_INPUT_TRIG(0),
CY_TCPWM_INPUT_TRIG(1),
0UL,
0Ul,
0UL,
false,
0UL,
0UL,
false,
};
#define MY_TCPWM_CNT_NUM (0UL)
{
}
#define CY_TCPWM_CNT_TRIGGER_ON_DISABLED
Output trigger disabled.
Definition: cy_tcpwm.h:294
#define CY_TCPWM_QUADDEC_CAPTURE_ON_INDEX
Capture on Index.
Definition: cy_tcpwm_quaddec.h:213
#define CY_TCPWM_QUADDEC_MODE_RANGE0
Counter Range between 0x0000 and 0xFFFF / 0xFFFFFFFF (for GRP_CNT_WIDTH = 16 / 32)
Definition: cy_tcpwm_quaddec.h:188
Assign Clock Divider
The clock source must be connected to proper working. Any of the peripheral clock dividers could be used. Use the SysClk (System Clock) driver API to do that.
Enable Quadrature Decoder
Quadrature has to be enabled before starting
#define MY_TCPWM_QUADDEC_NUM (0UL)
Start Quadrature Decoder
Quadrature has to be started
#define MY_TCPWM_QUADDEC_NUM (0UL)