Designing and Building a binary clock


Three weeks before the Houston Maker Faire Chris came to me asking if we could whip up a low cost giveaway for the faire. I wanted to giveaway something more than a blinky LED badge since that is the typical electronic swag at Maker Faire. It had to be something that the person would wear and would want to show off to other Makers to spread the word about MacroFab. Blinking LEDs are always necessary though. The budget was set to under $3 a unit and I was given only three weeks to prototype, design, and manufacture the giveaway.


The Macro Watch stemmed from those constraints. I picked the PIC16F527 microcontroller by Microchip to be the core of the watch because it was the cheapest MCU I could find that had enough I/O and I knew at least a little bit about it in terms of writing code for and programming. The watch shows time in binary since doing so requires less LEDs to display time than the usual watch patterns, driving the cost down. The least expensive SMD 32.786KHz crystal on Mouser (part # ABS25-32.768KHZ-T) was used to make the PIC16F527 run in “LP” mode (Low Power Crystal Mode) and help increase the accuracy of the time keeping without blowing through the battery quickly. MacroFab House Parts were used to fill in the rest of the passives and switches. For the wrist strap I ordered ESD wrist straps from China in bulk.

The plan was to spend 1 week prototyping and designing the board, 1 week for parts to arrive, and 1 week for assembly and packaging. An aggressive schedule on the R&D side but doable. What could possibly go wrong?


Stephen had an old PICDEM Lab prototyping breadboard so I ordered some PIC16F527-E/P components which are the DIP version of the microcontroller I was planing to use. A couple days later I popped it into the PICDEM Lab bread board, plugged in a PICkit 3 programmer and was talking to the PIC16F527 right away. Unfortunately, that was where the luck ran out.

First was to get an LED to blink. Easy no? I plugged an LED in the RA0 port and wrote a small blinky program. LED did not blink. I was not very familiar with this chip and figured it had to be some kind of configuration issue. A couple hours later, after triple checking my hardware and code, I came across table 6-1 “PORTA PINS ORDER OF PRECEDENCE” which lists the priority of how the configuration registers use the pins. I knew about setting the ANSEL registry to 0x00 but there was “C1IN+” listed on RA0. This PIC had comparators that where enabled by default! The register CM1CON0 had to be set to 0x00 as well before RA0 could be used as a digital GPIO. Finally success! Blinking LEDS!


With the idea prototyped I quickly moved on to the schematic and layout of the watch.


The PIC16F527-I/ML is the QFN version of the PIC16F527 and I used it as it was the smallest package available. To power the watch a CR2032 battery holder was picked — it’s a standard size battery and has decent capacity for a coin cell. To reduce board area and further drop the cost I chose to use one dropping resistor for the entire LED bank. The idea was to matrix through the LEDs one at a time. This will come into play later as being a bad idea. The schematic took only a couple hours to fill out with most of that spent designing the PIC16F527-I/ML and battery holder in Eagle. Parts were finalized and orders paced at our part distributors.


Layout was a typical two layer PCB. I made sure a standard 20mm wrist strap would fit inside the cut outs this was the width of an ESD strap. Copper pour around the cutouts strengthen the board.

We panelized the Macro Watch in 5 by 5 panels and a week later they arrived. Black soldermask and white silkscreen.


With the boards in we had 6 days to build the boards and finalize the firmware. we built a test panel before moving onto the production run. More issues! First, the PIC16F527-I/ML only comes in tube and so it would have to be hand placed, because someone was already using the tube feeders. Everything else went on the pick and place for assembly. I did not test Low Power Crystal Mode on the bread board and when I enabled that mode on the production board I could not matrix the LEDs fast enough to prevent flicker. The only fix was to drive the LEDs on all the time. This has the side effect of the LEDs getting dimmer when the seconds LED blinked. Trying to save $0.10 on the BOM forced me to run the LEDs improperly.

I changed the resistor from the specified 470ohm to 100ohm to reduce the impact of the seconds LED flashing which helped a bit. After changing out the resistor on the pick and place we ran the rest of the boards building a total of 150 Macro Watches in an afternoon. Assembly went really well with no rework needed on any of the boards. With only 5 days left till Maker Faire it was time to wrap up the code.

The code works by using Timer0 on the PIC16F527 to time keep. Using the 32.768kHz crystal and no timer prescaler (by setting the prescaler to work on the WDT instead of Timer0) the Timer0 ISR happens 32 times a second. The ISR counts 32 times and then adds one second to the current time. The pad labeled RA2 on the Macro Watch is high when ISR starts and goes low when the ISR finishes.


The main loop of the code is a small state machine that keeps track of what mode the watch is currently in. The first state is the idle state where the watch polls the switch and awaits user input. Once the button is pressed it moves to the second state which calculates how long the watch will display for and then it moves on to state three. State three does the bulk of the work by branching based on how much time the display has been on for and what the user is currently doing. The watch is also driving the LEDs in this state. If the user has held the button for more then 3 seconds the watch goes into state four. State four advances the time. The longer the button is pressed the faster the time advances.

For More Details: Designing and Building a binary clock

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top