To select Encoder Interface mode write SMS=‘001 in the TIMx_SMCR register if the counter is counting on TI2 edges only, SMS=010 if it is counting on TI1 edges only and SMS=011 if it is counting on both TI1 and TI2 edges.


STM32 - 定时器的设定 - 基础- 09 - 编码接口 - Encoder interface mode

Bits 2:0 SMS: Slave mode selection When external signals are selected the active edge of the trigger signal (TRGI) is linked to

the polarity selected on the external input (see Input Control register and Control Register description.

000: Slave mode disabled - if CEN = ‘1 then the prescaler is clocked directly by the internal clock.

001: Encoder mode 1 - Counter counts up/down on TI2FP1 edge depending on TI1FP2 level.

010: Encoder mode 2 - Counter counts up/down on TI1FP2 edge depending on TI2FP1 level.

011: Encoder mode 3 - Counter counts up/down on both TI1FP1 and TI2FP2 edges depending on the level of the other input.

100: Reset Mode - Rising edge of the selected trigger input (TRGI) reinitializes the counter and generates an update of the registers.

101: Gated Mode - The counter clock is enabled when the trigger input (TRGI) is high. The counter stops (but is not reset) as soon as the trigger becomes low. Both start and stop of the counter are controlled.

110: Trigger Mode - The counter starts at a rising edge of the trigger TRGI (but it is not reset). Only the start of the counter is controlled.

111: External Clock Mode 1 - Rising edges of the selected trigger (TRGI) clock the counter.

Note: The gated mode must not be used if TI1F_ED(TIxF_ED:TIx Edge Detector) is selected as the trigger input (TS=100). Indeed, TI1F_ED outputs 1 pulse for each transition on TI1F, whereas the gated mode checks the level of the trigger signal. The clock of the slave timer must be enabled prior to receiving events from the master timer, and must not be changed on-the-fly while triggers are received from the master timer


Select the TI1 and TI2 polarity by programming the Bit 1 CC1P: Capture/Compare 1 output polarity

STM32 - 定时器的设定 - 基础- 09 - 编码接口 - Encoder interface mode

Bit 1 CC1P: Capture/Compare 1 output polarity 

CC1 channel configured as output:

0: OC1 active high.

1: OC1 active low.

CC1 channel configured as input:

This bit selects whether IC1 or IC1 is used for trigger or capture operations.

0: non-inverted: capture is done on a rising edge of IC1. When used as external trigger, IC1 is non-inverted.

1: inverted: capture is done on a falling edge of IC1. When used as external trigger, IC1 is inverted.

and CC2P bits in the TIMx_CCER register. When needed, program the input filter as well.


The two inputs TI1 and TI2 are used to interface to an incremental (递增)encoder. Refer to Table 85.

STM32 - 定时器的设定 - 基础- 09 - 编码接口 - Encoder interface mode

The table summarizes the possible combinations, assuming TI1 and TI2 don’t switch at the same time. 

The counter is clocked by each valid transition on TI1FP1 or TI2FP2 (TI1 and TI2 after input filter and polarity selection, TI1FP1=TI1 if not filtered and not inverted, TI2FP2=TI2 if not filtered and not inverted) assuming that it is enabled (CEN 计数使能位 bit in TIMx_CR1 register written to ‘1).

The sequence of transitions of the two inputs is evaluated and generates count pulses as well as the direction signal. Depending on the sequence the counter counts up or down, the DIR(计数方向选择位) bit in the TIMx_CR1 register is modified by hardware accordingly. The DIR bit is calculated at each transition on any input (TI1 or TI2), whatever the counter is counting on TI1 only, TI2 only or both TI1 and TI2.

 STM32 - 定时器的设定 - 基础- 09 - 编码接口 - Encoder interface mode

 


编码接口定义

Encoder interface mode acts simply as an external clock with direction selection. This means that the counter just counts continuously between 0 and the auto-reload value in the TIMx_ARR register (0 to ARR or ARR down to 0 depending on the direction). So the user must configure TIMx_ARR before starting. In the same way, the capture, compare, prescaler, trigger output features continue to work as normal.

 编码接口简单理解为带方向选择的外部时钟,也就是计数器在0 和ARR之间连续计数,对于向上或者向下计数由上面说的DIR寄存器决定。这样,我们就可以在开始计数器先配置ARR,其他的捕捉、比较、触发输出的功能都是一样的。


In this mode, the counter is modified automatically following the speed and the direction of the incremental encoder and its content, therefore, always represents the encoder’s position. The count direction correspond to the rotation direction of the connected sensor.

这个模式下,计数器依据速度、计数器方向、内容自动的修改,这样就能总表述为编码的位置。计数的方向则和连接的传感器的计数方向一直。

An external incremental encoder can be connected directly to the MCU without external interface logic. However, comparators are normally be used to convert the encoder’s differential outputs to digital signals. This greatly increases noise immunity. The third encoder output which indicate the mechanical zero position, may be connected to an external interrupt input and trigger a counter reset.

一个外部递增的编码器可以直接连接到MCU,而不需要接口电路。同时,比较器通常用于将编码器的输出转化为数字信号。这可以增加鲁棒性。第三方编码器器数次能够指示机械零点的文字。这样可以连接到外部触发来对计数器进行置位。

 

相关文章:

  • 2022-03-06
  • 2021-11-24
  • 2022-01-30
  • 2021-07-24
  • 2022-12-23
  • 2021-12-12
  • 2021-12-02
猜你喜欢
  • 2021-06-16
  • 2021-09-06
  • 2022-01-10
  • 2021-10-31
  • 2021-11-15
  • 2021-12-09
  • 2021-11-15
相关资源
相似解决方案