GD32A50x User Manual
429
The channel input capture function can be also used for pulse width measurement from
signals on the TIMERx_CHx pins. For example, PWM signal connects to CI0 input. Select
CI0
as channel 0 capture signals by setting CH0MS to 2’b01 in the channel control register
(TIMERx_CHCTL0) and set capture on rising edge. Select CI0 as channel 1 capture signal
by setting CH1MS to 2’b10 in the channel control register (TIMERx_CHCTL0) and set capture
on falling edge. The counter is set to restart mode and is restarted on channel 0 rising edge.
Then the TIMERX_CH0CV can measure the PWM period and the TIMERx_CH1CV can
measure the PWM duty cycle.
Channel output compare function
Figure 18-51. Channel output compare principle (x=0,1,2,3)
Capture/
compare register
CHxCV
Counter
o
u
tp
u
t
co
m
p
a
ra
to
r
Compare output
control
CHxCOMCTL
Output enable
and polarity
selector
CHxP,CHxEN
OxCPRE
CHx_O
CNT>CHxCV
CNT=CHxCV
CNT<CHxCV
Figure 18-51. Channel output compare principle (x=0,1,2,3)
shows the principle circuit of
channels output compare function. The relationship between the channel output signal
CHx_O and the OxCPRE signal (more details refer to
) is
described as blew: The active level of O0CPRE is high, the output level of CH0_O depends
on OxCPRE signal, CHxP bit and CH0P bit (please refer to the TIMERx_CHCTL2 register for
more details).For example,
configure CHxP=0 (the active level of CHx_O is high, the same
as OxCPRE), CHxEN=1 (the output of CHx_O is enabled),
If the output of OxCPRE is active(high) level, the output of CHx_O is active(high) level;
If the output of OxCPRE is inactive(low) level, the output of CHx_O is active(low) level.
In channel output compare function, the TIMERx can generate timed pulses with
programmable position, polarity, duration and frequency. When the counter matches the
value in the TIMERx_CHxCV register of an output compare channel, the channel (n) output
can be set, cleared, or toggled based on CHxCOMCTL. When the counter reaches the value
in the TIMERx_CHxCV register, the CHxIF bit will be set and the channel (n) interrupt is
generated if CHxIE = 1. And the DMA request will be asserted, if CHxDEN=1.
So, the process can be divided into several steps as below:
Step1:
Clock configuration. Such as clock source, clock prescaler and so on.
Step2:
Compare mode configuration.
Set the shadow enable mode by CHxCOMSEN.
Set the output mode (set/clear/toggle) by CHxCOMCTL.
Select the active polarity by CHxP.
Enable the output by CHxEN.