![ARTERY AT32F435 Series Скачать руководство пользователя страница 258](http://html1.mh-extra.com/html/artery/at32f435-series/at32f435-series_reference-manual_2977592258.webp)
AT32F435/437
Series Reference Manual
2022.11.11
Page 258
Rev 2.03
Figure 14-169 Counter timing diagram with internal clock divided by 1 and TMRx_PR=0x32
0
1
2
3
...
31
32
31
30
2F
2E
...
2
1
0
1
2
3
COUNTER
31
32
31
30
...
PR[15:0]
OVFIF
TMR_CLK
0
DIV[15:0]
32
Clear
Clear
Clear
11
TWCMSEL
[1
:
0]
OWCDIR
Encoder interface mode
To enable the encoder interface mode, write SMSEL[2: 0]= 3’b001/3’b010/3’b011. In this mode, the two
inputs (C1IN/C2IN) are required. Depending on the level on one input, the counter counts up or down
on the edge of the other input. The OWCDIR bit indicates the direction of the counter.
Figure 14-2 Encoder mode structure
encoder mode
C2P
C2IFP2
C1DF
TMRx_CH3
XOR
TMRx_CH1
TMRx_CH2
C2IRAW
C2DF
C1P
C1IFP1
CNT
director
SMSEL=3'b001/010/011
C1INSEL
C1IRAW
filter
filter
polarity select
polarity select
edge
detector
OR
encoder
mode A
encoder
mode B
encoder
mode C
SMSEL
001
010
011
DIV_CLK
TMRx_DIV
CNT
counter
DIV counter
preload
Overflow event
pos/neg edge
Encoder mode A:
SMSEL=3’b001. The counter counts on the selected C1IFP1 edge (rising and falling
edges), and the counting direction is dependent on the edge direction of C1IFP1 and the level of C2IFP2.
Encoder mode B:
SMSEL=3’b010. The counter counts on the selected C2IFP2 edge (rising and falling
edges), and the counting direction is dependent on the edge direction of C2IFP2 and the level of C1IFP1.
Encoder mode C:
SMSEL=3’b011. The counter counts on both C1IFP1 and C2IFP2 edges (rising and
falling edges). The counting direction is dependent on the C1IFP1 edge direction and C2IFP2 level, and
C2IFP2 edge direction and C1IFP1 level.
To use encoder mode, follow the procedures below:
−
Set channel 1 input signal filtering through the C1DF[3:0] bit in the TMRx_CM1 register;
Set channel 1 input signal active level through the C1P bit in the TMRx_CCTRL register
−
Set channel 2 input signal filtering through the C2DF[3:0] bit in the TMRx_CM1 register;
Set channel 2 input signal active level through the C2P bit in the TMRx_CCTRL register
−
Set channel 1 as input mode through the C1C[1:0] bit in the TMRx_CM1 register;
Set channel 2 as input mode through the C2C[1:0] bit in the TMRx_CM1 register
−
Select encoder mode A (SMSEL=3’b001), encoder mode B (SMSEL=3’b010), or encoder mode
C (SMSEL=3’b011) by setting the SMSEL[2:0] bit in the TMRx_STCTRL register
−
Set counting cycles through the PR[15:0] bit in the TMRx_PR register
−
Set counting frequency through the DIV[15:0] bit in the TMRx_DIV register
−
Configure the corresponding IOs of TMRx_CH1 and TMRx_CH2 as multiplexed mode