How to use Timer Input Capture in LPC1768? LPC1768 Input Capture Tutorial

Table of Contents

In this tutorial, I will show you how to configure the Timer for Input Capture and How to use the Timer Input Capture in LPC1768 MCU. In the LPC1768 Timer Tutorial, I have explained about one important functionality of the Timer peripheral i.e. Timer Mode. The Input Capture Mode is another useful feature of Timer, usually used for frequency counting. Using this LPC1768 Timer Input Capture Tutorial, you can configure the timer block to capture incoming signals and calculate its frequency.

Introduction

Input Capture is a part of the MCU’s Timer Peripheral and is used read a digital signal applied to a pin of the MCU measure the LOW and HIGH transitions. The Input Capture feature is important in application related to frequency or time period measurement and pulse measurement.

It is very useful to know the duration of the ON Time and OFF Time of an incoming digital signal and one such commonly used application is the IR Signal Decoder.

Input Capture Block in LPC1768

From the LPC1768 Timer Tutorial, it is clear that there are four Timer Blocks in LPC1768 and each Timer Peripheral has two Input Capture Channels. The Input Capture can take a screenshot of the timer value whenever an input signal transition occurs.

To capture the inputs, we can use either ‘Timer Mode’ of the Timer or the ‘Counter Mode’ of the Timer. In timer mode input capture, the source of the signal is internal i.e. PCLK. We know that TC increments on every ‘PR+1’ cycles of PCLK. Upon detecting a signal edge like rising, falling or both, the value of the TC is loaded into the corresponding CRx i.e. Capture Register. Optionally, you can also generate an interrupt whenever the CRx is loaded with a new value.

In counter mode input capture, an external signal is applied to the CAPx.y pins and this signal is used to increment the TC upon detecting an edge (rising, falling or both). This can be configured in the CTCR Register.

Pins Associated with Input Capture

I have already mentioned the pins associated with the Timer Peripherals in the Timer Tutorial. But, as a reminder, the following table shows all the pins for Capture Signals.

NOTE: CAPx.y means, capture channel ‘y’ of Timerx.

 

 

CAP0.0 P1.26
CAP0.1 P1.27
CAP1.0 P1.18 / P1.28 / P2.6
CAP1.1 P1.19 / P1.29
CAP2.0 P0.4
CAP2.1 P0.5
CAP3.0 P0.23
CAP3.1 P0.24

 

 

Input Capture Registers in LPC1768

Let us now see the registers associated with Timer Input Capture in LPC1768.

CTCR – Count Control Register: Used to select either Timer Mode or Counter Mode. If counter mode is select, you can also select the input capture pin as well as the edge for counting (rising, falling or both).

 

 

Bits [1:0] Counter/Timer Mode When 00, Timer Mode. When 01, Counter Mode with rising edge. When 10, Counter Mode with falling edge. When 11, Counter Mode with both edges.
Bits [3:2] Counter Input Select When 00, CAPx.0 pin for Timerx.

When 01, CAPx.1 pin for Timerx.

 

 

CCR – Capture Control Register: Use to select the type of edge at which the TC is captured.

 

 

Bit 0 CAP0RE When 1, Capture on CAPx.0 Rising Edge.
Bit 1 CAP0FE When 1, Capture on CAPx.0 Falling Edge.
Bit 2 CAP0I When 1, Interrupt on CAPx.0 event.
Bit 3 CAP1RE When 1, Capture on CAPx.1 Rising Edge.
Bit 4 CAP1FE When 1, Capture on CAPx.1 Falling Edge.
Bit 5 CAP1I When 1, Interrupt on CAPx.1 event.

 

 

  • CR0 – CR1 – Capture Registers: Each Capture Register is associated with a device pin (CAPx.y) and can capture the value of TC when a specified event occurs on the pin.

Frequency Counter using Timer Input Capture in LPC1768

Let us now see an application of the Timer Input Capture in LPC1768 MCU. If you want to measure the frequency of an unknown signal, you can use the Input Capture Block of the LPC1768 and calculate it.

There are two ways in which you can measure the frequency of a signal. They are:

  • Using Interrupts
  • Using Probing (or Gating)

In Interrupts Method, we simply use an ISR to calculate the time between the consecutive pulses. This gives the period of the signal and from this period, we can easily calculate the frequency.

In Probing Method, a probing or gating interval is defined and, in this interval, we count the no. of pulses. From the Probing Interval and number of pulses, we can then calculate the frequency of the signal.

Conclusion

A simple tutorial on using the Timer Input Capture in LPC1768 MCU. Using this LPC1768 Timer Input Capture Tutorial, you can easily calculate the frequencies of incoming signals.

Facebook
Twitter
LinkedIn
Pinterest

Similar Articles & Blogs

Explore similar articles on various electronics and electrical topics – 

Logic AND Function

In 1854, George Boole performed an investigation into the “laws of thought” which were based around a simplified version of the “group” or “set” theory, and from

Learn More >>

Binary Coded Decimal

As we have seen in this Binary Numbers section of tutorials, there are many different binary codes used in digital and electronic circuits, each with

Learn More >>

Binary Fractions

We know that decimal (or denary) numbers use the base ten (base-10) numbering system where each digit in a decimal number is allowed to take one

Learn More >>

Octal Number System

The Octal Numbering System is very similar in principle to the previous hexadecimal numbering system except that in Octal, a binary number is divided up into groups

Learn More >>