Functionality And Implementation; Input Capture Mode; Compare Output Modes - WCH CH32V003 Series Reference Manual

Table of Contents

Advertisement

CH32V003 Reference Manual

10.3 Functionality and Implementation

The implementation of the complex functions of the advanced-control timer are all achieved by the operation
of the timer's compare capture channel, clock input circuit and counter and peripheral parts. The clock input
to the timer can come from multiple clock sources, including the input to the compare capture channel. The
operation of the compare capture channel and clock source selection directly determines its function. The
compare capture channel is bidirectional and can operate in both input and output modes.

10.3.1 Input capture mode

The input capture mode is one of the basic functions of the timer. The principle of input capture mode is that
a capture event occurs when a determined edge on the ICxPS signal is detected, and the current value of the
counter is latched into the compare capture register (R16_TIMx_CHCTLRx). When a capture event occurs,
CCxIF (in R16_TIMx_INTFR) is set, and if an interrupt or DMA is enabled, the corresponding interrupt or
DMA is also generated. if CCxIF is already set when a capture event occurs, the CCxOF bit is set. CCxIF can
be cleared by software, or by hardware by reading the compare capture register. CCxOF is cleared by software.
An example of channel 1 to illustrate the steps to use the input capture mode is as follows.
1)
Configure the CCxS domain to select the source of the ICx signal. For example, set to 10b and select
TI1FP1 as the source of IC1 instead of using the default setting, where the CCxS domain defaults to
making the comparison capture module the output channel.
2)
Configure the ICxF domain to set the digital filter for the TI signal. The digital filter will sample the
signal at a determined frequency, a determined number of times, and then output a hop. This sampling
frequency and number of times is determined by ICxF.
3)
Configure the CCxP bit to set the polarity of the TIxFPx. For example, keeping the CC1P bit low and
selecting rising edge jumps.
4)
Configure the ICxPS domain to set the ICx signal to be the crossover factor between ICxPS. For example,
keeping ICxPS at 00b, without crossover.
5)
Configure the CCxE bit to allow capturing the value of the core counter (CNT) into the compare capture
register. Set the CC1E bit.
6)
Configure the CCxIE and CCxDE bits as needed to determine whether to allow enable interrupts or DMA.
This completes the comparison capture channel configuration.
When a captured pulse is input to TI1, the value of the core counter (CNT) is recorded in the compare capture
register, CC1IF is set, and the CCIOF bit is set when CC1IF has been set before. If the CC1IE bit is set, then
an interrupt is generated; if CC1DE is set, a DMA request is generated. An input capture event can be generated
by software by writing the event generation register (TIMx_SWEVGR).

10.3.2 Compare output modes

The compare output mode is one of the basic functions of the timer. The principle of the compare output mode
is to output a specific change or waveform when the value of the core counter (CNT) agrees with the value of
the compare capture register. the OCxM field (in R16_TIMx_CHCTLRx) and the CCxP bit (in
R16_TIMx_CCER) determine whether the output is a definite high or low level or a level flip. The CCxIF bit
is also set when a compare coherent event is generated. If the CCxIE bit is pre-set, an interrupt will be
generated; if the CCxDE bit is pre-set, a DMA request will be generated.
To configure to compare output modes, proceed as follows.
1)
Configuring the clock source and auto-reload value of the core counter (CNT).
2)
Setting the count value to be compared to the comparison capture register (R16_TIMx_CHxCVR).
3)
If an interrupt needs to be generated, set the CCxIE bit.
4)
Keeping OCxPE at 0 to disable the preload register of the compare register.
5)
Setting the output mode, setting the OCxM field and the CCxP bit.
6)
Enable the output, setting the CCxE bit.
7)
Set the CEN bit to start the timer.
V1.3
91
http://wch.cn

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents