USB BCD Clock

Filled under: Electronics

Date posted: December 25, 2007

Binary-Coded Decimal Clock

Status – Updated
Original Date: Dec 2007

bcd_clock_1

The time is 2:29:32

This is a simple BCD clock driven a USB data connection to a PC and employing a multiplexed array of LEDs using POV.

Details:

Each digit of the time broken down from hour, minute,to the second then coded into a binary representation. Each row represents a single digit; the top two rows being the hour, the middle two rows being the minute, and the lower two rows being the seconds.

The binary representation of decimal digits:

Decimal Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

The microcontroller is a PIC18F2550 and has built in USB capabilities and a system clock speed of 48MHz. The clock speed is great enough to drive the 4 x 6 LED array using POV without showing a flicker. The time is directly controlled the host PC using a simple C++ program.

The LEDs are multiplexed which reduces the required MCU pins from 24 down to only 10. Using a simple array of four transistors and ten logic pins the firmware goes through each of the six rows of LEDs and lights up the LEDs one row at a time. Despite only on row of LEDs being lite at any time, using the concept of POV (persistence of vision) all that is required is to go through the rows at a fast enough speed and the eyes will be unable to notice the flicker. A refresh rate of 120Hz (120 flickers a second), the same as most modern computer monitors, is quick enough to eliminate the flicker.

A simple GUI program with an output preview.

The Interface Program:

The PIC MCU emulates a HID device which windows quickly and universally recognizes thus making the creation of a interface program rather to the point.

Using Visual Studio Express C++ 2010 and preprogrammed HID headers the interface program was basically just adding in the VID and PID  (Vendor ID and Product ID), adding system time grabbing code, and adding graphics to the UI. The program grabs the system time and sends it out the PIC device using the first three bytes of the report. From there the PIC breaks down the data and converts it into a binary coded display.

The HID framework for the C++ program is credited to http://www.waitingforfriday.com There you can find a well written tutorial for setting up PIC to USB communications using the preprogrammed C++ HID headers and the free USB libraries from MicroChip for the PIC MCU.

Components:

1x PIC18F2550
24x Ultra-bright LEDs
4x 2N2222 NPN transistors
7x 10K ohm Resistors
4x 470 ohm Resistors
2x 22pF Capacitors
2x 470uF Capacitor
1x USB jack
1x External 20MHz crystal oscillator
1x Programming header

bcd_clock_2

The backside wiring.

Schematic:

N/A

 

Code:

The PIC firmware is developed using MikroElektronika’s MikroC Pro compiler with their built in USB HID libraries. This all makes setting up a USB interface a breeze!

 

bcd_clock_3

<td>0100</td>