RC2024 – Part 1 – The Rotary Encoder

It’s October 2024, and Retro Challenge RC2024/10 has started.

I’m looking at interfacing rotary encoders with the RC2014 computer this year.

What is a rotary encoder?

A rotary encoder is an electronic device that measures rotational movement.

A rotary encoder

The rotary encoder I’m using generates two pulses as it turns. The pulses are on pins CLK (Clock) and DT (Direction of Travel). These pulses are out of phase with each other and this tells us which direction the encoder is turning. The encoder starts with both pins at logic 1. We then look for when CLK transitions to logic 0. At this point we check DT to see if it’s logic 1 or logic 0. This will tell us which way the encoder is being turned.

Let’s look at this on a timing diagram.

Timing diagram for a rotary encoder.

Going from A to B shows us turning the rotary encoder clockwise. We see CLK going from logic 1 to logic 0. We then sample DT and see it is still logic 1, so we know we are turning clockwise.

Going from B to A shows us turning the encoder anticlockwise. We see CLK going from logic 1 to logic 0. We then sample DT and see it is logic 0, so we know we are turning anticlockwise.

You may have noticed my rotary encoder has another pin call SW.

This is a switch triggered by pressing the shaft of the rotary encoder down. It is usually logic 1, but is logic 0 when pressed.

Wiring the rotary encoder to the RC2014

I need a way to be able to read the the CLK, DT, and SW pins.

For prototyping, I am using Stephen Cousins SC129 Digital I/O board for the RC2014. This has 8 input and 8 output pins, as well as LED indicators. I can use this from MS-BASIC on my RC2014 Classic 2.

The output from the rotary encoder could be noisy. Because of this, I am going to use a 74HCT14 Inverting Schmitt Trigger to clean the signals, and also invert them. Inverting the signals means they appear at logic 0 at rest. I will need to look for CLK transitioning to logic 1 when turning.

Wiring up the rotary encoder and turning it, I can see the input LEDs for 1 and 2 flashing. This is showing the logic levels changing from 0 to 1 and back again. I can also see they are out of sync with each other as expected.

My next step will be to read the incoming data from the rotary encoder in software.