AT32F421
Series Reference Manual
2022.11.11
Page 219
Rev 2.02
Figure 14-61 Channel 1 input stage
Capture
CNT counter
C1DT
C1P/C1CP
edge detector
C1IF
C1IN
C1IFP1
C2IFP1
STCI
C1C
C1IDIV
input divider
C1IPS
TMRx_CH1
filter
C1DF
C1SWTR
C1EN
OR
C2P/C2CP
edge detector
C2IF
TMRx_CH2
filter
C2DF
IS2
IS1
IS0
C1INC
IS3
STIS
Input mode
In input mode, the TMRx_CxDT registers 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/DMA request will
be generated if the CxIEN bit and CxDEN bit are enabled. If the selected trigger signal is detected when
the CxIF is set, 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 configuration procedure mentioned below:
Set C1C=01 in the TMR15_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 TMR15_CCTR
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 TMR15_IDEN
register or the C1DEN bit in the TMR15_IDEN register
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:
Set C
1C=2‘b01 to set C1IN as C1IFP1;
Set C
1P=1’b0 to set C1IFP1 rising edge active;
Set C
2C=2‘b10 to set C2IN as C1IFP2;
Set C
2P=1’b1 to set C1IFP2 falling edge active;
Set
STIS=3’b101 to set C1IFP1 as the slave timer trigger signal;
Set S
MSEL=3‘b110 to set the slave timer in reset mode;
Set C
1EN=1’b1 and C2EN=1’b1 to enable channel 1 and input capture.
In these configurations, the rising edge of channel 1 input signal triggers capture and saves captured
values to the C1DT register, and channel 1 input signal rising edge resets the counter. The falling edge
of channel 1 input signal triggers capture and saves captured values to the C2DT register. The period
and duty of channel 1 input signal can be calculated through C1DT and C2DT respectively.