Silicon ChipUSB Clock With LCD Readout, Pt.1 - October 2008 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Smart power meters will jack up your electricity bill!
  4. Review: CleverScope CS328A USB Dual-Channel 100MHz Scope by Mauro Grassi
  5. Feature: PICAXE-08M 433MHz Data Transceiver by Stan Swan
  6. Project: USB Clock With LCD Readout, Pt.1 by Mauro Grassi
  7. Project: Digital RF Level & Power Meter by Jim Rowe
  8. Project: Versatile Special Function Timer by John Clarke
  9. Project: Railpower Model Train Controller, Pt.2 by John Clarke
  10. Feature: Exposing PC Boards In A Modified Microwave Oven by Graeme Rixon
  11. Vintage Radio: The AWA Radiola 653P AC/Battery Portable by Rodney Champness
  12. Feature: Cent-a-meter Owl: Watching Your Power Consumption by Stan Swan
  13. Book Store
  14. Outer Back Cover

This is only a preview of the October 2008 issue of Silicon Chip.

You can view 30 of the 104 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Articles in this series:
  • Amateur Radio (November 1987)
  • Amateur Radio (November 1987)
  • Amateur Radio (December 1987)
  • Amateur Radio (December 1987)
  • Amateur Radio (February 1988)
  • Amateur Radio (February 1988)
  • Amateur Radio (March 1988)
  • Amateur Radio (March 1988)
  • Amateur Radio (April 1988)
  • Amateur Radio (April 1988)
  • Amateur Radio (May 1988)
  • Amateur Radio (May 1988)
  • Amateur Radio (June 1988)
  • Amateur Radio (June 1988)
  • Amateur Radio (July 1988)
  • Amateur Radio (July 1988)
  • Amateur Radio (August 1988)
  • Amateur Radio (August 1988)
  • Amateur Radio (September 1988)
  • Amateur Radio (September 1988)
  • Amateur Radio (October 1988)
  • Amateur Radio (October 1988)
  • Amateur Radio (November 1988)
  • Amateur Radio (November 1988)
  • Amateur Radio (December 1988)
  • Amateur Radio (December 1988)
  • Amateur Radio (January 1989)
  • Amateur Radio (January 1989)
  • Amateur Radio (April 1989)
  • Amateur Radio (April 1989)
  • Amateur Radio (May 1989)
  • Amateur Radio (May 1989)
  • Amateur Radio (June 1989)
  • Amateur Radio (June 1989)
  • Amateur Radio (July 1989)
  • Amateur Radio (July 1989)
  • Amateur Radio (August 1989)
  • Amateur Radio (August 1989)
  • Amateur Radio (September 1989)
  • Amateur Radio (September 1989)
  • Amateur Radio (October 1989)
  • Amateur Radio (October 1989)
  • Amateur Radio (November 1989)
  • Amateur Radio (November 1989)
  • Amateur Radio (December 1989)
  • Amateur Radio (December 1989)
  • Amateur Radio (February 1990)
  • Amateur Radio (February 1990)
  • Amateur Radio (March 1990)
  • Amateur Radio (March 1990)
  • Amateur Radio (April 1990)
  • Amateur Radio (April 1990)
  • Amateur Radio (May 1990)
  • Amateur Radio (May 1990)
  • Amateur Radio (June 1990)
  • Amateur Radio (June 1990)
  • Amateur Radio (July 1990)
  • Amateur Radio (July 1990)
  • The "Tube" vs. The Microchip (August 1990)
  • The "Tube" vs. The Microchip (August 1990)
  • Amateur Radio (September 1990)
  • Amateur Radio (September 1990)
  • Amateur Radio (October 1990)
  • Amateur Radio (October 1990)
  • Amateur Radio (November 1990)
  • Amateur Radio (November 1990)
  • Amateur Radio (December 1990)
  • Amateur Radio (December 1990)
  • Amateur Radio (January 1991)
  • Amateur Radio (January 1991)
  • Amateur Radio (February 1991)
  • Amateur Radio (February 1991)
  • Amateur Radio (March 1991)
  • Amateur Radio (March 1991)
  • Amateur Radio (April 1991)
  • Amateur Radio (April 1991)
  • Amateur Radio (May 1991)
  • Amateur Radio (May 1991)
  • Amateur Radio (June 1991)
  • Amateur Radio (June 1991)
  • Amateur Radio (July 1991)
  • Amateur Radio (July 1991)
  • Amateur Radio (August 1991)
  • Amateur Radio (August 1991)
  • Amateur Radio (September 1991)
  • Amateur Radio (September 1991)
  • Amateur Radio (October 1991)
  • Amateur Radio (October 1991)
  • Amateur Radio (November 1991)
  • Amateur Radio (November 1991)
  • Amateur Radio (January 1992)
  • Amateur Radio (January 1992)
  • Amateur Radio (February 1992)
  • Amateur Radio (February 1992)
  • Amateur Radio (March 1992)
  • Amateur Radio (March 1992)
  • Amateur Radio (July 1992)
  • Amateur Radio (July 1992)
  • Amateur Radio (August 1992)
  • Amateur Radio (August 1992)
  • Amateur Radio (September 1992)
  • Amateur Radio (September 1992)
  • Amateur Radio (October 1992)
  • Amateur Radio (October 1992)
  • Amateur Radio (November 1992)
  • Amateur Radio (November 1992)
  • Amateur Radio (January 1993)
  • Amateur Radio (January 1993)
  • Amateur Radio (March 1993)
  • Amateur Radio (March 1993)
  • Amateur Radio (May 1993)
  • Amateur Radio (May 1993)
  • Amateur Radio (June 1993)
  • Amateur Radio (June 1993)
  • Amateur Radio (July 1993)
  • Amateur Radio (July 1993)
  • Amateur Radio (August 1993)
  • Amateur Radio (August 1993)
  • Amateur Radio (September 1993)
  • Amateur Radio (September 1993)
  • Amateur Radio (October 1993)
  • Amateur Radio (October 1993)
  • Amateur Radio (December 1993)
  • Amateur Radio (December 1993)
  • Amateur Radio (February 1994)
  • Amateur Radio (February 1994)
  • Amateur Radio (March 1994)
  • Amateur Radio (March 1994)
  • Amateur Radio (May 1994)
  • Amateur Radio (May 1994)
  • Amateur Radio (June 1994)
  • Amateur Radio (June 1994)
  • Amateur Radio (September 1994)
  • Amateur Radio (September 1994)
  • Amateur Radio (December 1994)
  • Amateur Radio (December 1994)
  • Amateur Radio (January 1995)
  • Amateur Radio (January 1995)
  • CB Radio Can Now Transmit Data (March 2001)
  • CB Radio Can Now Transmit Data (March 2001)
  • What's On Offer In "Walkie Talkies" (March 2001)
  • What's On Offer In "Walkie Talkies" (March 2001)
  • Stressless Wireless (October 2004)
  • Stressless Wireless (October 2004)
  • WiNRADiO: Marrying A Radio Receiver To A PC (January 2007)
  • WiNRADiO: Marrying A Radio Receiver To A PC (January 2007)
  • “Degen” Synthesised HF Communications Receiver (January 2007)
  • “Degen” Synthesised HF Communications Receiver (January 2007)
  • PICAXE-08M 433MHz Data Transceiver (October 2008)
  • PICAXE-08M 433MHz Data Transceiver (October 2008)
  • Half-Duplex With HopeRF’s HM-TR UHF Transceivers (April 2009)
  • Half-Duplex With HopeRF’s HM-TR UHF Transceivers (April 2009)
  • Dorji 433MHz Wireless Data Modules (January 2012)
  • Dorji 433MHz Wireless Data Modules (January 2012)
