PSOC E8XXGP Device Support Library
Quadrature Decoder (TCPWM)

General Description

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:

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

/* Scenario: there is need to initialize
* the first (index = 0) quadrature decoder of the TCPWM0 block
* with the below configuration settings
*/
cy_stc_tcpwm_quaddec_config_t tcpwm_v1_qd_config =
{
/* .resolution = */ CY_TCPWM_QUADDEC_X1, /* One count during one encoder cycle */
/* .interruptSources = */ CY_TCPWM_INT_ON_TC, /* Simple example without index input */
/* .indexInputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* The default value (0UL) */
/* .indexInput = */ CY_TCPWM_INPUT_0, /* The index input is not used */
/* .stopInputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* The default value (0UL) */
/* .stopInput = */ CY_TCPWM_INPUT_0, /* The stop input is not used, the block will be stopped by SW */
/* .phiAInput = */ CY_TCPWM_INPUT_TRIG_0, /* The phiA input is connected to the trigger multiplexer #0 of the Trigger Group #3 */
/* .phiBInput = */ CY_TCPWM_INPUT_TRIG_1, /* The phiB input is connected to the trigger multiplexer #1 of the Trigger Group #3 */
};
#define MY_TCPWM_CNT_NUM (0UL)
if (CY_TCPWM_SUCCESS != Cy_TCPWM_QuadDec_Init(TCPWM0, MY_TCPWM_CNT_NUM, &tcpwm_v1_qd_config))
{
/* Handle possible errors */
}
/* Enabled the initialized quadrature decoder */
Cy_TCPWM_QuadDec_Enable(TCPWM0, MY_TCPWM_CNT_NUM);
/* Then start the decoder */
Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_CNT_NUM);
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_INPUT_RISINGEDGE
A rising edge triggers the event (Capture, Start, Reload, etc..)
Definition: cy_tcpwm.h:263
#define CY_TCPWM_INPUT_0
Input is tied to logic 0.
Definition: cy_tcpwm.h:225
#define CY_TCPWM_INPUT_TRIG_1
Input is connected to the trigger input 1.
Definition: cy_tcpwm.h:228
#define CY_TCPWM_INPUT_TRIG_0
Input is connected to the trigger input 0.
Definition: cy_tcpwm.h:227
#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

/* Scenario: there is need to initialize
* the first (index = 0) quadrature decoder of the TCPWM0 block
* with the below configuration settings
*/
cy_stc_tcpwm_quaddec_config_t tcpwm_v2_qd_config =
{
/* .resolution = */ CY_TCPWM_QUADDEC_X1, /* One count during one encoder cycle */
/* .interruptSources = */ CY_TCPWM_INT_ON_TC, /* Simple example without index input */
/* .indexInputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* The default value (0UL) */
/* .indexInput = */ CY_TCPWM_INPUT_0, /* The index input is not used */
/* .stopInputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* The default value (0UL) */
/* .stopInput = */ CY_TCPWM_INPUT_0, /* The stop input is not used, the block will be stopped by SW */
/* .phiAInput = */ CY_TCPWM_INPUT_TRIG(0), /* The phiA input is connected to the trigger multiplexer #0 of the Trigger Group #3 */
/* .phiBInput = */ CY_TCPWM_INPUT_TRIG(1), /* The phiB input is connected to the trigger multiplexer #1 of the Trigger Group #3 */
/* .phiAInputMode = */ CY_TCPWM_INPUT_LEVEL, /* Pass through (no edge detection) */
/* .phiBInputMode = */ CY_TCPWM_INPUT_LEVEL, /* Pass through (no edge detection) */
/* .quadmode = */ CY_TCPWM_QUADDEC_MODE_RANGE0, /* Quad mode */
/* .period0 = */ 0UL, /* Period 0 Value */
/* .captureOnIndex = */ CY_TCPWM_QUADDEC_CAPTURE_ON_INDEX, /* Capture On Index event */
/* .compare0 = */ 0Ul, /* Sets the value for Compare 0 */
/* .compareBuf0 = */ 0UL, /* Sets the value for the buffered Compare 0 */
/* .enableCompare0Swap = */ false, /* If enabled, the compare 0 values are swapped on the terminal count */
/* .compare1 = */ 0UL, /* Sets the value for Compare 1 */
/* .compareBuf1 = */ 0UL, /* Sets the value for the buffered Compare 0 */
/* .enableCompare1Swap = */ false, /* If enabled, the compare 0 values are swapped on the terminal count */
/* .capture0OrIndex1InputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* Configures how the capture0/index1 input behaves.*/
/* .capture0OrIndex1Input = */ CY_TCPWM_INPUT_0, /* Selects which input the capture0/index1 uses. The inputs are device-specific. */
/* .capture1InputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* Configures how the capture1 input behaves. */
/* .capture1Input = */ CY_TCPWM_INPUT_0, /* Selects which input the capture1 uses. The inputs are device-specific. */
/* .trigger0Event = */ CY_TCPWM_CNT_TRIGGER_ON_DISABLED, /* Disable output trigger0 event generation*/
/* .trigger1Event = */ CY_TCPWM_CNT_TRIGGER_ON_DISABLED, /* Disable output trigger1 event generation*/
};
#define MY_TCPWM_CNT_NUM (0UL)
if (CY_TCPWM_SUCCESS != Cy_TCPWM_QuadDec_Init(TCPWM0, MY_TCPWM_CNT_NUM, &tcpwm_v2_qd_config))
{
/* Handle possible errors */
}
/* Enabled the initialized quadrature decoder */
Cy_TCPWM_QuadDec_Enable(TCPWM0, MY_TCPWM_CNT_NUM);
/* Then start the decoder */
Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_CNT_NUM);
#define CY_TCPWM_INPUT_LEVEL
The event is triggered on each edge of the TCPWM clock if the input is high.
Definition: cy_tcpwm.h:269
#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

/* Scenario: Enable Quadrature Decoder */
#define MY_TCPWM_QUADDEC_NUM (0UL)
Cy_TCPWM_QuadDec_Enable(TCPWM0, MY_TCPWM_QUADDEC_NUM);

Start Quadrature Decoder

Quadrature has to be started

/* Scenario: Start Quadrature Decoder operation */
#define MY_TCPWM_QUADDEC_NUM (0UL)
Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_QUADDEC_NUM);

API Reference

 Macros
 
 Functions
 
 Data Structures
 

Macros

#define Cy_TCPWM_QuadDec_GetCapture   Cy_TCPWM_QuadDec_GetCapture0Val
 
#define Cy_TCPWM_QuadDec_GetCaptureBuf   Cy_TCPWM_QuadDec_GetCapture0BufVal