ST AN591 Application note

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

This timer is an 8 bit timer/counter with prescaler. It includes auto-reload PWM, capture and compare capability with one input and one output pins. It can be controlled by the following registers (8 bit):

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

PS2

 

PS1

PS0

Prescaler ratio

Reg. SC1

 

 

 

 

 

 

 

 

 

 

 

 

 

0

 

0

 

0

0

1

 

 

 

 

 

 

 

0

 

0

 

0

1

2

 

 

 

 

 

 

 

0

 

0

 

1

0

4

 

 

 

 

 

 

 

0

 

0

 

1

1

8

 

 

 

 

 

 

 

0

 

1

 

0

0

16

 

 

 

 

 

 

 

0

 

1

 

0

1

32

 

 

 

 

 

 

 

0

 

1

 

1

0

64

 

 

 

 

 

 

 

0

 

1

 

1

1

128

 

 

 

 

 

 

 

1

 

0

 

0

0

3

 

 

 

 

 

 

 

1

 

0

 

0

1

6

 

 

 

 

 

 

 

1

 

0

 

1

0

12

 

 

 

 

 

 

 

2/5

Loading...
+ 3 hidden pages