ST AN591 Application note

AN591
Application note
Input capture with ST62 auto-reload timer
Introduction
This note presents how to use the Auto-reload timer (ARTimer) of the ST62 to measure durations or frequencies of an input signal.
Auto-reload timer description
Mode Control Register (MC)
Status registers (SC0, SC1)
Load register (LR)
Incremental counter register (TC)
Compare register (CP)
Reload/Capture register (RC)
It can also wake-up the MCU from wait mode and exit from stop mode if an external event is present on the input pin. The prescaler ratio can be programmed to choose the timer input frequency FIN (see Table 1).
Figure 1. Auto-reload timer block diagram
July 2008 Rev 2 1/5
www.st.com
Input capture with ST62 auto-reload timer AN591
Capture mode with reset
This can be used to measure time durations or frequencies.This mode is used to measure the time elapsed between two edges of an external signal: two rising edges, two falling edges, or one rising and one falling if the configuration of the timer is modified after the first edge detected.
The minimum duration of one signal to measure depends on the CPU clock and on the required precision. With a 8MHz Quartz crystal, a signal of 8ms duration can be measured with a resolution of 1/64.
Example:
Let’s measure the time elapsed between two rising edges on TIMIN:
The prescaler ratio must be programmed according to the expected duration to measure. In this example it is programmed to: prescaler ratio = 4, clock source = CPU clock. (in case the duration expected can be longer than the 255 count span of the TC count register, the overflow interrupt can be used to increment a RAM variable, used as the most significant part of the result).
In the program example, waiting for the edge on TIMIN is made by a software loop (jrr 2, SC0, wt_edge), but it is also possible to use the external event interrupt to read the result immediately after the edge without loading the rest of the program. It is also possible to read the result directly from RC without waiting or using the interrupt, if the duration is required at an asynchronous time, not just after the edge.
Table 1. Prescaler programming ratio
Bit 0
Reg. SC1
00001
00012
00104
00118
010016
010132
011064
0111128
10003
10016
101012
PS2 PS1 PS0 Prescaler ratio
2/5
Loading...
+ 3 hidden pages