Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
84
Добавлен:
01.03.2016
Размер:
3.56 Mб
Скачать

16-bit advanced control timer (TIM1)

RM0016

 

 

17.4.2Internal clock source (fMASTER)

If both the clock/trigger mode controller and the external trigger input are disabled

(SMS = 000 in TIM1_SMCR and ECE = 0 in the TIM1_ETR register), the CEN, DIR, and UG bits behave as control bits and can be changed only by software (except UG which remains cleared automatically). As soon as the CEN bit is written to 1, the prescaler is clocked by the internal clock.

The figure below shows the behavior of the control circuit and the up-counter in normal mode, without the prescaler.

Figure 44. Control circuit in normal mode, fCK_PSC = fMASTER

fMASTER

CEN = CNT_EN

UG

CNT_INIT (=UG synchronized: UG or UG+1 clock)

COUNTER CLOCK = CK_CNT = CK_PSC

COUNTER REGISTER

31

32 33

34 35 36

00 01 02 03 04

05 06 07

17.4.3External clock source mode 1

The counter can count at each rising or falling edge on a selected timer input. This mode is selected when SMS = 111 in the TIM1_SMCR register (see Figure 45).

Figure 45. TI2 external clock connection example

 

 

 

 

 

 

 

 

 

TIM1_SMCR

 

 

 

 

 

 

 

 

 

TS[2:0]

 

 

 

 

 

 

 

 

 

 

orTI2F

or

 

 

 

 

 

 

 

TRGO from other timers

TI1F

or

 

Encoder

 

 

 

 

 

 

 

 

 

mode

 

 

 

 

 

 

TI1F_ED

100

 

 

External clock

 

 

 

 

TI1FP1

TRGI

 

 

 

 

 

ti2f_rising 0

101

 

 

mode 1

CK_PSC

 

 

 

TI2FP2

 

 

TI2

Filter

Edge

110

 

 

 

 

 

 

Detector

ti2f_falling

 

 

 

External clock

 

 

ETRF

ETRF

 

 

 

 

 

1

111

 

 

mode 2

 

 

 

 

 

 

 

 

 

 

ICF[3:0]

 

CC2P

 

fMASTER

 

 

Internal clock

 

TIM1_CCMR2

 

TIM1_CCER1

(internal clock)

mode

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ECE

SMS[2:0]

 

 

 

 

 

 

 

TIM1_ETR

 

TIM1_SMCR

150/454

Doc ID 14587 Rev 9

RM0016

16-bit advanced control timer (TIM1)

 

 

Procedure

Use the following procedure to configure the up-counter and, for example, to count in response to a rising edge on the TI2 input:

1.Configure channel 2 to detect rising edges on the TI2 input by writing CC2S = 01 in the TIM1_CCMR2 register.

2.Configure the input filter duration by writing the IC2F[3:0] bits in the TIM1_CCMR2 register (if no filter is needed, keep IC2F = 0000).

Note: The capture prescaler is not used for triggering, so it does not need t o be configured. The CC2S bits do not need to be configured either as they only select the input capture source.

3.Select rising edge polarity by writing CC2P = 0 in the TIM1_CCER1 register.

4.Configure the timer in external clock mode 1 by writing SMS = 111 in the TIM1_SMCR register.

5.Select TI2 as the input source by writing TS = 110 in the TIM1_SMCR register.

6.Enable the counter by writing CEN = 1 in the TIM1_CR1 register.

When a rising edge occurs on TI2, the counter counts once and the trigger flag is set (TIF bit in the TIM1_SR1 register) and an interrupt request can be sent if enabled (depending on the TIE bit in the TIM1_IER register).

The delay between the rising edge on TI2 and the actual reset of the counter is due to the resynchronization circuit on TI2 input.

Figure 46. Control circuit in external clock mode 1

 

 

TI2

 

 

 

CNT_EN

 

 

 

COUNTER CLOCK = CK_CNT = CK_PSC

 

 

 

COUNTER REGISTER

34

35

36

TIF

 

 

 

 

Write TIF=0

 

 

Doc ID 14587 Rev 9

151/454

Соседние файлы в папке Минимум документации STM8