WCH CH32V003 Series Reference Manual page 117

Table of Contents

Advertisement

CH32V003 Reference Manual
forces OCxREF to high.
Note that by forcing OCxM to 100b or 101b, the comparison process between the internal main counter and
the compare capture register is still going on, the corresponding flags are still set, and interrupts and DMA
requests are still being generated.
11.3.4 PWM input mode
The PWM input mode is used to measure the duty cycle and frequency of PWM and is a special case of the
input capture mode. The operation is the same as input capture mode except for the following differences:
PWM occupies two compare capture channels and the input polarity of the two channels is set to opposite, one
of the signals is set as trigger input and SMS is set to reset mode.
For example, to measure the period and frequency of the PWM wave input from TI1, the following operations
are required.
1)
Set TI1 (TI1FP1) to be the input of IC1 signal. Set CC1S to 01b.
2)
Set TI1FP1 to rising edge active. Holding CC1P at 0.
3)
Set TI1 (TI1FP2) as the input of IC2 signal. Set CC2S to 10b.
4)
Select TI1FP2 to set to falling edge active. Set CC2P to 1.
5)
Select TI1FP1 as the source of the clock source. set TS to 101b.
6)
Set the SMS to reset mode, i.e. 100b.
7)
Enables input capture. cc1e and cc2e are set.
11.3.5 PWM input mode
PWM output mode is one of the basic functions of the timer. PWM output mode is most commonly used to
determine the PWM frequency using the reload value and the duty cycle using the capture comparison register.
Set 110b or 111b in the OCxM field to use PWM mode 1 or mode 2, set the OCxPE bit to enable the preload
register, and finally set the ARPE bit to enable the automatic reload of the preload register. The value of the
preload register can only be sent to the shadow register when an update event occurs, so the UG bit needs to
be set to initialize all registers before the core counter starts counting. In PWM mode, the core counter and the
compare capture register are always comparing, and depending on the CMS bit, the timer is able to output
edge-aligned or center-aligned PWM signals.
l
Edge alignment
When using edge alignment, the core counter is incremented or decremented, and in the PWM mode 1 scenario,
OCxREF rises to high when the core counter value is greater than the compare capture register; when the core
counter value is less than the compare captureregister (for example, when the core counter grows to the value
of R16_TIMx_ATRLR and reverts to full 0), OCxREF falls to low.
l
Central alignment
When using the central alignment modes, the core counter runs in alternating incremental and decremental
count modes, and OCxREF performs rising and falling jumps when the values of the core counter and the
compare capture register match. However, the comparison flags are set at different times in the three central
alignment modes. When using the central alignment modes, it is best to generate a software update flag (set
the UG bit) before starting the core counter.
11.3.6 Single pulse mode
The single pulse mode can respond to a specific event by generating a pulse after a delay, with programmable
delay and pulse width. Setting the OPM bit stops the core counter when the next update event UEV is generated
(counter flips to 0).
V1.3
117
http://wch.cn

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents

Save PDF