09.12.2012 Views

RM0090: Reference manual - STMicroelectronics

RM0090: Reference manual - STMicroelectronics

RM0090: Reference manual - STMicroelectronics

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 timers (TIM2 to TIM5) <strong>RM0090</strong><br />

timers. Timer 2 stops when Timer 1 is disabled by writing ‘0 to the CEN bit in the TIM1_CR1<br />

register:<br />

● Configure Timer 1 master mode to send its Output Compare 1 <strong>Reference</strong> (OC1REF)<br />

signal as trigger output (MMS=100 in the TIM1_CR2 register).<br />

● Configure the Timer 1 OC1REF waveform (TIM1_CCMR1 register).<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 gated mode (SMS=101 in TIM2_SMCR register).<br />

● Reset Timer 1 by writing ‘1 in UG bit (TIM1_EGR register).<br />

● Reset Timer 2 by writing ‘1 in UG bit (TIM2_EGR register).<br />

● Initialize Timer 2 to 0xE7 by writing ‘0xE7’ in the timer 2 counter (TIM2_CNTL).<br />

● Enable Timer 2 by writing ‘1 in the CEN bit (TIM2_CR1 register).<br />

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

● Stop Timer 1 by writing ‘0 in the CEN bit (TIM1_CR1 register).<br />

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

CK_INT<br />

TIMER1-CEN=CNT_EN<br />

TIMER1-CNT_INIT<br />

TIMER1-CNT<br />

TIMER2-CNT<br />

TIMER2-CNT_INIT<br />

TIMER2<br />

write CNT<br />

TIMER 2-TIF<br />

75 00 01<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 159 for connections. Timer 2 starts counting from its current value (which can be<br />

nonzero) 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 and 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 (fCK_CNT = fCK_INT/3). ● 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 />

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

451/1416 Doc ID 018909 Rev 3<br />

AB 00 E7 E8 E9<br />

Write TIF=0<br />

02

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

Saved successfully!

Ooh no, something went wrong!