The IncrEnc interface can be used in one of the following configurations T3 as core or T2 as core
Setup with T3 as core
- T3 as incremental mode
- Multiplication factor:
- twoFold: use both edges of TxIn
- fourFold: use both edges of TxIn and TxEUD
- Reverse of direction supported by GPT12
- T3 value diff is used for speed calculation at high speed (speed > speedModeThreshold)
- T4 used for zero signal detection if pinZ is not NULL
- interrupt is generated to support turn calculation if zeroIsrPriority != 0
- T4 clears T3 on zero signal event on TxIn input
- T5 used for low speed calculation (speed < speedModeThreshold)
- Rising edge of TxIn or TxEUD captures the T5 timer in CAPREL
Setup with T2 as core
- T2 as incremental mode
- Multiplication factor:
- twoFold: sample on both edges of TxIn
- fourFold: sample on both edges of TxIn and TxEUD
- Reverse of direction supported by GPT12
- T2 value diff is used for speed calculation at high speed
- T4 used for zero signal detection if pinZeroTxEUD is not NULL
- T4 clears T2 on zero signal event on TxEUD input
Preparation
Include Files
Include following header file into your C code:
#include <Gpt12/Gpt/IfxGpt12_IncrEnc.h>
Variables
Interrupt Handler Installation
See also How to define Interrupts?
Define priorities for the Interrrupt handlers. This is normally done in the Ifx_IntPrioDef.h file:
#define ISR_PRIORITY_INCRENC_ZERO 6
Add the interrupt service routines to your C code. They have to call the GPT12 interrupt handlers by passing the gpt12 handle:
Finally install the interrupt handlers in your initialisation function:
IfxCpu_Irq_installInterruptHandler(&ISR_IncrIncZero, ISR_PRIORITY_INCRENC_ZERO);
Module Initialisation
The module initialisation can be done in the same function. Here an example:
Update
speed, position and direction of the incremental encoder can be collected by the following
{
refreshDeadLine =
addTTime(refreshDeadLine, tickRefresh);
}