Items relevant to "USB Clock With LCD Readout, Pt.1":
  • PIC18F4550-I/PT programmed for the USB Clock (Programmed Microcontroller, AUD $20.00)
  • Firmware (HEX file), source code, software and driver for the USB Clock [0411008A.HEX] (Free)
  • USB Clock PCB pattern (PDF download) [04110081] (Free)
  • USB Clock front panel artwork (PDF download) (Free)
Articles in this series:
  • USB Clock With LCD Readout, Pt.1 (October 2008)
  • USB Clock With LCD Readout, Pt.1 (October 2008)
  • USB Clock With LCD Readout, Pt.2 (November 2008)
  • USB Clock With LCD Readout, Pt.2 (November 2008)
Items relevant to "Digital RF Level & Power Meter":
  • PIC16F88-I/P programmed for the RF Level & Power Meter [0421008A.HEX] (Programmed Microcontroller, AUD $15.00)
  • PIC16F88 firmware and source code for the Digital RF Level & Power Meter [0421008A.HEX] (Software, Free)
  • Digital RF Level & Power Meter main PCB pattern (PDF download) [04210081] (Free)
  • Digital RF Level & Power Meter input PCB pattern (PDF download) [04210082] (Free)
  • Digital RF Level & Power Meter attenuator PCB pattern (PDF download) [04210083] (Free)
  • Digital RF Level & Power Meter panel artwork (PDF download) (Free)
Items relevant to "Versatile Special Function Timer":
  • PIC16F628A-I/P programmed for the Special Function Timer [0511008A.HEX] (Programmed Microcontroller, AUD $10.00)
  • PIC16F628A firmware and source code for the Special Function Timer [0511008A.HEX] (Software, Free)
  • Versatile Special Function Timer PCB pattern (PDF download) [05110081] (Free)
Items relevant to "Railpower Model Train Controller, Pt.2":
  • Railpower IV main PCB [09109081] (AUD $20.00)
  • Railpower IV front panel PCB [09109082] (AUD $15.00)
  • PIC16F88-I/P programmed for the Railpower IV [0910908A.HEX] (Programmed Microcontroller, AUD $15.00)
  • PIC16F88 firmware and source code for the Railpower IV Model Train Controller [0910908A.HEX] (Software, Free)
  • Railpower IV Model Train Controller main PCB pattern (PDF download) [09109081] (Free)
  • Railpower IV Model Train Controller display PCB pattern (PDF download) [09109082] (Free)
  • Railpower IV Model Train Controller panel artwork (PDF download) (Free)
Articles in this series:
  • Railpower Model Train Controller (September 2008)
  • Railpower Model Train Controller (September 2008)
  • Railpower Model Train Controller, Pt.2 (October 2008)
  • Railpower Model Train Controller, Pt.2 (October 2008)

Purchase a printed copy of this issue for $10.00.

