Connecting an incremental encoder to an ATmega8 microcontroller

A typical diagram of connecting an encoder to an ATmega8 microcontroller is shown in Figure 1. In the diagram, clock pins A and B are pulled up with resistors R1 and R2 to the power supply and give a low signal when triggered.

Figure 1 - Typical diagram for connecting an encoder to an ATmega8 microcontroller

Figure 1 – Typical diagram for connecting an encoder to an ATmega8 microcontroller

Among the disadvantages of this connection is the presence of “contact bounce”.

To suppress the “bounce” in the circuit, an RC circuit is used (Figure 2).

Figure 2 - Scheme of connecting the encoder to the microcontroller ATmega8

Figure 2 – Scheme of connecting the encoder to the microcontroller ATmega8

Let’s calculate the value of the capacitor and resistors for the circuit shown in Figure 2.

To calculate the value of the capacitor and resistors, the circuit uses the law of voltage change when the capacitor of the RC circuit is discharged (1):

Hence the time during which the voltage reaches a logical maximum:

Calculation example

To calculate the value of the capacitor and resistors, formula (4) is also used, which allows you to determine the time constant of the RC circuit:

Calculation example

The actual EC11E encoder chatter waveform is shown in fig. 3.

Figure 3 - Real oscillogram of the

Figure 3 – Real oscillogram of the “bounce” encoder EC11E

From Figure 1, we can see that the actual “bounce” time (approximately 0.16 ms) differs significantly from the maximum value (2 ms) given in the datasheet for the EC11E encoder.

It follows from this that a 10 nF capacitor should be enough to eliminate the “bounce”.

But, during the operation of the end device, as a result of the “drawdown” of the encoder contacts as a result of intensive mechanical movements, this rating will not be enough.

Accordingly, a capacitor with a nominal value of 100 nF will be quite enough.

To improve the positioning accuracy, Schmitt triggers are used in hardware debouncing circuits (Figure 4, 5).

Figure 4 - Scheme of connecting the encoder to the microcontroller ATmega8

Figure 4 – Scheme of connecting the encoder to the microcontroller ATmega8

Figure 5 - Scheme of connecting the encoder to the microcontroller ATmega8

Figure 5 – Scheme of connecting the encoder to the microcontroller ATmega8

In Figure 5, the two rightmost flip-flops are used to reverse the signal.

The inverting Schmitt trigger SN74HC14N can be replaced with domestic counterparts.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *