HOME

 

Display with encoder

Taking advantage | Schematic diagram | Breadboarding | Truth table | Testing | More experiments

Taking advantage

This design explains how to use an encoder to set the number shown by a 7-segment display. Turn the knob clockwise to increment the number, turn it counterclockwise to set it back.
Encoders are the most practical (and handy) way to set a large number of digital devices. Think of an alarm clock, would'nt be easier to set the alarm time simply turning a knob, in place of frantically pressing a couple of buttons? By the way, grandma alarm clock works exactly in that way...
Happily, things keep changing and latest clocks revamped the old fashioned way of setting the time - through use of latest technology, though. Car radios, microwave ovens, instrumentation, hi-fi are a few examples of devices that make use of encoders to improve user interface. Therefore, encoders gradually grow from being specialized parts, designed for professional use, to cheap and widespread consumer parts, available to mere mortals.
Time to learn how to take advantage of their availability and convenience!

Schematic diagram

The circuit counts four main parts (Nutchip, encoder, display driver and display), nonetheless should not be difficult to understand.
Its a matter of connecting two Nutchip inputs to the two encoder pins, and all four Nutchip outputs to a 4511 7-segment display driver. We suggest you to read the counter project pages for a detailed description of the 4511 and 7-segment displays. Here we note how all of the display connections are handled by the 4511 itself. The display, a common-cathode part, has been selected because it fits nicely a breadboard, but you can replace it with another brand or model provided it is a common-cathode type. Also, different parts can have different pinouts, therefore require a different board wiring to suit the new layout. To pinpoint all of the pins, try to power the display with a 5V source connected in series with a 390 ohm resistor (for limiting the current). Try powering different pin pairs until the whole pin/segment pattern is discovered. A good puzzling game for a rainy day, if nothing else...

The incremental-type (also known as quadrature-type ) encoder connects directly to a couple of input pins (IN1 and IN2). We can think of an encoder in terms of a pair of switches (namely A and B encoder pins) with one of their pins connected together (COM pin). We connected this common pin to GND; therefore, from Nutchip's perpective, the A and B switches acts like any other pair of common-or-garden switches. The Nutchip reads an "1" on the input when the switch is open, and a "0" when the switch is closed. No other parts are required, as Nutchips include an internal pullup resistor which makes the input positive (a logic "1") whenever the pin is not connected to any other potential.

Turning the encoder knob causes the encoder switches to close/open according to a well-known pattern, changing the logic state of IN1 and IN2 pins on the Nutchip.
Whenever the knob is in a rest position, both the switches A and B are open. The magic happens when moving the encoder from one position to another (positions are determined by the number of detents on the shaft). If the shaft moves clockwise, the switches close according to the following sequence: A, A+B, B, then both open on next detent. In case of counterclockwise operation, the sequence reverses to B, B+A, A, and both open again.
Note that different encoders other than the one from ALPS we used (see photo) can have a slightly twice a number of detents, whith the above sequence stopping also in places with both the switches closed. In this case, the circuit works as well, but it is necessary to step two "clicks" to increment the count by one.

More details about encoders can be found in the encoder lights page; details about displays and the 4511 driver can be found in the counter porject page.

 


Schematic diagram of the encoder-settable display

 

Breadboarding

Because of the relatively high number of connections involved, this project requires extra care in order to avoid mistakes. We assembled our prototype on a solderless breadboard. Ensure you have enough wire jumpers; also, check all connections against the photo as some of the jumpers cross and overlap each other.
The encoder used in this design is manufactured by Alps and provides 3 pins spaced apart 5.08 mm each. It could theoretically fit the breadboard spacing, nonetheless we preferred to build an adapter from an old dual-in-line IC socket and some spare insulated copper wire. We halved the 2.54 mm IC socket, cutting out 5 pins, and soldering a length of wire each other pin. This kind of adapter worked well, see photo below; the green wire is pin A, the white one is pin B, and the common pin refers to black wire.


The circuit assembled on a solderless breadboard.
To connect the encode we built an adapter, soldering the wires to an IC socket.
The encoder pins fit the socket, allowing encoder reuse in future experiments.

Parts list:

7 x 390 ohm resistor
1 x 100 nF capacitor
1 x rotary encoder (ALPS)
1 x 3-pin ceramic resonator, 4 MHz
1 x TFK214 common cathode display
1 x CD4511 display driver
1 x Nutchip (NUT01-AK or NUT01-DEA)

 

State table

The truth table accounts for 30 different rows, so you can think it is quite complicated. But at a closer inspection it can be found that it is basically made repeating the same basic structure over and over. In fact, the basic block counts just three conditions grouped in only 2 states, and it is repeated 10 times. Let's see how it works:

Handling shaft rotation is a two-step process:

In order to make the table more manageable, we numbered the states starting from multiples of #5: 0, 5, 10, 15... etc.
The first shaft position is handled by states 0 and 1; the second position is handled by states 5 and 6, the third by states 10 and 11, and so on.
Those using this project with Nutchip Commander should note that the gaps present in this numbering cause the state number displayed by the Commander to differ from actual one.

The state table if stored in the file "encoder_display.nut".

 

Testing

Despite of the relatively high component count of this circuit, prototype testing cannot be easier. Powering up the circuit from a 5V supply, the display must show 0. Turning the encoder shaft clockwise chages the number from 0 to 1,2,3.. up to 9; after that the circuits wraps around continung countin from 0 and so on. Turning the shaft counterclockwise reverses the effect, going from 0 to 9,8,7, etc.

The board includes a great number of connections, and it's all to easy to inadvertently omit or reverse some wire jumpers. A few tip to help you locating the failure:

More experiments

Encoders have the gift of versatilty. Differently from potentiometers or rotary switches, its behaviour can be changed simply changing the truth table (the programming) that rules the circuit.
Try to modify the table in order to transform circuit behavior as described in the following: