29.01.2015 Views

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

General-purpose timer (TIMx)<br />

RM0008<br />

Figure 141. Gating timer 2 with Enable of timer 1<br />

CK_INT<br />

TIMER1-CEN=CNT_EN<br />

TIMER1-CNT_INIT<br />

TIMER1-CNT<br />

75 00 01<br />

02<br />

TIMER2-CNT<br />

AB 00 E7 E8 E9<br />

TIMER2-CNT_INIT<br />

TIMER2<br />

write CNT<br />

TIMER 2-TIF<br />

Write TIF=0<br />

Using one timer to start another timer<br />

In this example, we set the enable of Timer 2 with the update event of Timer 1. Refer to<br />

Figure 139 for connections. Timer 2 starts counting from its current value (which can be<br />

non-zero) on the divided internal clock as soon as the update event is generated by Timer 1.<br />

When Timer 2 receives the trigger signal its CEN bit is automatically set <strong>and</strong> the counter<br />

counts until we write ‘0’ to the CEN bit in the TIM2_CR1 register. Both counter clock<br />

frequencies are divided by 3 by the prescaler compared to CK_INT (f CK_CNT = f CK_INT /3).<br />

● Configure Timer 1 master mode to send its Update Event (UEV) as trigger output<br />

(MMS=010 in the TIM1_CR2 register).<br />

● Configure the Timer 1 period (TIM1_ARR registers).<br />

● Configure Timer 2 to get the input trigger from Timer 1 (TS=000 in the TIM2_SMCR<br />

register).<br />

● Configure Timer 2 in trigger mode (SMS=110 in TIM2_SMCR register).<br />

●<br />

Start Timer 1 by writing ‘1’ in the CEN bit (TIM1_CR1 register).<br />

Figure 142. Triggering timer 2 with update of timer 1<br />

CK_INT<br />

TIMER1-UEV<br />

TIMER1-CNT<br />

FD FE FF 00 01<br />

02<br />

TIMER2-CNT<br />

45 46 47 48<br />

TIMER2-CEN=CNT_EN<br />

TIMER 2-TIF<br />

Write TIF=0<br />

352/995 Doc ID 13902 Rev 9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!