Grant's Pinball Clock

  ;


Description

Grant Levey found an old electromechanical 4-digit drum-type score display that once lived in a pinball machine. He wanted to use it as a clock display. He requested help from the folks on the PICAXE list in May, 2007. I designed this project to assist Grant with his own design efforts.

His drum display uses four digits, each with a trigger input that increments the display by one with each trigger pulse. Apparently, the display assembly has no facility to set all four digits to zero. (The lack of a zero set makes the project a bit clumsy, as I'll discuss below.)

Since the processor doesn't control the display directly, and has no real way of knowing what the display is actually showing in response to the program's increment pulses, the system must have a way to get the display into a known initial condition. Once in that condition -- the all-zero state -- the program can then sync its internal timekeeping registers with the increment pulses it sends the display.

The four digits are used to display Hours x 10, Hours x 1, Minutes x 10, and Minutes x 1. Grant wanted to set this up for 12-hour time, although a 24-hour time display can be accomplished with a simple program modification.

 

User Interface and Operation

I decided to provide display and time setting in two distinct phases.

In the first, the display is set to a known initial condition -- all digits set to zero. When the user has completed display initialization, the program sets its internal timekeeping registers to zero (to match, hopefully, the state of the display) and the next -- time set -- phase begins.

In the timekeeping phase, the user selects each digit, increments it to match the actual time, then moves on to the next digit. While the digits are being incremented in the time set mode, the program's internal timekeeping registers are incremented in step. At the end of this process, the display will (hopefully) be displaying the correct time, and the internal timekeeping registers are sync'd with the external display.

Once the time has been set, the user selects the timekeeping mode. While timekeeping, the clock sends appropriate pulses to the display to, hopefully, display the correct time.

The design uses three pushbuttons and two LEDs as the user interface. Here's how it works:

When the processor is powered up, the program is uninitialized. Both LEDs illuminate.

The first pushbutton changes the mode with each button press: display initialization, time set, clock run, then cycling back to display initialization, etc.

The two LEDs indicate the mode:

  • Uninitialized: both LEDs on
  • Display Initialization mode: the first LED on, the second LED off
  • Time Set mode: the first LED off, the second LED on
  • Clock Run: both LEDs off

In both the display initialization and time set modes, the other two pushbuttons work the same way. The second pushbutton scrolls through the active digits, from Hour x 10 to Hour x 1 to Minute x 10 to Minute x 1 and back to the Hour x 10 digit. The third pushbutton increments the active digit once for each button press.

During clock run mode, the time set LED will flash one second on, one second off to show that the timebase is operating. The Init LED will flash each time a pulse is sent to the pinball display.

Operation

At powerup, both LEDs will illuminate.

The user will first initialize the display. With the first press of the mode pushbutton, the first LED will illumate and the second will turn off.

The user will select each digit in turn using the second pushbutton. For each digit, the third pushbutton will increment the selected display digit until it reads zero. The the next digit is selected using the second pushbutton.

When all digits are displaying zero, the user pushes the first pushbutton once again to enter the time set routine. At that instant, the program's internal timekeeping registers are set to zero, matching the state of the external display. The first LED will go out and the second LED wil illuminate.

Using the same procedure as the display initialization routine, the user sets the correct time on the external display. In the time set mode, however, the program's internal timekeeping registers increment in synchronization with the changes sent to the external display.

When the correct time is displayed, the next press of the first pushbutton will start timekeeping. Both LEDs extinguish in the clock run mode.

If the user presses the first pushbutton once again, timekeeping halts and the program enters the display initialization routine once again.

In timekeeping mode, the Minutes x 1 digit will increment once each minute, with carry to the Minutes x 10 digit.

When the Minutes x 10 digit reaches 5, the next increment will send enough pulses to advance the digit back to zero. The Hour x 1 digit is then incremented.

In a similar fashion, the Hours will increment through the seequence 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, and back to 01.

 

Hardware

Refer to the sketches, below.

An 18-pin PICAXE-18X is the heart of the system. The PICAXE drives the display driver transistors via four outputs, one for each pinball display digit. Two other outputs drive the LED indicators.

The pushbuttons are fed to three PICAXE input lines.

The clock system has two different timebase options.

The first option uses 1 Hz squarewave pulses generated by a Dallas DS1307 real time clock chip. The chip is connected to the PICAXE via a 2-wire I2C connection. Once initialized by the program, the DS1307 feeds a 1 Hz squarewave to the PICAXE via its SQW/OUT line.

The second timebase option uses a 50 or 60 Hz squarewave derived from the local AC line as shown in the second sketch.

Either timebase option produces the same result in the software: 1 Hz pulses built in the program's interrupt routine.

 

Software

Note that there are two different versions of the PICAXE BASIC listing -- one for the DS1307 timebase, and one for the 50/60 Hz line-derived timebase. The two versions differ primarily in the interrupt routine.

Let's take a look at it. Download either version, and open it in your RevEd PICAXE development system, version 5.1.1 or later. Set your options for 18X and 256 subroutines.

The program is structured into three main loops, one corresponding to each of the modes of operation: display initialization, time setting, and timekeeping.

Note that the very first section of the program contains the constants you'll adjust to tune the program to your hardware. Things you might adjust are local line frequency, pushbutton debounce time delay, and, the one most likely to require a tuneup, the on time and off time of the pulses sent to the external display.

Next move down to the main routine. At powerup, interrupts are disabled and variables are initialized. The program turns on both LEDs, then waits for a press of the mode select pushbutton.

At the first button press, the program enters the display initialization routine. The first LED illuminates and the second is turned off. During initialization, only the display digit values are incremented. No internal timekeeping registers are varied.

The next press of the first pushbutton enters the SetTime routine. At that instant, all internal timekeeping registers are zeroed. The first LED shuts off and the second LED illumiates. This works similar to the display initialization routine except that in this loop, the program's internal timekeeping registers are incremented in synchronization with the external display.

The next button press enables interrupts, turns off both LEDs, enables interrupts, and begins timekeeping. routine.

The timekeeping loop continually monitors the first pushbutton and the value in the 60-second register, incremented each second by the interrupt routine.

When the value in the 60 second register reaches 60, the register is cleared and the Minute x 1 digit (and its corresponding timekeeping register) is incremented. The loop then tests for carry to the next digit, on up the chain.

As each digit is incremented beyond its display range, it is fed a series of pulses to increment it forward to zero.

The interrupt routine simply increments the 60 second register once each second. In the DS1307 version, only the 60 second register is incremented. For the line-derived timebase version, a further register (1 second register) is incremented to derive 1-second pulses in software. When the one-second register reaches the value of the LineFreq constant, the interrupt routine increments the 60-second register.

Download the PICAXE BASIC Listing, Version 0.05

 

Pinball Clock

 

Alternative Line-Derived Timebase

If you will be building your own 5 VDC power supply to power your clock, you can save a chip and crystal by deriving your clock's timebase from the 50/60 Hz AC line. You'll actually gain better performance and more accuracy with the line-derived approach, since your power provider takes great care to keep the average frequency of the AC line at exactly 50 or 60 Hertz.

Below is a sketch showing the timebase circuitry, and a PICAXE BASIC listing modified to use a line-derived timebase.

Even if you don't plan to build Grant's clock, you might steal this timebase and interrupt routine for other PICAXE projects.

Download the alternative PICAXE BASIC Listing, Version 0.05

 

Pinball Clock