General Timers
User Manual All information provided in this document is subject to legal disclaimers. © REALTEK 2019. All rights reserved.
229
10.6.2
Pulse Mode
Pulse mode: support TIM4.
10.6.2.1
Pulse Mode 0 (Pulse Width)
The pulse mode 0 configuration flow is shown in Table 10-9.
Table 10-9 Pulse mode 0 configuration flow
Step What to do
How to do
Comments
1
Disable the timer
Write “0x00” to TIMx_CR
Stop Counter
2
Set prescaler
Configure TIMx_PSC
3
Set ARR
Configure TIMx_ARR
Must great than the width of TRGI
4
Configure pulse mode 0
Configure CCxPM bit in TIMx_CCRx
Configure the pulse polarity of TRGI
(CCxP in TIMx_CCRx)
5
Initialize the counter
Write “0x01” to TIMx_EGR (set UG bit)
Generate UEV by software
6
Clear event flag
Write “0x0F” to TIMx_SR
Clear all flags
7
Enable the timer
Set CEN bit in TIMx_CR
Configure UEV condition at the same time
8
Read the current value of the counter
when CCxIF is asserted
Read TIMx_CCRx
Use interrupt to notify CPU, must enable
CCxIE in TIMx_DIER
9
Clear CCxIF
Write TIMx_SR
The statistic process is repeated unless OPM bit is set in TIMx_CR.
10.6.2.2
Pulse Mode 1 (Pulse Number)
The pulse mode 1 configuration flow is shown in Table 10-10.
Table 10-10 Pulse mode 1 configuration flow
Step What to do
How to do
Comments
1
Disable the timer
Write “0x00” to TIMx_CR
Stop Counter
2
Set prescaler
Configure TIMx_PSC
3
Set ARR
Configure TIMx_ARR
Set the statistic period
4
Configure pulse mode 1
Configure CCxPM bit in TIMx_CCRx
Configure the edge polarity of TRGI (CCxP in
TIMx_CCRx)
5
Initialize the counter
Write “0x01” to TIMx_EGR (set UG bit)
Generate UEV by software
6
Clear event flag
Write “0x0F” to TIMx_SR
Clear all flags
7
Enable the timer
Set CEN bit in TIMx_CR
Configure UEV condition at the same time
8
Read the pulse number when UIF is
asserted
Read TIMx_CCRx
Use interrupt to notify CPU, must enable UIE
in TIMx_DIER
9
Clear UIF
Write TIMx_SR
The statistic process is repeated unless OPM bit is set in TIMx_CR.
10.6.3
PWM Mode
PWM mode: support TIM5.
10.6.3.1
Repeated Mode
The PWM repeated mode configuration flow is illustrated in Table 10-11.
Realtek confidential files
The document authorized to
SZ99iot
2019-05-15 10:08:03