ftm_quad_decoder_peripheral#
Overview#
This demo describes the usage of Quad Decoder feature in FTM module, which can be used to count the position of decoder.
An external decoder is used to generate the PHA and PHB’s signal. These two signals are feed to the FTM pins with Quad Decoder feature (FTMx_QD_PHA and FTMx_QD_PHB). Then, the counter value and direction would be displayed in terminal window predically.
Supported Boards#
FRDM-K22F
Hardware requirements
Mini/micro USB cable
FRDM-K22F board
Personal Computer
Encoder with PHA and PHB singal.
Board settings
Connect the “J24-2” (PTB0, FTM1_QD_PHA) to encoder’s PHA singal.
Connect the “J24-4” (PTB1, FTM1_QD_PHB) to encoder’s PHB singal.
Prepare the Demo
Connect a USB cable between the PC host and the OpenSDA USB port on the board.
Connect the board with encoder.
Open a serial terminal with these settings:
115200 baud rate
8 data bits
No parity
One stop bit
No flow control
Download the program to the target board.
Either press the reset button on your board or launch the debugger in your IDE to begin running the example.
Running the demo
Scroll forward and backword the encoder and watch the log on the terminal window:
FTM quad decoder peripheral example
Encoder direction: -
Get current counter: 0
Encoder direction: -
Get current counter: 0
Encoder direction: -
Get current counter: 0
Encoder direction: -
Get current counter: 0
Encoder direction: -
Get current counter: 0
Encoder direction: -
Get current counter: 1995
Encoder direction: +
Get current counter: 1998
Encoder direction: +
Get current counter: 11
Encoder direction: +
Get current counter: 7
Encoder direction: +
Get current counter: 13
Encoder direction: +
Get current counter: 0
Encoder direction: +
Get current counter: 0
Encoder direction: +
Get current counter: 0
Encoder direction: -
Get current counter: 1995