IMPORTANT NOTE: I have mentioned this already in the previous tutorials but I will repeat it in every LPC1768 Tutorial. Download both the Datasheet and User Manual for LPC1768 MCU from the official NXP website. I cannot explain / discuss each and every topic in detail. You have to look up for the topic of discussion in those documents and gather additional information.

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. When 01, CAPx.1 pin for Timerx. 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. Comment * Name * Email * Website

Δ

LPC1768 Input Capture   How to use Timer Input Capture in LPC1768  - 61LPC1768 Input Capture   How to use Timer Input Capture in LPC1768  - 76LPC1768 Input Capture   How to use Timer Input Capture in LPC1768  - 53LPC1768 Input Capture   How to use Timer Input Capture in LPC1768  - 3LPC1768 Input Capture   How to use Timer Input Capture in LPC1768  - 20LPC1768 Input Capture   How to use Timer Input Capture in LPC1768  - 87