GD32VF103 User Manual
249
We configure TIMER2 as a prescaler for TIMER0. Refer to
Master/Slave mode timer example
for connections. Do as follow:
1. Configure TIMER2 in master mode and select its update event (UPE) as trigger output
(MMC=3’b010 in the TIMER2_CTL1 register). Then TIMER2 drives a periodic signal on
each counter overflow.
2. Configure the TIMER2 period (TIMER2_CAR registers).
3. Select the TIMER0 input trigger source from TIMER2 (TRGS
=3’b010 in the
TIMERx_SMCFG register).
4. Configure TIMER0 in external clock mode 0
(SMC=3’b111 in TIMER0_SMCFG register).
5. Start TIMER0
by writing ‘1 in the CEN bit (TIMER0_CTL0 register).
6. Start TIMER
2 by writing ‘1 in the CEN bit (TIMER2_CTL0 register).
Start TIMER0 with TIMER2’s Enable/Update signal
First, we enable TIMER0 with the enable out of TIMER2. Refer to
TIMER0 with enable signal of TIMER2
. TIMER0 starts counting from its current value on
the divided internal clock after trigger by TIMER2 enable output.
When Timer0 receives the trigger signal, its CEN bit is automatically set and the counter
counts until we disable TIMER0. Both counter clock frequencies are divided by 3 by the
prescaler compared to TIMER_CK (f
CNT_CLK
= f
TIMER_CK
/3). Do as follow:
1. Configure TIMER2
master mode to send its enable signal as trigger output(MMC=3’b001
in the TIMER2_CTL1 register)
2. Configure Timer0 to select the input trigger from TIMER2 (TRGS
=3’b010 in the
TIMERx_SMCFG register).
3.
Configure Timer0 in event mode (SMC=3’b 110 in TIMERx_SMCFG register).
4. Start TIMER2 by writing 1 in the CEN bit (TIMER2_CTL0 register).
Figure 15-29. Triggering TIMER0 with enable signal of TIMER2
TIMER_CK
TIMER2_CNT_REG
TIMER0_CNT_REG
TIMER2_CEN
61
62
63
11
12
13
TIMER0_TRGIF
14
In this example, we also can use update event as trigger source instead of enable signal.
Refer to
Figure 15-30. Triggering TIMER0 with update signal of TIMER2
. Do as follow:
1. Configure TIMER2 in master mode and send its update event (UPE) as trigger output
(MMC=
3’b010 in the TIMER2_CTL1 register).