Learning the Teensy LC: Input Capture

Teensy LC input capture test

As a third step to learning the Teensy LC, I decided to tackle input capture. I discovered that there is no separate interrupt vector for input capture; it is the same vector used by the timer interrupt. This means that if we are looking for a timer overflow event as well as a pin change for input capture, we must check for that specific interrupt flag within the interrupt service routine (ISR).

To try the example, connect a button to pin 20 of the Teensy LC, and connect the other side of the button to the Teensy LC’s ground (G) pin. Run the code and open a serial terminal. Whenever you press the button, you will see the time (in nanoseconds) between edges. Push the button a number of times, and you’ll see examples of switch bounce.

Output of Teensy LC input capture

Leave a Reply