Tempus - a Metric Clock
I was asked to build a metric, or decimal clock, as they are not readily available commercially. Metric time, or French Revolutionary time, divides the day into decimal units. A day has 10 hours, an hour 100 minutes, and a minute 100 seconds.
(If you do a search, you will discover so-called metric or decimal clocks for sale. But be careful - these clocks have what looks like a metric face (10 hour markings and numbering), but use a standard 12-hour mechanism, with 60 seconds per hour and 60 seconds per minute. Such a clock is not a metric clock at all. I have not been able to find a true metric clock for sale, other than antiques. If you find a modern one, please let me know.)
I was asked to build an analog metric clock with hour, minute, and second hands that would run on Great Britain mains power. I have built clocks using 1 RPM synchronous motors, which run in step with 60 Hz 120v power. My first thought was to use a 50 Hz synchronous motor. But doing the math reveals this to be problematic. There are 60*60*24 or 86,400 seconds per day in standard time, but 10*100*100 = 100,000 seconds per day in metric time. So a metric second is .864 of a standard second. With 100 metric seconds per revolution of the seconds hands, that makes 86.4 standard seconds per revolution, 60/86.4 = .694444444 RPMs. Not easy to find a synchronous motor like that.
What kind of motor could operate accurately at an unusual speed? I decided a stepper motor would work. My first thought along this line was to use one motor at the proper RPM for the seconds hand, and gears to drive the minutes and hours hands. But a divide by 100 gear train would require 4 sets of wheels and pinions to be compact. I decided to use a separate stepper motor for each hand.
Supplies
- MSP 430 Launchpad - Texas Instruments
- 28BYJ-48 5v stepper motor with ULN2003 Driver Board - eBay
- pushbutton switch, SPST
- .1 uF ceramic capacitor
- USB power supply
- Gears - hobby shop
- Brass tubing - hobby shop
Motors
It didn't take long for me to come across the 28BYJ-48 5v stepper motor. These are readily available for hobbyists, complete with driver board to interface with microcontrollers such as Arduino. They are also quite inexpensive. I purchased 5 motors with driver boards from a US supplier on eBay.
There is an excellent video on these motors, 28BYJ-48 Stepper Motor and ULN2003 Driver Intro, on You Tube: https://www.youtube.com/watch?v=B86nqDRskVU. From the video, you can see that the motors can be operated in various modes. I chose to operate in full step mode, which is fairly straightforward to implement and yields maximum torque. In this mode, two of the four motor coils are activated at a time, and the motor makes 32 steps per motor shaft revolution. These motors have an internal gear set that is said to be a 1:64 ratio, but in fact that is only an approximation, and an approximation won't allow us to keep accurate metric time. More on that later.
While these stepper motors can be operated with continuous current - that is, always having two coils activated - it's not generally necessary or desirable. Not necessary because the motor shaft will not move after a step if current is removed, and not desirable because at continuous power more current is used and the motors get hotter. I do not operate the minutes and hours motors continuously, and have made provisions in the software to also not operate the seconds motor continuously.
Controller and Electronics
I have used TI MSP430 microcontrollers and the Launchpad development board on a few other projects, so that was a natural choice for this project. I used a Launchpad with its supplied MSP430G2553 microcontroller and 32.768 kHz watch crystal for a timebase. The motor driver boards connect directly to port pins on the Launchpad. The motors require 5v. This was readily obtained from the Launchpad's test point TP1, which is connected to the 5v supply on the mini USB port. The only other electrical components are a pushbutton switch and debounce capacitor, the latter of which was soldered directly to the pushbutton's leads.
Ordinarily I would get circuit boards made, or solder a breadboard, but as this project was a one-off and the Launchpad inexpensive, I just used it in the final clock. I used a universal USB power adapter to power the clock once development was finished and the USB cable was unplugged from the host PC. The adaptor has snap-on prongs for US, GB, and other countries' power.
Clock Body and Hands
I design the clock face and body using Carvewright's Designer software and machined them using the Carvewright CNC machine. I used 3/4" MDF for the parts. The hands were similarly designed and machined out of maple. Hobby brass tubing was used for the shafts. This tubing is sized such that the next large tube slides nicely over the smaller diameters. I used smaller diameter tubing for the seconds hands, and progressively larger for the minute and hour hands. I got some hobby gears sized to fit the metric shafts of the stepper motors. The diameter was close enough to standard English tubing size to also fit onto the hands shafts. I soldered larger-diameter tubing onto the smaller diameter tubing to fit the gears. I designed and machined motor mounts with the Carvewright. I added some spring-loaded shoes to the gears to prevent undesired movement of the hands due to gear backlash in the stepper motors and the gears that I added.
Software
The basic function of the software is to step the seconds (and minutes and hours) motor at the correct rate for a metric clock. One of the microcontroller's timers is use to trigger the next step. As already mentioned, I used a 32.768 MHz watch crystal as a timebase for the MSP's ACLOCK. With a timer set to this clock, it counts up once every 1/32,768 seconds. So, how many timer counts between steps? With 32 steps per motor rev, the not quite 1/64 gear set in the motor, .864 seconds per metric second, 100 metric seconds in a full rev of the second hand, the math was done with a spreadsheet - numbers in red are inputs, black numbers are calculated.
Of course we can only set the timer to an integer number of timer counts, but we can't simply round off and maintain accuracy. So, the software initially sets the next lowest integer number, then keeps track of the error between the ideal and actual number of counts each time the timer triggers, using floating point arithmetic. When the error equals or exceeds the absolute value of 1.0, the timer count is increased (or decreased on negative error) by one.
All this is done via an interrupt handler.
While the motors are being stepped about once every 42 mS, it is not necessary to keep the coils energized that long. I found that the motors appeared to work reliably at as little as 12 mS, and maybe less. So, I set a timer compare register to also interrupt after about 12 mS and shut the motor coils off, well before the next step. However, as this clock was leaving my hands, to be safe in the end I did leave the coils to all motors on for the full 42 mS. I used TI's Code Composer Studio's graphical interface Grace to configure the microcontroller, so all it takes to enable or disable the shorter coil activation time is to change a timer CCR (capture compare register) value. In the configuration that I supplied, I set the CCR to 2000 counts, beyond the value of the basic "tick" rate, so the compare will not trigger and the interrupt service routine to shut the coils off is never invoked. To enable, just set the CCR value (or period in Grace) to something like 12 mS. I plan to experiment with this some more.
The minute hand is stepped once every 100 steps of the seconds motor, and the hour hand once every 10 steps of the minutes motor, to keep correct time.
(To develop and debug the software, I used the standard 12 hours per revolution and 60 minutes per revolution, and cardboard clock faces. I found this easier to get my head around, as standard time is much more familiar to me. Once everything was working, I just changed the constants to metric time.)
Since the microcontroller has no knowledge of where the hands might be positioned on startup, the hands must initially be aligned. A pushbutton switch is used to align each hand in turn and set the time. When the pushbutton switch is first pushed, the hour hand starts moving, slowly at first, then more rapidly. Releasing the switch stops the hand, but if pushed again within 3 seconds the same hand moves again, starting out slowly as before. This allows the hand to be swept quickly to the approximate desired position, then jogged precisely to position. Releasing the pushbutton for more than 3 seconds advances movement to the minutes, then seconds hand. Once the hands are aligned, the minutes and hours hands can be moved in coordinated fashion to set the time and finally run all three hands.
A second timer is used to move the hands more rapidly for alignment and to set the time. This timer starts out with a longer up count value, but this value is decreased by a percentage each counter overflow to speed up the hands.
The pushbutton switch is connected to a port pin, and the pin configured with an internal pull-up. A capacitor across the switch's terminals makes up a simple RC debounce circuit. The port pin is configured to interrupt on both push and release of the button. A state machine advances action to align each hand, set the time, and start the clock. The watchdog timer is configured as a 1-second interval timer to determine how long the switch has been released.