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

RM0016

16-bit advanced control timer (TIM1)

 

 

17.4.6Synchronization between TIM1, TIM5 and TIM6 timers

On some products, the timers are linked together internally for timer synchronization or chaining. When one timer is configured in master mode, it can output a trigger (TRGO) to reset, start, stop, or clock the counter of any other timer configured in slave mode.

Figure 53. Timer chaining system implementation example

 

 

 

TIM 1

 

 

 

TRGO from TIM6

ITR0

 

 

 

 

TRGO from TIM5

ITR2

 

 

 

 

 

 

 

 

 

 

 

Trigger

TRGO

TIM 5

 

 

 

Controller

 

 

 

 

 

 

TRGO from TIM6

ITR0

 

 

 

 

TRGO from TIM1

ITR3

 

TIM1_CH1

TI1

 

 

Trigger

TRGO

TI2

 

 

TIM1_CH2

 

 

 

 

 

Controller

 

 

 

 

 

 

 

TIM 6

TIM5_CH1

TI1

 

 

 

 

 

 

 

 

TI2

 

 

 

 

TIM5_CH2

 

 

 

 

 

 

TRGO from TIM5

ITR2

Trigger

TRGO

 

 

Controller

 

 

 

TRGO from TIM1

ITR3

 

 

 

 

Doc ID 14587 Rev 9

157/454

16-bit advanced control timer (TIM1)

RM0016

 

 

Figure 54 presents an overview of the trigger selection and the master mode selection blocks.

Figure 54. Trigger/master mode selection blocks

 

 

TRIGGER SELECTION BLOCK

 

 

 

TIMx_SMCR

 

 

 

TS[2:0]

MASTER MODE SELECTION BLOCK

 

 

 

ITR0

UG

 

TRGO from TIM6

CNT_EN

 

 

UEV

 

 

ITR

 

 

MATCH1

TRGO

 

ITR2

TRGO from TIM5

OC1REF

 

TRC

 

 

 

OC3REF

 

 

TI1F_ED

OC3REF

 

From the Capture/

TRGI

OC4REF

 

TI1FP1

 

 

Compare block

TI2FP2

 

MMS[2:0]

 

 

 

 

 

 

ETRF

 

TIMx_CR2

 

 

 

Using one timer as prescaler for another timer

Refer to Figure 55 to see how timer A can be configured to act as a prescaler for timer B.

1.Configure timer A in master mode so that it outputs a periodic trigger signal on each UEV. To configure that a rising edge is output on TRGO1 each time an update event is generated, write MMS = 010 in the TIMx_CR2 register.

2.Connect the TRGO1 output of timer A to timer B, timer B must be configured in slave mode using ITR1 as the internal trigger. Select this through the TS bits in the TIMx_SMCR register (writing TS = 001).

3.Put the clock/trigger controller in external clock mode 1, by writing SMS = 111 in the TIMx_SMCR register. This causes timer B to be clocked by the rising edge of the periodic timer A trigger signal (which corresponds to the timer A counter overflow).

4.Enable both timers by setting their respective CEN bits (TIMx_CR1 register).

Note:

If OCi is selected on timer A as trigger output (MMS = 1xx), its rising edge is used to clock

 

the counter of timer B.

Figure 55. Master/slave timer example

 

TIMER A

 

 

 

 

TIMER B

 

Clock

 

MMS

 

TS

SMS

 

 

 

 

 

 

 

 

 

UEV

MASTER

TRGO1

ITR1

SLAVE

CK_PSC

 

 

 

MODE

 

 

MODE

 

 

PRESCALER

COUNTER

CONTROL

 

 

CONTROL

PRESCALER

COUNTER

 

 

 

 

 

 

 

 

 

 

INPUT

 

 

 

 

 

 

 

TRIGGER

 

 

 

 

 

 

 

SELECTION

 

 

158/454

Doc ID 14587 Rev 9

RM0016

16-bit advanced control timer (TIM1)

 

 

Using one timer to enable another timer

Example 1

The enable of timer B is controlled with the output compare 1 of timer A (refer to Figure 56 for connections). Timer B counts on the divided internal clock only when OC1REF of timer A is high. Both counter clock frequencies are divided by four by the prescaler compared to

fMASTER (fCK_CNT = fMASTER/4).

1.Configure timer A master mode to send its output compare 1 reference (OC1REF) signal as trigger output (MMS = 100 in the TIMx_CR2 register).

2.Configure the timer A OC1REF waveform (TIMx_CCMR1 register)

3.Configure timer B to get the input trigger from timer A (TS = 001 in the TIMx_SMCR register).

4.Configure timer B in trigger gated mode (SMS = 101 in TIMx_SMCR register)

5.Enable timer B by writing 1 in the CEN bit (TIMx_CR1 register)

6.Start timer A by writing 1 in the CEN bit (TIMx_CR1 register)

Note:

The counter 2 clock is not synchronized with counter 1. This mode only affects the timer B

 

counter enable signal.

Figure 56. Gating timer B with OC1REF of timer A

fMASTER

 

 

 

 

 

 

Timer A-OC1REF

 

 

 

 

 

 

Timer A-CNT

FC

FD

FE

FF

00

01

Timer B-CNT

3045

3046

 

3047

 

3048

Timer B-TIF

 

 

 

 

 

 

Write TIF=0

In Figure 56, the timer B counter and prescaler are not initialized before being started. Therefore, they start counting from their current value. It is possible to start from a given value by resetting both timers before starting timer A. In this case, any value can be written in the timer counters. The timers can easily be reset by software using the UG bit in the TIMx_EGR registers.

Doc ID 14587 Rev 9

159/454

16-bit advanced control timer (TIM1)

RM0016

 

 

Example 2

Timer A and timer B are synchronized. Timer A is the master and starts from 0. Timer B is the slave and starts from E7h. The prescaler ratio is the same for both timers. Timer B stops when timer A is disabled by writing 0 to the CEN bit in the TIMx_CR1 register:

1.Configure timer A master mode to send its output compare 1 reference (OC1REF) signal as trigger output (MMS = 100 in the TIMx_CR2 register).

2.Configure the timer A OC1REF waveform (TIMx_CCMR1 register)

3.Configure timer B to get the input trigger from timer A (TS = 001 in the TIMx_SMCR register).

4.Configure timer B in trigger gated mode (SMS = 101 in TIMx_SMCR register)

5.Reset timer A by writing 1 in UG bit (TIMx_EGR register)

6.Reset timer B by writing 1 in UG bit (TIMx_EGR register)

7.Initialize timer B to 0xE7 by writing ‘E7h’ in the timer B counter (TIMx_CNTRL)

8.Enable timer B by writing 1 in the CEN bit (TIMx_CR1 register)

9.Start timer A by writing 1 in the CEN bit (TIMx_CR1 register)

10.Stop timer A by writing 0 in the CEN bit (TIMx_CR1 register)

Figure 57. Gating timer B with the counter enable signal of timer A (CNT_EN)

fMASTER

Timer A-CEN = CNT_EN

Timer A-UG

Timer A-CNT

Timer B-CNT

Timer B-UG

Timer B write CNT

Timer B-TIF

75

 

00

01

02

AB

00

E7

E8

E9

Write TIF=0

160/454

Doc ID 14587 Rev 9

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