AT32F421
Series Reference Manual
2022.11.11
Page 185
Rev 2.02
Figure 14-22 Input/output channel 1 main circuit
Capture
CNT counter
C1DT
Compare
C1DT
preload
0
1
C1OBEN
C1DT_shadow
C1OCTRL
Overflow event
C1ORAW
C1EN
1
0
disable
filter
Capture trigger
C1P
polarity select
to GPIO
C1OUT
C1P/C1CP
edge detector
C1IN
C1DF
C1IFP1
C2IFP1
STCI
C1C
C1IDIV
input divider
C1EN
C1IRAW
TMRx_CH1
XOR
TMRx_CH2
TMRx_CH3
C1INSEL
Figure 14-23 Channel 1 input stage
Capture
CNT counter
C1DT
C1P/C1CP
edge detector
C1IN
C1IFP1
C2IFP1
STCI
C1C
C1IDIV
input divider
C1IPS
C1IF
XOR
TMRx_CH2
TMRx_CH3
TMRx_CH1
C1INSEL
C1IRAW
filter
C1DF
C1SWTR
C1EN
C2IF
C2IRAW
C2P/C2CP
edge detector
filter
C2DF
IS2
IS1
IS0
C1INC
IS3
STIS
OR
Input mode
In input mode, the TMRx_CxDT register latch the current counter values after the selected trigger signal
is detected, and the capture compare interrupt flag bit (CxIF) is set to 1. An interrupt or a DMA request
will be generated if the CxIEN and CxDEN bits are enabled. If the trigger signal is detected when the
CxIF is set to 1, a capture overflow event occurs. The TMRx_CxDT register overwrites the recorded
value with the current counter value, and the CxRF is set to 1.
To capture the rising edge of C1IN input, following the procedure below:
Set C1C=01 in the TMR3_CM1 register to select the C1IN as channel 1 input
Set the filter bandwidth of C1IN signal (CxDF[3: 0])
Set the active edge on the C1IN channel by writing C1P=0 (rising edge) in the TMR3_CCTRL
register
Program the capture frequency division of C1IN signal (C1DIV[1: 0])
Enable channel 1 input capture (C1EN=1)
If needed, enable the relevant interrupt or DMA request by setting the C1IEN bit in the
TMR3_IDEN register or the C1DEN bit in the TMR3_IDEN register
Timer Input XOR function
The 3 timer input pins (TMR3_CH1, TMR3_CH2 and TMR3_CH3) are connected to the channel 1
(selected by setting the C1INSE in the TMR3_CTRL2 register) through an XOR gate.
The XOR gate can be used to connect Hall sensors. For instance, connect the three XOR inputs to the
three Hall sensors respectively so as to calculate the position and speed of the rotation by analyzing
three Hall sensor signals.
PWM input
The PWM input mode applies to channel 1 and channel 2. To enable this mode, map the C1IN and C2IN
to the same TMRx_CHx, and configure the CxIFPx of channel 1/2 to trigger slave timer controller reset.
The PWM input mode can be used to measure the period and duty cycle of input signal. The period and
duty cycle of channel 1 can be measured as follows: