To Build a Clock

As I teenager I taught myself digital electronics. Working from the classic books of the day, mostly the TTL Cookbook, I built a succession of projects. Among these was my first clock. Unlike other projects, this clock was a kit from Jameco Electronics. It actually had a printed circuit board, a wooden case, and a red acrylic face. Not only did I get to solder a real circuit board for the first time, I learned every gate and flip-flop in the circuit. When I finished I knew how it worked.

Point-to-Point
A GPS observing clock or a bomb?
I have built a few more clocks over the years, sometimes with classic seven segment LED displays. The latest was a GPS clock built in the 1990’s to provide accurate time on my observing table beside the telescope in the night. To a nerd like me the glowing LED displays are simply cool, something about this red glow contains a quality missing in the slick color LCD display of my modern phone or tablet computer.

On Monday this week a teenage high school student was arrested and interrogated by police for bringing a digital clock of his own construction to school. Like any young budding engineer Ahmed Mohamed wanted to show off his creation. Unfortunately the closed minds of MacArthur High School in Irvine Texas only saw a Muslim student with a possible bomb. It is clear someone has been watching way too much Fox News.

The most poignant part to me is Ahmed being led out of the school in handcuffs wearing a NASA t-shirt. In those photos I saw myself, a nerd in High School, doing the same things, starting on a road that would eventually lead me to an engineering job on the world’s most powerful telescopes.

Digital Clock
A digital clock built by Ahmed Mohamed, photo released by the Irvine Texas police department
Fortunately the nationwide condemnation of the school administration and local police force has been swift and unforgiving. Social media has seized on this incident, the school’s Facebook page roiling with sharp criticism. Nationwide press articles have been equally unforgiving. Tech industry celebrities like Facebook’s Mark Zuckerberg have shown their support. Ahmed has even received a tweet and an invitation from the president…

Cool clock, Ahmed. Want to bring it to the White House? We should inspire more kids like you to like science. It’s what makes America great. – Tweet by President Barack Obama

It is gratifying to see that the message of many of these comments is that a young person building an electronic project is something to be celebrated, not feared. We should be encouraging students to experiment, to build, to learn. True engineers start this way, exploring technology for themselves, the experience gained can not be taught in a classroom. In my career I have met and worked closely with dozens of engineers, I can tell which ones were tinkerers and makers before they started college, who build and create for the sheer joy of it.

Ahmed is not sure if he will return to school immediately and the family is consulting with attorneys. Police are currently holding the clock as evidence. Thirty years later I still have my first clock.

On Time Again

So last month the observatory clocks decided is was 1995. A software bug interfered with proper decoding of the GPS time signal. For a few weeks we got by by kludging two of the old clocks together in a creative way to provide good time for the telescopes.

The new clocks are now fully online and operational. I ran one of the new time servers for a couple weeks while keeping the old time servers in place as a backup. These have now been removed, with a second new unit installed as an in-place spare.

Hopefully this will keep everything on-time for the foreseeable future. Two new precision clocks, Microsemi SyncServer S350’s, time accurate to microseconds.

Meantime there may be a fix for the old equipment, a new GPS module by Heol Design. We have one on order to try. It would be a shame to throw out these very nice clocks.

Observatory Clocks
Two new GPS time servers installed in the Keck 2 computer room

Creating a Clock in a Microchip PIC18F

Engineering is full of these little exercises. A set of numbers that must be arranged to achieve the desired result. In this case I need to keep time in a microcontroller, as there are events that I wish to occur every few seconds.

If you are using a crystal oscillator with the microcontroller, the frequency is reasonably accurate, about 50ppm at 25°C. As long as your application does not require high precision time, the result is a decent clock. Some form of clock or timekeeping is a very typical function in many microcontroller projects.

To do this I have a standard set of subroutines that I simply import into each microcontroller project. Well tested and used for years, requiring little effort to set up each time. The routines count seconds, minutes, hours, and even days and months if needed. This time is different… I am using a PIC18F25K80 in place of the PIC16’s I have used for decades. A newer processor, little differences in the hardware and instruction set… I need to rewrite the code.

PIC18F Timer
The layout of timer 2 in the PIC18F25K80 microcontroller

Timer 2 on the PIC18F25K80 is typical of timers found in both the PIC16 and PIC18 family. There are always a handful of timers in any microcontroller, usually with different arrangements for different tasks. At least one will be set up much like this one, with a comparator to provide a repeating fixed and timed interval.

Continue reading “Creating a Clock in a Microchip PIC18F”

A GPS Observing Clock

Observing Clock
A hand made GPS clock for the observing table
For years, when observing, I found myself wanting a clock on my observing table when recording observations. I have used either a wrist watch or a cell phone, but looking at these was uncomfortable as these modern devices use bright backlit LCD displays, not a nice night-vision friendly red. The cell phone also has the additional problem of using up its battery quite quickly when out of range of a digital cell tower at some remote observing site. I needed a simple desk clock for my observing setup.

Accuracy was also a question, accurate time is always important when observing. Asteroid occultations, lunar and solar eclipses, iridium flares, twilight, jovian moon transits, the list of things where accurate time is useful is long in astronomy.

The Specs

Of course being a electrical engineer makes designing and building a clock a fairly trivial exercise. But why stop there? Why not build in a few extra features…

  • Use red 7-segment LED’s and build in some type of selectable dimming mechanism.
  • Why bother setting the clock each time you set it up? Make the clock self setting and very accurate.
  • Since the clock is accurate add a serial port to allow the clock to supply accurate time to a laptop when taking astrophotos.

Continue reading “A GPS Observing Clock”