Path: Home => AVR-EN => Applications => RGB BCD watch m16   Diese Seite in Deutsch: Flag DE Logo
RGB display of time 15:39:13 AVR applications

RGB BCD watch with ATmega16
Hardware, Mounting, Application and Software for the BCD watch

RGB BCD watch with ATmega16

... as contrast to decimal or ordinary digital watches, here with several colors to select from.
  1. Properties
  2. Hardware
  3. mounting
  4. Software
These pages as PDF (34 pages, 835 KB).

1 Properties der RGB-Uhr mit ATmega16

The hardware properties of the described BCD watch: A short Video with the watch:

Page top Properties Hardware mounting Software

2 Hardware

2.1 Display part

Schematic of the display This is the display part of the watch. It consists of 20 RGB leds with common anode and two 16-pin socket terminal strips that connect the display part to the controller part.

Driving the leds is organized using multiplexing. Each one third of the time the hours, minutes and seconds are active. Therefore the anodes of two digits are all connected and are tied with a PNP anode driver to high voltage when active. For two leds each the common anode line is routed to one pin of the terminal strip in order to limit the current per pin to 2 * 3 * 20 = 120 mA. That results in 11 anode pins (three for the six hour anodes, four for each of the seven minutes and seconds anodes).

The three single leds in each RGB led are tied together in three common cathode pins. The three lowest leds of the Ones are connected and result in the signals C0R, C0G and C0B. Those are switched to GND by the port pin of the controller if those shall be on during that multiplex cycle part. Seven diodes (four with the ones, three with the tens, resp. two in case of the hours, with three colors each form 21 common cathode lines. Together with the eleven anode lines 32 pins of the two 165-pin terminal strips are occupied.

LED voltages depending from led currents These here are the voltages of the three leds in flow direction at different currents between 0.5 and 30 mA. The curves are very different. The red led has the lowest forward voltage and increases only slightly when the current increases. The green led has a lower forward voltage than the blue led, but the voltage increases faster with increasing current. Therefore the green led has a higher forward voltage than the blue one from a certain current on. Please note that these voltages are strongly depending from the exemplar measured, so do not use that voltages without care.

The fitting curves were derived from voltages from 15 mA current upward only.

2.2 Controller part

Schematic of the controller part This is the controller part with the ATmega16. It's I/O port A controls five color cathodes, port C further eight and port D the last eight. Current control through the leds is done with resistors, which result from the different forward voltages of the three colors (see below). Note that the cathode port pins are active low, so a zero has to be written to the output when the cathode shall be on.

The currents through all leds, that are on over a multiplex period all sum up in the GND pin of the controller. In order to limit those currents to the 200 mA (PDIP package), that are specified as maximum load in the device's databook, the current through the leds was selected to be 20 mA. The highest current is achieved when 57 is displayed: five leds are on. If two colors are selected (such as blue and red) ten led currents add up to 200 mA. If all three colors would be active (led color white) the maximum load on the GND pin would either be exceeded or the individual led current would have to be limited to 13.3 mA. This would also be possible, the difference is rarely seen by the human eye, but larger resistor values would result.

The three anodes are driven by the I/O port pins PB0 (Hours), PB1 (Minutes) and PB2 (Seconds), via the PNP transistors BD440. Their base current is limited by the 1k resistors. The anode port pins are also active low (logical zero = on).

The two keys for adjusting the time are connected to the port pins PB3 and PB4. Both have their internal pull-up resistors on, so the keys are also active low.

The potentiometer of 100k divides the operating voltage and is connected with the AD converter input pin ADC0.

The two XTAL pins are connected with a 4 MHz crystal and two 18 pF ceramic capactors. This crystal has to be invoked as source by setting the respective fuses (see below). You can use other crystals, too, but the constant clock and the whole clocking scheme in the source code has to be changed then.

The port pins PB5, PB6 and PB7 serve exclusively the ISP6 interface over which the controller can be programmed within the running system.

Distribution of the number of leds on over a day This accounts for the number of leds that are switched on over each second of a day. As the three displayed numbers are multiplexed, the 26 does not reflect a complete cycle.

Current load over the last hour of a day The resistors limit the current to 20 mA per led color. The highest currents through all the leds occur on the end of the day, between 23:00 and 24:00 hours. The picture demonstrates the large differences of current loads over this period.

At maximum, a current peak of 173 mA occurs over one second. This is well below the current limit of the GND pin in the PDIP package.

Minute averages of the current For the load of the power supply, besides the maximum current load, the minute average plays a role for the stability of the supply. This is because the thermal load of the transformer and the voltage regulator are two design characteristics. The diagram shows the minute averages over a whole day.

By average the minute loads are well below 100 mA, only at the end of an hour short periods with higher currents occur. These short periods are not relevant in that case, the 3.8VA transformer and the regulator are well below their design limits.

2.3 Power supply

Power supply of the BCD watch The power supply has to fulfil the following requirements:
  1. It has to deliver a stable 5 V because the currents through the leds are only determined with resistors and not via constant current sources.
  2. As at max. 5 leds with two colors active can cause up to 200 mA load, a short time limit of 7.5 * 0.2 = 1.5VA would be minimum. The next higher available is a 3.6VA.
  3. The voltage regulator has to be a 7805 to supply 0.2A. At 1 W thermal load a small cooling device with 20 K/W capacity is sufficient.
The schematic shows such a standard power supply with a 2*7.5V transformer. Both diodes are 1N4001 or equivalent.

Power supply voltage without load The following diagram simulates the power supply without an attached load (see the Power supply software here). The voltage on the electrolytical capacitor remains well below 16 V, so its voltage rating of 16 V is fine.

Power supply voltage at 220 mA maximum load This here is the voltage of the power supply at 220 mA constant current load, the maximum that can occur over a short time period of a second. Transformer load reserve and capacitor are fine.

This power supply was tested over a long time period with 280 mA load. The 5V are absolutely stable and the temperatures of transformer and regulator are acceptable. Only if larger currents over 500 mA are demanded the regulated voltage drops.

Page top Properties Hardware mounting Software

3 Mounting

Mounting the PCBs and the connectors Both, the controller part as well as the display part, are mounted on a double-sided experimental PCB. Double-sided because both PCBs are plugged backside-by-backside with the two 16-pin connectors. The connectors therefore have to be soldered on the component side, as can be seen from the simplified drawing.


Placing the LEDs on the display PCB The 20 RGB LEDs are placed on a double-sided 66-by-66 mm PCB. Four M2.5 screws hold the PCB on the inner side of the box cover and fix the 5 mm LEDs in the holes of the cover. Use 5 mm plastic spacers for the screws to keep the PCB in a small distance.

The four pins of the LEDs are slightly bent and displaced to the side, so the LEDs are stable to the side and cannot be bent side wards. The Plus signs show the centers of the 5 mm holes to be drilled into the box cover.

The following describes how the PCB is mounted. First of all the 5 mm holes are drilled in the box cover and are widened to 5.5 mm to leave some space so the LEDs do not have to be forced into the holes. The four holes for the screws are also drilled and four M2.5-by-20 mm screws are placed into those holes (use tape to keep those in the holes). Then bent and place a row of six LEDs for the hours digit loosely into the PCB. Place the PCB into the four screws and press the LEDs into their place in the cover holes. Then shorten the wires of the LEDs and solder the wires to the PCBs. Remove the PCB and place the next seven LEDs for the minutes losely into their holes in the PCB. Repeat this procedure until all LEDs are mounted and soldered and fit into the cover's holes.

Finally place the two female 16-pin connectors on the soldering side and solder those on the LED side of the PCB. Connect the pins of the connector with enameled copper wire with the respective LED pins, that are shown in the schematic, by applying the following procedure:
  1. Insert the copper wire from the LED soldering side into the hole near to the connector pin.
  2. Bent the first 5 mm of the copper wire by 90° with a pair of tweezers and burn the enamel from the first 3 mm of the wire end.
  3. Bring the wire close to the connector pin and solder it.
  4. Whenever more than one connection with LED pins have to be wired: remove two mm of the enamel of the wire, solder these two mm and solder it to the LED pin.
Correct wiring can be tested with a resistor of e.g. 220Ω from one of the anode connector pins to plus and connecting the cathode pin to minus of e.g. a 5V power supply.

3.2 Controller PCB

Component placement on the controller PCB This is the design of the controller's PCB with a size of 65-by-55 mm.

As the controller PCB is piggybacked on the LED PCB, pin rows and numbering changes accordingly.

Both 16-pin male connectors are mounted from the soldering side of the PCB. Soldering procedure for these is the same as for the female connectors on the display PCB.

When the power supply wires, the 40-pin IC socket for the ATmega16 (without the ATmega16), the LED resistors, the anode driver transistors and the two connectors are placed, soldered and wired, the LED PCB can be attached and the power can be applied applied. By connecting the anode driver pins 1, 2 or 3 on the socket with ground and by connecting one of the cathode pins PA3 to PA7, PC0 to PC7 resp. PD0 to PD7 with GND the LEDs 0 to 5 (hours) resp. 0 to 6 (minutes, seconds) shall be on in the order blue - green - red.

If the power supply, the crystal with its two capacitors, the RESET resistor, the IC socket and the ISP6 connector are placed, soldered and wired, the ATmega16 can be plugged in and the ID bits of the controller can be read. The fuse bits of the ATmega16 can be programmed to use the external crystal (see fuse programming). If both operations a5re succesfull, you can bring the source code to accelerate the timing (by setting the constant cAccel in the source code to a higher value than 1, re-assemble and burn the hexcode to the flash memory). This makes a day shorter so that, with cAccel = 8, it lasts only three hours, or, with cAccel = 64, only 22.5 minutes.

Further hardware bug diagnostics are available in the source code and are described in the chapter Software.

3.3 Power supply PCB

Design of the power supply The power supply is placed onto a 70x50 mm single-sided PCB.

3.4 Mounting in a plastic box

Mounting the watch in a plastic box All can be mounted in a 150*75*45 mm standard plastic box.

The controller PCB in the box Thanks to the 32 pins of the two connectors the controller PCB is piggybacked on the display PCB and does not need screwing.

Don't forget to drill some holes below and over the cooling plate for the 7805 and the transformer so those get fresh air and their heat removed.

3.5 Box labeling

The front side of the box needs a nice labeling, because everybody wants to know what this blinking box does. Unfortunately it cannot be characterized in a few words what BCD is, so it cannot be printed on the cover and remains the owner's task to comment on this. "Yes, it is a watch, but ..." and "You know, you add together the tens and the ones, both encoded as powers of two ..." are some sentences that might be necessary.

Find some labeling (and all other drawings I made) as Open-Office-Draw file here.

Page top Properties Hardware mounting Software

4 Software


The assembler source code for the watch can be downloaded from here and viewed in the browser here.

Additional documents for download: If you use the watch as a gift, a nice handbook with at least 50 pages would be appropriate. Use anything you'll find on that web page to impress the new owner.

4.2 Assembling the source code

Prior to assembling make sure that no debugging switches are set in the source code (see below for those).

For assembling you need an assembler that is familiar with .IF directives. ATMEL's assembler 2 is fine for that. If you do not want to download more than 900 MB just to have an assembler, or if you don't have a Windows operating system, is better off with my own one, gavrasm. How to assemble, if you have a 64-bit Windows is described here, for a 64-bit Linux here. Those who have a different operating system (32 bit, Mac-OS, etc.) should download the source code of gavrasm and compile their own with Free Pascal (FPC).

The assembled machine code shall be available in the same directory as .hex file.

4.3 Flashing, fuses

The hex code has to be copied to the flash memory of the ATmega16. Use a programmer and the related software.

Fuses ATmega16 by default Fuses ATmega16 for external crystal and JTAG off Prior to or after the fuses of the ATmega16 have to be changed. Otherwise the watch runs in a 96-hours-mode and one LED bit is not working as designed. The respective fuse settings are marked.

4.4 How the software works

A more comprehensive description of how the software works is available here.

Page top Properties Hardware mounting Software

Praise, error reports, scolding and spam please via the comment page to me.

©2019 by