General-purpose timers (TIM2/TIM3/TIM4/TIM5)
In the example in
started. So they start counting from their current value. It is possible to start from a given
value by resetting both timers before starting TIM3. Then 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.
In the next example (refer to
master and starts from 0. TIM2 is the slave and starts from 0xE7. The prescaler ratio is the
same for both timers. TIM2 stops when TIM3 is disabled by writing '0 to the CEN bit in the
TIM3_CR1 register:
1.
Configure TIM3 master mode to send its Output Compare 1 Reference (OC1REF)
signal as trigger output (MMS=100 in the TIM3_CR2 register).
2.
Configure the TIM3 OC1REF waveform (TIM3_CCMR1 register).
3.
Configure TIM2 to get the input trigger from TIM3 (TS=010 in the TIM2_SMCR
register).
4.
Configure TIM2 in gated mode (SMS=101 in TIM2_SMCR register).
5.
Reset TIM3 by writing '1 in UG bit (TIM3_EGR register).
6.
Reset TIM2 by writing '1 in UG bit (TIM2_EGR register).
7.
Initialize TIM2 to 0xE7 by writing '0xE7' in the TIM2 counter (TIM2_CNTL).
8.
Enable TIM2 by writing '1 in the CEN bit (TIM2_CR1 register).
9.
Start TIM3 by writing '1 in the CEN bit (TIM3_CR1 register).
10. Stop TIM3 by writing '0 in the CEN bit (TIM3_CR1 register).
TIM3-CEN=CNT_EN
TIM3-CNT_INIT
TIM2-CNT_INIT
TIM2-write CNT
Using one timer to start another timer
In this example, we set the enable of Timer 2 with the update event of Timer 3. Refer to
Figure 387
non-zero) on the divided internal clock as soon as the update event is generated by Timer 1.
When Timer 2 receives the trigger signal its CEN bit is automatically set and the counter
counts until we write '0 to the CEN bit in the TIM2_CR1 register. Both counter clock
frequencies are divided by 3 by the prescaler compared to CK_INT (f
1344/2301
Figure
388, the TIM2 counter and prescaler are not initialized before being
Figure
Figure 389. Gating TIM2 with Enable of TIM3
CK_INT
TIM3-CNT
75
TIM2-CNT
AB
TIM2-TIF
for connections. Timer 2 starts counting from its current value (which can be
RM0432 Rev 6
389), we synchronize TIM3 and TIM2. TIM3 is the
00
00
E7
Write TIF = 0
01
02
E8
E9
= f
CK_CNT
CK_INT
RM0432
MS33120V1
/3).
Need help?
Do you have a question about the STM32L4+ Series and is the answer not in the manual?