MTB CAT1 Peripheral driver 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);

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);

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