For the advanced constructor . . . USB Clock With LCD Readout Pt.1: By MAURO GRASSI This LCD USB Clock connects to your PC’s USB port. It synchronises its time with your PC – and ultimately an internet time server – when your PC is on to maintain accurate timekeeping. It can also operate on its own using battery back-up and has user-selectable display modes. A LL RECENT PC OPERATING systems, including Windows, provide services for NTP (Network Time Protocol), a protocol that’s used to synchronise your PC’s local time with an internet time server. This USB Clock in turn synchronises with your PC’s clock and provided you boot your PC regularly (and synchronise it to an internet time server), it will maintain accurate timekeeping. 18  Silicon Chip In operation, the USB Clock is powered via the PC’s USB port when the PC is on. This also charges an internal NiMH battery. This battery powers the clock when the PC is off or when the clock is disconnected from the USB port. When the PC is off, the clock’s timekeeping is maintained by a 32.768kHz watch crystal. This is accurate to within ±20ppm, giving a timekeeping accuracy of better than two seconds a day in stand-alone mode. Control software By now, you’ve probably guessed that the LCD USB Clock is based on a microcontroller. In this case, we’re using a PIC18F4550 micro to provide all the necessary functions. In addition, a small command-line program (usbclock.exe) is used to siliconchip.com.au change the USB clock’s settings and to synchronise the clock’s time with your PC’s clock. This will be described next month. We’ll even show you how to set-up your Windows operating system (using an entry in the Start-up folder) to automatically synchronise the USB Clock to the PC’s clock each time the machine boots. That way, you can install the software and forget it. In fact, this system will even take care of daylight saving time shifts. When your PC automatically adjusts for daylight saving it automatically adjusts the USB clock as well (when it is next synchronised). Display modes This clock doesn’t just tell the time. Oh no! – that would be far too easy. Because it’s got a microcontroller, we can do all sorts of other stuff as well, such as displaying the time in either 24-hour or 12-hour format, displaying the date, displaying the charging current or the battery voltage and having the display scroll. Basically, there are 12 different display modes and Table 2 shows the complete list. So how do we step through these different display modes? Well, you can either do it by repeatedly pressing the front-panel pushbutton switch (S1) or you can use the usbclock.exe program. For example, if you press the switch once, the backlight comes on. Press it again and the LCD shows the day and the month in DD:MM format (ie, mode 1). Press it again and the display steps to mode 2 to show the year and so on. As stated, there are 11 display modes in all, the last two bringing up scrolling displays. Mode 9 scrolls the time and the date, while mode 10 scrolls the time only. Prefer to control the clock via your computer’s keyboard instead? No problem – just type usbclock.exe -z:X at a command prompt, where “X” is a number between 0 and 11, depending on the mode you want displayed. Want to display the date? Type usbclock -z:1. Want to display the battery charging current? Type usbclock -z:4. Once the selected mode has been displayed, the display automatically reverts to the default display mode at the end of a preset time-out. This preset time-out has a default value of siliconchip.com.au Main Features • Automatically synchronises its time with your PC and by extension, an internet time server. • Internal rechargeable battery to keep the time while disconnected from the PC. • • • 4-digit LCD with optional dimming LED backlight. • • • Low-power CMOS design for extended battery life. All settings are changed by connecting to a PC. Can display supply voltage and battery charge status, as well as date and time. Automatic backlighting mode. Displays time in either 24-hour or 12-hour format. 30 seconds but this can be changed if you wish. Naturally, you can also change the default display mode if you want. For example, you might want the LCD to shows the date (mode 1) by default instead of the time (mode 0). We’ll talk more about this in Pt.2 next month. Backlight display modes An optional LCD backlight module allows the display to be read in the dark. There are three different userselectable modes for this backlight: (1) Backlight always on mode: in this mode, the backlight is always on when the clock is plugged into a USB port. (2) Automatic mode: the backlight automatically switches on between 6pm and 6am (ie, between 1800 and 0600 hours), which means that the backlight automatically switches on at night. Note: the unit must be connected to a USB port for this mode to operate. (3) Pushbutton only mode: in this mode, the backlight comes on for a preset time only when the front-panel pushbutton is pressed. The default time is five seconds but this can be set for longer periods if necessary. When the clock is operating from battery power, only the third backlighting mode (ie, pushbutton mode) is available. In addition, the backlighting function is automatically disabled if the battery discharges below a preset voltage. This is done to conserve battery life and maintain timekeeping when no USB power is available for extended periods. The current drain without backlighting is typically below 1mA. This increases to about 200mA when the backlight is on at 100% duty cycle. How it works Fig.1 shows the complete circuit of the LCD USB Clock. As can be seen, it consists of a microcontroller (IC1), an LCD and a bit of supporting circuitry. The LCD is driven via two D-type octal transparent latches (IC2-IC3). These latches are needed only because there are not enough I/O pins available on the microcontroller. In operation, the microcontroller loads a 16-bit word into the latches to drive the segments of the LCD. Just how the LCD is driven is explained in some detail later in the article. Power for the circuit is derived from the USB port on the computer and is fed to pin 1 (+V) of a USB Type B socket. This pin is nominally at +5V although in practice it can be anywhere between 4.75V and 5.25V, ie, 5V ±5%. Advanced Constructors Only This project uses a number of surface-mount ICs (including the microcontroller) which means that very good soldering skills are necessary in order to build it. In addition, you may have to fiddle with your PC’s firewall (if you use a third-party firewall) and the one on your modem as well, to get your PC to synchronise with an internet time server. As such, we regard this project as being suitable for advanced constructors only. October 2008  19 Pin Function Details 1 VPP Programming voltage (typically 13V) 2 PGC Programming clock signal 3 GND Ground reference 4 GND 5 VDD Ground reference Supply voltage (typically 5V) 6 PGD Programming data signal Table 1: this table shows the pinout of the ICSP (in-circuit serial programming) header CON1. It can be used to program IC1 in-circuit using a programmer like the dsPIC Programmer featured in the May 2008 issue. Other programmers like Microchip’s PICKit2 can also be used, by connecting the pins appropriately. Diode D1 provides reverse polarity protection for the USB Clock’s circuitry. It also ensures that, when the PC is switched off (but the USB cable is left connected), the battery cannot discharge back into the PC’s USB port. When USB power is applied, the supply rail sits at about 4.4V. This is sufficient to power the circuit and to trickle-charge the three AAA NiMH cells used for back-up battery. The 4.4V supply rail is bypassed using a 47mF electrolytic capacitor. Two 3.3W resistors connected in parallel (to give 1.65W) are used to limit the charging current through the battery. In addition, the voltage across these resistors is directly proportional to the charging current and this voltage is applied via a 15kW resistor to the AN1 (pin 20) input of IC1. As a result, the applied voltage is digitised and the resulting value then used by the firmware to detect when the USB cable is disconnected. When that happens, the battery supplies power for the clock and the AN1 input sits at a small negative voltage with respect to ground. The 15kW resistor in series with the AN1 input limits the input current to avoid damage to this input, while the 100nF monolithic capacitor is used to bypass the applied voltage signal. The other 100nF capacitors are used to bypass the main supply rail, while the 220nF capacitor is used to bypass the output of IC1’s internal 3.3V regulator at pin 37 (this is used to run the on-board USB transceiver). Crystal clocks A 20MHz crystal (X1) is used for the USB system and as the system clock. This crystal is connected between pin 30 & 31 of IC1, while the two associated 15pF capacitors provide the correct load to ensure that the oscillator starts reliably. An internal PLL multiplication stage and division stage are then used to derive a 48MHz clock which is used by the USB system. Crystal X2 is a standard 32.768kHz watch crystal (32,768 = 215) and is used for timekeeping. Its tolerance is less than 20ppm (parts per million) and it gives quartz watch accuracy, typically a second or two per day (or a minute per month at worst). However, this is only relevant if the USB Clock is not synchronised regularly with the PC. The two associated 22pF ceramic capacitors provide the correct loading for this crystal. Measuring the supply voltage As mentioned above, IC1’s VUSB pin (pin 37) is the output of the microcontroller’s internal 3.3V voltage regulator. This output is fed directly to the AN0 ADC input at pin 19. Since this voltage sits very close to 3.3V, this allows the microcontroller to measure its own supply voltage. This can be used to detect a low voltage condition and thus disable the backlight operation accordingly. Backlight circuit Display Mode What’s Shown On The LCD 0 Time is shown as HH:MM (hours:minutes) with the colon toggling at 2Hz (eg, 22:25 indicates it is 10:25pm). 1 Date is shown as DD:MM (day:month) (eg, 17.07 indicates 17 July). 2 Date is shown as YYYY (year) (eg, 2008 indicates the year 2008). 3 Time is shown as MM:SS (minutes:seconds) with the colon toggling at 1Hz (eg, 25:59 indicates 25 minutes and 59 seconds past the hour). 4 Battery charging current is shown in amps (eg, C.074 indicates 74mA). 5 Supply voltage is shown in volts (eg, b4.48 indicates 4.48V). 6 Battery charge state is shown in % (eg, b100 indicates 100% charge). 7 Shows the current backlight PWM Duty cycle as a percentage (eg, P080 indicates 80% duty cycle). 8 The current state of the USB enumeration is shown as a number (eg, Usb6 indicates the clock is CONFIGURED and ready to receive data). 0: DETACHED state      4: ADDRESS PENDING state 1: ATTACHED state         5: ADDRESSED state 2: POWERED state         6: CONFIGURED state 3: DEFAULT state 9 The time and date are shown as a scrolling string. 10 The time is shown as a scrolling string. 11 Displays firmware version (eg, F1.00 refers to version 1.00). Table 2: the USB Clock has 12 display modes as listed here. You step through them by repeatedly pressing switch S1 or by using the usbclock.exe program. 20  Silicon Chip The backlight consists of four LED pairs connected in series (note: these are part of a complete module). This is preferable to a parallel connection because it ensures that the LEDs have exactly the same current flowing through them at all times, thus ensuring equal brightness. The downside of a series connection is that you need a much higher driving voltage, in this case around 16V since the forward voltage drop of each LED pair is around 4V. This stepped-up voltage is derived using IC4 which is an LM3519 “High-Frequency Boost White LED Driver”. In operation, IC4 works from a supply rail as low as 2.7V and can generate a constant 20mA through the LEDs. A 3.3mH RF choke, Schottky diode D3 and the 4.7mF & 22mF bypass capacitors complete the backlight driver. The brightness of the backlight is controlled via the enable (EN) input (pin 1) of IC4 using PWM (pulse width modulation) from pin 36 (CCP1) of IC1. The PWM frequency generated by IC1 is around 30kHz and the duty-cycle siliconchip.com.au 2008 3 2 35 32 38 39 19 37 22pF 15pF Vss 6 29 CCP1 RD0 RC6 RC7 RD4 RD5 RD6 RD7 RB0 RD3 RB1 RB2 RB3 RB4 RA2 RD2 Vss 25 26 27 17 15 13 16 12 18 36 40 44 1 2 3 4 5 8 41 9 10 11 14 21 RA5 24 23 RA4 22 RA3 RE0 RE1 RE2 PGD PGM ICPGD PGC RD1 AN0 VUSB T1oscIN T1oscO OSC2 MCLR ICPGC IC1 PIC18F4550 OSC1 D+ D– USB CLOCK 220nF 22pF X2 32.768kHz 15pF 31 30 43 42 2x 3.3 4a (LCD p21)/4b (IC2 p9) 4f (LCD p22)/4c (IC2 p8) 4g (LCD p23)/4d (IC2 p7) 3b (LCD p24)/4e (IC2 p6) 3a (LCD p25)/DP3 (IC2 p5) 3f (LCD p26)/3c (IC2 p4) 3g (LCD p27)/3d (IC2 p3) COL (LCD p28)/3e (IC2 p2) 2b (LCD p29)/DP2 (IC3 p9) 2a (LCD p30)/2c (IC3 p8) 2f (LCD p31)/2d (IC3 p7) 2g (LCD p32)/2e (IC3 p6) 1b (LCD p34)/DP1 (IC3 p5) 1a (LCD p35)/1c (IC3 p4) 1f (LCD p36)/1d (IC3 p3) 1g (LCD p37)/1e (IC3 p2) 100nF K 15k 4 3 6 2 A 1 S1 11 1 7 6 5 4 GND LE D0 D1 D2 D3 D4 D5 D6 D7 2 3 4 5 6 7 8 9 IC3 74HCT573 8 A K D2: 1N4148 Vcc 4.7 F 16V DP2 10 3 DP3 4 EN GND LE D0 D1 D2 D3 D4 D5 D6 D7 2 3 4 5 6 7 8 9 GND 2 Vout LEDrtn IC4 LM3519 SW 5 A A IC2 74HCT573 Vcc 4 3 K K 22 F 16V K   A 100nF OPTIONAL BACK LIGHTING LED MODULE 10 19 18 17 16 15 14 13 12 O0 O1 O2 O3 O4 O5 O6 O7 20 Vcc OE D3 1N5819 11 1 Vcc D1, D3:1N4004, 1N5819 1 Vin 3.3 H 6 COL 9 10 11 12 13 14 15 16 17 18 19 20 19 18 17 16 15 14 13 12 O0 O1 O2 O3 O4 O5 O6 O7 20 Vcc OE 3 2 1 DP1 2 : 8.8.8.8 1 Fig.1: the circuit of the LCD USB Clock is based on a microcontroller (IC1) and a 4-digit LCD readout. Power comes from the USB port of a PC or from a 3.6V rechargeable NiMH battery. IC4 and its associated circuitry are used only for the optional backlighting feature. SC  4 1 X1 20MHz USB TYPE B SOCKET 20 RA5 AN1 RA4 A NC 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 COM1 COM1 RA2 CON1 NC RB4 5 RA5 1f 1e RB3 15k D2 RA2 1a RB2 – RA4 1b 1c 1d RB1 Vdd RB4 2g 2e Vdd RE0 NC 1g NC NC DP1 100nF RB3 2f 2d 3x 15k RB2 2a 2c 100nF RB1 2b DP2 28 RD7 COL 3e RB0 7 RB0 3g 3d RD7 47 F 16V RD6 3f 3c RD6 K RD4 3a DP3 RD5 D1 1N4004 RD5 3b 4e RD4 Vcc RC7 4g 4d RC7 3.6V BATTERY CON + 2 RD2 4f RD2 NC RE0 RC6 4a 4b 4c RC6 siliconchip.com.au October 2008  21 4 L1* LK1 220nF 1 CON1 2 LK6 LK7 LK8 5 6 LK9 – + IC1 1 PIC18F4550 (TQFP-44) IC4* 12 D3* LCD MODULE 100nF 100nF 23 34 1 22 F* 3.3 3.3 04110081 LK2 LK3 15k* + 15k 15k 3 2 4.7 F* D2 15k LK5 1 LK4 X2 D1 BACKLIGHT SOCKET* K 3 3.3 H 15k 100nF 4 Fig.2: follow these layout diagrams to install the parts on the top side and on the underside of the PC board. The parts marked with an asterisk are installed only if the optional backlighting is required (see text). 1 1 IC2 74HC573D 15pF 22pF + 18001140 X1 47 F USB TYPE B SOCKET IC3 74HC573D 15pF 22pF + 100nF CON2 TOP OF BOARD UNDERSIDE OF BOARD These two photos show the fully-assembled USB Clock module from the top (left) and bottom (right). is set by the firmware. In particular, the firmware automatically reduces the duty-cycle (and thus the backlight brightness) if it detects that the battery is “buckling” under the load. Note that IC4’s “shutdown” current is less than 1mA, making it ideal for battery-powered applications. Pushbutton switch Six-way header CON1 is used to connect pushbutton switch S1 between pins 12/16 of IC1 and ground. Pins 12/16 are normally pulled high via a 15kW pull-up resistor but are 22  Silicon Chip pulled low each time S1 is pressed. This switch is used to turn on the backlighting and to step through the different display modes (see Table 2). In addition, CON1 can also be used to program the microcontroller in circuit (ie, it also functions as an ICSP header). ICSP (in-circuit serial programming) is a vital requirement for any SMD microcontroller, as these are more difficult to program out of circuit than standard through-hole parts. If you purchase the USB Clock as a kit, the microcontroller will be preprogrammed and so you will not need to use this connector. By contrast, the “home-brew” constructor can use this connector to program the microcontroller using the hex file that’s available in the October 2008 download section of the SILICON CHIP website. The ICSP pin connections for CON1 are shown in Table 1. The other header, CON2, is used to connect the rechargeable battery pack (3 x 900mAh AAA NiMh cells). Driving the LCD The firmware is responsible for all the clock functions, as well as driving siliconchip.com.au This photo shows the fully-assembled PC board before installation of the backlight and the LCD. Note the foam blocks which are used to support the backlight. the LCD. In operation, the display segments are driven by a square wave with a frequency of about 25Hz. A segment is on whenever its driving signal is out of phase with the backplane signal (at pins 1 & 40). Conversely, a segment will be off whenever its driving signal is in phase with the backplane drive. The segment contrast is proportional to the RMS of the voltage applied to the segment relative to the backplane. Basically, we need 33 driving signals (28 for the LCD’s four 7-segment digits, four for the decimal points and the colon and one to control the backplane). In this circuit, however, the microcontroller (IC1) drives the display segments using just 18 lines. It does this by driving 16 segments directly, while the other 16 segments are driven by loading two 8-bit bytes (ie, from the same microcontroller outputs) into D-type octal transparent latches IC2 & IC3. This latching occurs very quickly (within nanoseconds), thus ensuring that the segment drive is very close to 50% duty cycle. This is important to minimise the DC offset across the LCD segments, as excessive DC offset can destroy this kind of display. Fig.3: the 20-pin socket strip for the backlight is modified by removing the pins indicated in red. The pins are removed from the 20pin socket strip by cutting them off flush using sidecutters, as shown at left. The photo above shows the modified socket strip. Pin 27 of the microcontroller provides the LCD’s backplane signal. This directly drives pins 1 & 40 of the LCD. a custom Microchip driver (MCHPUSB). Each time the host program on the PC sends a 64-byte packet, the microcontroller in the USB Clock decodes it (according to the sent command) and updates its settings accordingly. The time is sent as a time data type, consisting of the hours, minutes, seconds, day of the week, day of the month, day of the year and year. In addition, the microcontroller keeps an internal record of the last Full-speed (12Mbps) USB2.0 Another job of the firmware is to service the USB2.0 port. Endpoint 0 is implemented, as that is mandatory for any USB device. Endpoint 1 is implemented as well and uses 64-byte data packets. These packets are used to communicate with the host program (usbclock.exe) on the PC via Table 3: Resistor Colour Codes o o o siliconchip.com.au No.   4   2 Value 15kW 3.3W 4-Band Code (1%) brown green orange brown orange orange gold brown 5-Band Code (1%) brown green black red brown orange orange black silver brown October 2008  23 Backlight & LCD Options If you decide to omit the back­light, use the reflective LCD module from Jaycar (Cat. ZD-1886). Reflective LCD modules reflect the polarised ambient light to create the contrast for the segments. However, they do not let light pass through from underneath and are therefore unsuitable for backlighting. If you do wish to have a backlight, you must use a trans-reflective LCD module instead (eg, Farnell Cat. 1989340). A trans-reflective LCD module differs from a reflective module in that it lets some light pass through from underneath, thus making it suitable for backlighting. The specified reflective and trans-reflective modules are pin-for-pin compatible, so either will work in this circuit. They are both 4-digit static LCD displays that consume very little power and so are ideal for battery-powered applications. The backlight plugs into the modified centre socket strip, so that it sits directly under the LCD. successful synchronisation with the host. If the packet is successfully transmitted, the USB Clock sends a 64-byte packet back to the host program. It contains information on all the relevant settings of the USB Clock and these can be accessed by running the usbclock. exe program with the information option (ie, by typing usbclock -i). We’ll explain how to use the command line program usbclock.exe to communicate with and synchronise the USB Clock next month. This program can also be used to change various default settings. Construction Building the USB Clock requires good soldering skills, since a number of SMDs (surface mount devices) are used. However, the SMDs used have a relatively large pin spacing, so the job should still be relatively straightforward. All the parts are mounted on a single PC board coded 04110081 and measuring 63 x 78mm. Fig.2 shows the parts 24  Silicon Chip layout and wiring details. Note that those parts marked with an asterisk are installed only if you intend fitting the optional backlight. Note also that if the backlight is fitted, you will need to use a transreflective 4-digit LCD, as specified in the parts list. Begin by inspecting the PC board for hairline cracks in the tracks and for shorts between closely-spaced tracks. That done, start the assembly by installing the wire links. There are nine of these, including one under the righthand side of the LCD. Use tinned copper wire for the links. It can be straightened by clamping one end in a vise and then stretching it slightly by pulling on the other end with a pair of pliers. The resistors go in next. Table 3 shows the resistor colour codes but you should also check each one using a DMM before soldering it into circuit. The three diodes are next on the list. Note that these are all mounted vertically on the board. Make sure that all the diodes are correctly oriented and note that that D1 is a 1N4004 while D3 ia a 1N5819. The 3.3mH RF choke (L1) can now be soldered into place. This also mounts vertically on the board. It looks like the resistors, so don’t get it mixed up with these parts (it should have a very low DC resistance). Now fit the four ceramic capacitors (2 x 15pF & 2 x 22pF). These are all located immediately to the left of the USB socket. Once they’re in, install the five monolithic capacitors (4 x 100nF & 1 x 220nF) and the three electrolytics. Make sure that the electrolytics are all correctly oriented. Follow these with the two crystals (X1 & X2). The 32.768kHz watch crystal (X2) has very delicate leads so be careful with these. This crystal should be mounted so that it sits horizontally on the PC board. Secure X2 in place with a small dab of silicone to prevent it from moving and fracturing its leads after it has been installed. Cutting the IC sockets The next step is to cut the two 40-pin IC sockets in half to obtain three 20-pin strips (the remaining strip is discarded). Two of these 20-pin socket strips are used to mount the LCD while the other is used to mount the backlight module. We recommend that you can leave part of the middle connecting bar on the top socket strip (see photos) to provide support for the backlight module. The two socket strips for the LCD module should now be soldered into position. siliconchip.com.au This life-size view shows the completed unit before the lid is fastened into place. Take care to ensure that the LCD is the right way around and be sure to install the battery with the correct polarity. The socket strip for the backlight module can now also be mounted but first you have to remove a number of pins. This is done by snipping them off using side-cutters, as follows: beginning on the left, remove two pins, then leave one, remove two, leave two, remove two, leave two, remove two, leave two, remove two, leave one, remove two (ie, 12 removed in total). Fig.3 shows the pattern. The modified socket strip can then be soldered into place. We also suggest adding a couple of foam pads as shown in one of the photos to provide additional support for the backlight module. Once these socket strips are all in place, install the USB socket and the 6-pin and 2-pin headers (CON1 & CON2). That completes the top of the PC board, apart from plugging in the backlight module and the LCD. Leave these two components out for the time siliconchip.com.au Soldering In The Surface-Mount ICs The PIC microcontroller (IC1) is mounted by soldering pins 21 & 22 (topright of IC1) first. Any solder bridges between pins (eg, as indicated by the red circles in the centre photo) can be cleared using solder wick. The photo at right shows IC3 & IC4 mounted position while above is a close-up of IC4. Make sure that all ICs are correctly oriented. October 2008  25 Parts List 1 PC board, code 04110081, 63 x 78mm 1 Type B USB socket (Jaycar PS-0920; Altronics P-1304) 1 Deluxe Hand Held Case, 79 x 117 x 24mm, with battery compartment (Altronics H-8976) 1 transreflective 4-digit + colon LCD (Farnell 1989340)*, OR 1 reflective 4-digit + colon LCD (Jaycar ZD-1886) 1 20MHz crystal, HC49US case (X1) (Jaycar RQ-5299) 1 32.768kHz watch crystal, ±20ppm (X2) (Altronics V-1902) 1 SPST momentary pushbutton switch (S1) (Jaycar SP-0656) 1 3.3mH RF Choke (Jaycar LF1516, Altronics L-7016)* 2 40-pin DIL IC sockets 1 6-way header, 2.54mm pitch (CON1) 1 2-way header, 2.54mm pitch (CON2) 3 900mAh (or better) NiMH AAA rechargeable batteries with solder tabs (Jaycar SB-1724) 1 50mm dia. x 300mm length of Thermotite heatshrink (Jaycar WH-5580) (for battery pack) 1 Type A to Type B USB cable (Altronics P-1911A, Jaycar WC-7700) 2 header plugs (2.5mm pitch) (RS Components Cat. 311-6209) 1 120mm-length of medium-duty hookup wire (red) 1 120mm-length of medium-duty hookup wire (black) being. They go in after the four SMD ICs have been installed. Soldering the SMD ICs The four SMD ICs (IC1-IC4) are installed on the copper side of the PC board – see Fig.2. To install them, you will need a soldering iron with a finepointed tip, some very fine resin-cored solder, a pair of self-closing tweezers and a good light. A magnifying lamp is also handy or failing that, a magnifying glass so that you can inspect the soldered leads for possible shorts. Begin by installing IC2 & IC3, the two 74HC573D latches. These have a larger pin spacing than IC1 and so are 26  Silicon Chip 1 30mm length of 0.7mm tinned copper wire 4 6g self-tapping screws Semiconductors 1 PIC18F4550-I/PT microcontroller (TQFP44 package) programmed with 0411008A (IC1) (Farnell 9321365) 2 74HC573D octal D-type transparent latch (SO20 package) (IC2-IC3) (Farnell 1201326) 1 LM3519MK-20 LED driver IC (SOT-23 6 package) (IC4) (Farnell 1312717)* 1 LTR24S360-4YG LED backlight module (Farnell 1208878)* 1 1N4004 diode (D1) 1 1N4148 Signal diode (D2) 1 1N5819 Schottky diode (D3)* Capacitors 1 47mF 16V electrolytic 1 22mF 25V electrolytic* 1 4.7mF 16V electrolytic* 1 220nF monolithic 4 100nF monolithic 2 22pF ceramic 2 15pF ceramic Resistors (0.25W, 1%) 4 15kW 2 3.3W 1 15kW* Footnote Parts marked with an asterisk (*) are required for the optional LCD backlighting only. a good place to start. First, position IC2 on the PC board and “clamp” it in place using the selfclosing tweezers (or a clothes peg). Check that it is correctly oriented (ie, with pin 1 positioned as shown on Fig.2), then carefully solder pin 10 to its pad. Now do the same for pin 20 which is diagonally opposite. The IC will now be firmly anchored in place and you can remove the tweezers and carefully solder the remaining 18 pins. Repeat this procedure for IC3, then move on to IC1 (the PIC microcontroller). IC1 is slightly more difficult to install because its pins are closer to- gether. As before, take care to ensure that it is properly oriented and clamp it accurately in position before soldering its pins. In this case, the best pins to solder first are pins 21 and 22 at top right (see photo). These are soldered to the same pad, so they’re easier to deal with. After that, solder pin 1, then remove the clamp and solder the remaining pins. The trick here is not to apply too much solder. Use it sparingly and be sure to solder each pin quickly. You don’t want to apply too much heat for too long, otherwise you could damage the IC. Don’t worry if you get solder bridges between adjacent pins at this stage – just move onto the next pin and keep going. After you’ve finished soldering the 44 pins, you can remove any solder bridges using solder wick. This is done by laying the wick along the pins and then applying the soldering iron to the wick to “suck” up the excess solder (see photo). IC4 (LM3519) can now be installed. It’s quite small and comes in a 6-pin SOT-23 package. Once again, make sure it is correctly oriented before soldering its pins. Pin 1 is adjacent to the chamfer along one edge of its body (see Fig.2). In practice, it’s easiest to solder pin 6 first, since its PC pad is larger than the others. The remaining five pins can then be carefully soldered. It’s now a good idea to carefully inspect each IC with a magnifying glass to make sure that everything is correct. In particular, look for solder bridges and for pins that haven’t been soldered. Note: for further information on soldering SMDs, refer to the feature article in the March 2008 issue of SILICON CHIP. LCD & backlight installation Now that the ICs are all in place, install the backlight module into its IC socket strip, then fit the LCD module. Take care with the orientation of the LCD – pin 1 goes to bottom left. Making the battery pack The battery pack consists of three NiMH AAA cells with solder tabs. These are connected in series as shown in Fig.5 to give an output of 3.6V. To make up the pack, first lay two siliconchip.com.au batteries together side-by-side but facing in opposite directions. Solder their tabs together, then sit the third battery in the channel formed by the first two and solder its tabs. It’s then just a matter of adding the output leads (red for positive, black for negative) and using some heatshrink to secure the cells into a pack. The output leads are terminated in a 2-pin header and this should be fitted before the leads are connected to the battery. Warning: be careful not to short any of the cell terminals or the output leads. NiMH batteries can supply lots of current. Fig.4: switch S1 connects to pins 2 & 4 of CON1 via a 2-pin header plug. TO CON1 VIA 2-PIN HEADER PLUG PIN 2 S1 PIN 4 Fig.5: the battery pack is made up by connecting the NiMH cells in series. Use heatshrink sleeving to secure the cells together in one pack. AAA NiMH CELL TO CON2 VIA 2-PIN HEADER PLUG + AAA NiMH CELL – AAA NiMH CELL Final assembly The assembly can now be completed by installing it in the specified case. As shown in the photos, the PC board is secured to integral stand-offs in the bottom of the case using four 6g self-tapping screws. The battery sits in a separate compartment and is plugged into CON2 but don’t do that just yet. Next, you will have to drill a hole in the lid of the case for the switch and cut out a window for the LCD. The front panel artwork shown in Fig.6 can be used as a drilling template (either copy the artwork from the magazine or download it from the SILICON CHIP website and print it out). Once you have the artwork, attach it to the front panel using double-sided tape, then drill the hole for the switch. Use a small pilot drill to begin with, then carefully enlarge it to 10mmdiameter using a tapered reamer. The window for the LCD is best made by drilling a series of holes around the inside perimeter. The centre-piece is then be cut out using a small hacksaw and the job filed to a smooth finish. The drilling template should now be removed and a new front-panel artwork printed out. This should be protected by covering it with some wide strips of clear adhesive tape before cutting it out and attaching it to the front panel. It can be affixed using double-sided tape or by using a thin smear of silicone sealant. nated in a 2-way header which is then plugged into pins 2 & 4 of CON1. MODE 10mm BACKLIGHT 51 x 23mm LCD CUTOUT USB CLOCK SILICON SILICON CHIP CHIP www.siliconchip.com.au Fig.6: this full-size artwork can be used as a drilling template. Cut out the holes in the front panel label using a sharp hobby knife, then mount the switch in position and attach a couple of 100mm-long flying leads. These leads are then termi- Testing Assuming IC1 is programmed, apply power by plugging the battery pack into CON2. Be sure to connect the battery the right way around, as there is no on-board protection against a reversed battery connection. As soon as you apply power, the LCD should show a default time of 12:00, assuming that the battery is charged. If the battery isn’t charged, then you will have to apply power by plugging the USB Clock into the USB port of your PC. The clock should then briefly flash the word “SYnc” and then repeat this every 15 seconds, indicating that it hasn’t been synchronised. If it does that, then it is working correctly and the lid can be attached. It’s now simply a matter of installing a driver plus the usbclock.exe program on your PC and then running the program to synchronise the USB Clock. We’ll describe just how this is done in Pt.2 next month. We’ll also show you how to synchronise your PC to an internet time server and describe how to run usbclock.exe automatically each time SC your PC starts. Issues Getting Dog-Eared? Keep your copies safe with our handy binders Available Aust, only. Price: $A14.95 plus $10.00 p&p per order (includes GST). Just fill in and mail the handy order form in this issue or ring (02) 9939 3295 and quote your credit card number. siliconchip.com.au October 2008  27