Fast clocks, model railroads, LED displays, and more

Lead Image © Natalia Prokofyeva, 123RF.com

Faster, Faster

Some model train enthusiasts like to run their trains like a real railroad with a dispatcher controlling movements, issuing train orders, and making sure the train stays on schedule. But, time runs differently for these trains, thanks to fast clocks.

Because model railroad routes are much shorter than their real-life counterparts, it takes mere seconds, or perhaps a minute or two at most, to get from place to place. One trick employed to make these trips seem longer is the use of specially designed fast clocks. By passing time faster, the clock shows that more time has elapsed, even if two locations are just inches apart.

The heart of my fast clock is a Pi Zero [1]. Although it's rather trivial to retrieve the current system time and display it, changing the update rate of the system time is not so trivial. To circumvent this challenge, I use my own timer events set to 500ms (2x), 250ms (4x), or 125ms (8x) to update a time object in Python. For real-time/real-speed operation, I also have a 1,000ms update rate. A keyboard shortcut will update the time object to reflect real-world time when the display is not in use as a "fast" clock.

Remote Displays

The next challenge to make it easy to see all around the layout. The main display of the clock is the Pi Zero's HDMI output. For remote displays, I drive seven-segment displays to create digital clocks that can be duplicated as needed. Each display only requires three (or sometimes four) wires between it and the previous display or Pi Zero.

The chip I use is called an MM5450 [2]. It's a shift register with a few special features built in. So, what's a shift register? Think of it as a row of seats in a movie theater with an usher at the row entrance. As you step into the row, the usher asks you to either sit down or remain standing. As more people enter, you keep moving down the row until everyone has a seat. Once the row is full, the usher tells everyone to sit or remain standing as instructed when they entered. That's the same way a shift register manages its data.

A classic TTL shift register like the MM74HCT164 is only 8 bits wide, although there are also 16-bit versions available. It also operates at 5V. The MM5450 has 34 outputs and also operates at 5V, but it includes a current limiter. This means LEDs can connect to it directly without discrete resistors. The 5450 can operate at 3.3V as well, so if that's your project voltage, you are still in good shape!

I use four pins from the GPIO port to power and control the remote displays. Conveniently, they are all located next to each other (Figure 1). Pin 4 (board numbering) provides 5V directly from the Pi's power input, pin 6 is ground, and pins 8 and 10 are the built-in UART, but here I use them as general-purpose outputs. Remember that odd pin numbers are closest to the main processor, and even numbers are closest to the upper edge of the board. This allows a four-pin jumper to connect between the Pi Zero and my breadboard.

Figure 1: This diagram shows how all of the segments are wired to the 5450 and how the 5450 is wired to the Pi Zero. Note the variable resistor on the 5450 to control display brightness.

Although 3.3V is available from the Pi's GPIO port, it can't source much current. The 5V pin on the GPIO port, however, has the entire source current available from the power supply (less what the Pi itself is using). Because I'm driving 28 LEDs, I used the 5V pin so more current is available.

To instruct the 5450 to light a series of LEDs, a bitstream is clocked into the chip one bit at a time. The 5450 has two inputs – data and clock. The data line provides the value high for 1 and low for 0. The clock line watches for a high-voltage level that says "read the data pin now." First, a "start bit" is sent by setting the data line high (representing 1) and raising, then lowering the clock line. Then, the desired on/off values of all 34 outputs is sent in the same manner, setting the data line appropriately each time. Finally, the clock is pulsed once more, and the bit pattern appears on the connected LEDs.

Stop Bits and the 35th Output

Although I refer to the last bit in the bitstream as a "stop bit," it is actually a 35th output. In the MM5450, a data enable line appears on pin 23, which I hardwire to ground. The MM5451 is an identical chip, except data enable has been replaced with a 35th output.

Alternatively, data enable can be wired to a separate GPIO pin on the Pi Zero. If data enable is high, then the 5450 ignores all clock and data signals. That allows clock and data lines to be shared among many MM5450s and still be controlled individually.

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content