Silicon ChipProgrammable Christmas Star - November 2006 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Do people really want a high-performance valve amplifier?
  4. Review: Sony Alpha A100 Digital SLR Camera by Barrie Smith
  5. Review: JVC KD-AVX2 Car Entertainment System by Julian Edgar
  6. Project: Build A Radar Speed Gun, Pt.1 by Jim Rowe
  7. Project: Build Your Own Compact Bass Reflex Loudspeakers by Aaron Waplington
  8. Project: Programmable Christmas Star by David Meiklejohn
  9. Review: Bitscope BS310 Mixed Signal Oscilloscope by Peter Smith
  10. Salvage It: Using the convex lenses from car headlights (bike light) by Julian Edgar
  11. Project: DC Relay Switch For High-Current Loads by John Clarke
  12. Project: LED Tachometer With Dual Displays, Pt.2 by John Clarke
  13. Project: PICAXE Net Server, Pt.3 by Clive Seager
  14. Vintage Radio: Radio Corporation’s WS108 military transceiver by Rodney Champness
  15. Book Store
  16. Advertising Index
  17. Outer Back Cover

This is only a preview of the November 2006 issue of Silicon Chip.

You can view 37 of the 112 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.

Items relevant to "Build A Radar Speed Gun, Pt.1":
  • PCB patterns for the Radar Speed Gun (PDF download) [DOPPLR1A/DOPPLR1B] (Free)
  • Radar Speed Gun front panel artwork (PDF download) (Free)
Articles in this series:
  • Build A Radar Speed Gun, Pt.1 (November 2006)
  • Build A Radar Speed Gun, Pt.1 (November 2006)
  • Build A Radar Speed Gun, Pt.2 (December 2006)
  • Build A Radar Speed Gun, Pt.2 (December 2006)
Items relevant to "DC Relay Switch For High-Current Loads":
  • PCB pattern for the DC Relay Switch (PDF download) [05211061] (Free)
Items relevant to "LED Tachometer With Dual Displays, Pt.2":
  • LED Tachometer Control PCB [05111061] (AUD $10.00)
  • LED Tachometer Display PCB [05111062] (AUD $5.00)
  • PIC16F88-I/P programmed for the LED Tachometer [ledtacho.hex] (Programmed Microcontroller, AUD $15.00)
  • PIC16F88 firmware and source code for the LED Tachometer [ledtacho.hex] (Software, Free)
  • PCB patterns for the LED Tachometer (PDF download) [05111061/2] (Free)
  • LED Tachometer display mask (PDF download) (Panel Artwork, Free)
Articles in this series:
  • LED Tachometer With Dual Displays, Pt.1 (October 2006)
  • LED Tachometer With Dual Displays, Pt.1 (October 2006)
  • LED Tachometer With Dual Displays, Pt.2 (November 2006)
  • LED Tachometer With Dual Displays, Pt.2 (November 2006)
Items relevant to "PICAXE Net Server, Pt.3":
  • PICAXE-28X BASIC source code for the PICAXE Net Server (Software, Free)
Articles in this series:
  • PICAXE Net Server, Pt.1 (September 2006)
  • PICAXE Net Server, Pt.1 (September 2006)
  • PICAXE Net Server, Pt.2 (October 2006)
  • PICAXE Net Server, Pt.2 (October 2006)
  • PICAXE Net Server, Pt.3 (November 2006)
  • PICAXE Net Server, Pt.3 (November 2006)
  • PICAXE Net Server, Pt.4 (December 2006)
  • PICAXE Net Server, Pt.4 (December 2006)

Purchase a printed copy of this issue for $10.00.

Star of wonder, star of night! Star of royal beauty bright; westward leading, still proceeding, guide us to thy Perfect Light. Programmable Christmas Star Features H Light enough to hang on the Christmas tree or in a window H Cycles through hundreds of pre-programmed patterns H User programmable (with optional PIC programmer) H Programmable display rate H Patterns can be looped H Twinkle effects H Battery powered H Turns itself off after 3 hours by David H Low component count siliconchip.com.au Meiklejohn November 2006  41 I n November 1998, SILICON CHIP published a very popular Christmas Star project, based on an Atmel microcontroller. Recent advances in microcontroller technology mean that this new design, based on a single 8-pin PIC micro, has considerably fewer components and can run from a pair of 1.5V batteries. As it is also easier to build and you can re-program it if you want different patterns, we believe this new Christmas Star will be even more popular than the original! It runs through a programmed pattern sequence, held in EEPROM on the PIC. With a suitable PIC programmer, such as Microchip’s low-cost PICkit 2, it is possible to load a new sequence into the EEPROM without affecting the underlying code. There’s no need to understand PIC programming to create your own display sequence! How it works Fig. 1 shows the complete circuit, such as it is! It consists of little more than the pre-programmed PIC12F683I/P microcontroller, 20 LEDs and a few resistors. Typically, to control a large number of LEDs using a small number of output lines, the LEDs are arranged in a matrix, say 5x4 for 20 LEDs, with transistors driving each row and/or column. That was the approach taken for the previous Christmas Star project, but not this time! So how do we drive 20 LEDs with an 8-pin PIC and five resistors? Here’s the Christmas Star, actual size, from the front. Each “arm” has the same colour run of LEDs – blue, green, yellow and red, with single white LEDs between.This shot was taken with the LEDs flashing, hence some colour shown. It’s not quite as dramatic as the photo earlier, taken in near darkness! It’s made possible through a technique known as “Complementary LED Drive”. It relies on two factors: 1: LEDs will only conduct (and therefore produce light) when a highenough forward voltage is applied. If the voltage is too low, or reversed, they simply won’t light up. 2: The PIC12F683 has Tri-state outputs. That is, they can be set high (nearly 3V in this circuit), low (close to 0V), or placed into a highimpedance input state, effectively disconnecting them from the circuit (“off”). Further, the outputs can either source or sink current, up to 25mA. As an example, consider what happens when the PIC is configured with pin GP5 high, pin GP0 low, and pins GP1, GP2 and GP4 Tri-stated (disconnected). Current will flow from GP5 47Ω K LED5 A 1 Vdd 10k 3V BATTERY 100nF LED1 GP5 4 IC1 GP4 PIC12F683 MC GP2 GP1 S1 GP0 Vss 8 SC 2006 2 3 5 6 7 47Ω A A K LED6 A LED9 K LED11 K A K LED7 A LED10 K LED12 λ K A A K LED8 LED4 47Ω K λ A λ A K λ LED15 A λ λ LED16 K K LED18 K A λ A LED17 A LED20 K λ λ K λ λ K A λ K K LED14 λ λ A λ LED19 A K λ λ LED3 47Ω λ K LED2 47Ω LED13 A λ λ A A PROGRAMMABLE CHRISTMAS STAR K ALL LEDS A Because the PIC chip takes care of timing, sequencing and lighting the LEDs, the circuit is extremely simple. You don’t have to follow the LED colours used in the prototype but the patterns will obviously be different. 42  Silicon Chip siliconchip.com.au LED18 LED20 LED1 LED5 LED19 LED14 + BATTERY – 100nF LED17 47Ω 47Ω 10k IC1 PIC12 F683 S1 LED11 LED4 47Ω 47Ω 47Ω LED2 LED6 sa 3. mts 1 ir V h LED15 C LED13 ra tS LED16 LED3 LED7 LED12 LED9 LED10 LED8 About the only thing that you can do wrong when assembling the Christmas Star is to put a LED (or the PIC chip) in the wrong way, or to have a bad solder joint underneath. Otherwise it should be pretty much plain sailing, even for a complete novice! GP3 high until S1 is pressed, pulling the input low. The software polls for this at the end of each display cycle and if S1 is pressed, it puts the PIC into a low-power sleep mode. The PIC is then set to automatically wake up if the switch is pressed again. Debouncing is done in software, so there is no need for external debounce circuitry. Power is supplied direct from two 1.5V batteries. N cells were chosen because their size makes them easy to mount unobtrusively on the back of the board. But cheaper AAA cells will also fit, albeit a little less neatly. They’ll also last longer. Alkaline batteries will provide more than 50 hours continuous operation, and should last up to two years with the circuit in sleep mode (“off”). Finally, a 100nF bypass capacitor is used to smooth the power supply to the microcontroller. It helps to keep the PIC stable, particularly as the batteries discharge toward the PIC’s minimum operating supply voltage of around 2V. Construction through resistor R1, then LED19, returning through R5 to GP0. So LED19 will light up. Since LEDs are one-way devices, current can’t flow through LED20, so it stays off. But there are other paths for current to flow from GP5 to GP0. For example, via LEDs 9 and 10 in series. But these two LEDs in series are in parallel with LED19, which is conducting. Here’s where factor 1 (which we mentioned earlier) comes into play. The forward voltage across a conducting LED is roughly constant; for a red LED it is around 2V. The voltage drop across the series combination of LED9 and LED10 must be the same as that across LED19. So each of LED9 and LED10 will have a forward voltage of only a half that of LED19. If LED19 is turned on with a 2V drop, there will be a drop of only 1V across each of L9 and L10 – not enough to make them conduct. So they won’t light up. You’ll find many other possible paths for forward conduction; a particularly obvious one is the series combination of LED1, LED2, LED3 and LED4. Similar reasoning shows that the voltage across each is only a quarter that across the conducting LED19; not enough for them to turn siliconchip.com.au on. Similarly for other paths, such as the non-obvious LED13, LED16, LED17 combination. In fact, with GP5 high, GP0 low, and the other outputs disconnected, only LED19 will have enough forward voltage to light up. Using this technique, it is possible for five outputs to uniquely address up to twenty LEDs, with the limitation that only one can be turned on at once. To overcome this limitation, the software uses multiplexing to make it appear as though more than one LED is lit at the same time. The software displays patterns on up to four LEDs which are turned on in sequence, each for 200µs, at nearly 1250Hz, creating the illusion that the four LEDs are on at once. The remainder of the circuit is very straightforward. Resistors R1-R5 limit current to the LEDs. The current path to a given LED will always flow through two of these resistors, so the effective resistance in series with each LED is 94W. Assuming a 3V power supply, and a red LED with a forward voltage drop of 2V, LED current will be 10mA, well within the supply capability of the PIC. Switch S1 is used as an on/off switch. Resistor R6 holds the PIC pin The Christmas Star is built on a single-sided PC board, cut in the shape of an eight-pointed star. All components are mounted on this PC board, so construction is very straightforward. Firstly, if you’re not building from a kit, you’ll need to choose your LEDs. In the prototype, all the LEDs are clear, high-intensity types. Five colours were used: red, green, yellow, blue and white, arranged with four red LEDs forming an inner ring, then yellow, green and finally blue at the outermost of the big points and white LEDs used on the four small points. Of course, you can arrange the colours any way you want; after all, it’s your star! And the choice of high intensity or diffused types with a wider viewing angle is entirely up to you. About now, you may be wondering how it is possible to use blue, or indeed most high-intensity types, when they have a forward voltage higher than the supply voltage of 3V. In practice, they do run at voltages down to 2.5V or so; they’re just not as bright as they would otherwise be. At low voltages, they’re still about as bright as a “normal” LED; quite bright enough to light up nicely at night time! November 2006  43 Parts List – Programmable Christmas Star 1 pre-programmed PIC12F683I/P IC 20 5mm LEDs (see text for colours and types) 1 100nF monolithic capacitor 1 10kW 1/4W resistor 5 47W 1/4W resistors 1 6mm PCB tactile switch 1 N-cell battery holder with fly leads (or AAA – see text) 2 N-cell alkaline batteries (or AAA) Double-sided foam tape (to mount battery holder) These two shots show how the dual “N” cell battery holder fits on the back of the PC board, secured in place with double-sided foam adhesive tape or pads. Note that a “AAA” holder will also (just!) fit on the PC board and will give longer battery life than the “N” cells used in the prototype. Even so, you should expect about 50 hours of display from the pair of “N” Cells. By the way, don’t mistake the 1.5V “N” cells for 12V remote control batteries. They are not too dissimlar in size and 24V would create a whole different (brief!) display . . . An IC socket for the PIC is strongly recommended. Besides reducing the risk of damaging the chip, it means that later, if you acquire a PIC programmer, you have the possibility of creating your own display pattern. Begin by soldering in the resistors, then use one of the discarded resistor leads for the single wire link. Next comes the IC socket, the capacitor, the pushbutton switch and the LEDs. Take special care of the correct orientation of each LED. If you put any in backwards, the star will still operate, but the patterns will be wrong. Orientation is shown on the PC board silk-screen overlay. 44  Silicon Chip At this point you can test the circuit, with the IC socket empty, by putting the two batteries into the (not yet installed) battery holder, then putting the battery holder leads (ie 3V) across various combinations of pins 2, 3, 5, 6 and 7 on the IC socket. For each different combination, a single LED, specific to that combination, should light strongly. Note that it is possible, if you have used a range of LED colours, that you will see other LEDs light very dimly in addition to the single strong light. If so, don’t worry, you won’t notice that effect when the display is operating. If no combinations produce any light, use a multimeter to check that you’re getting 3V from the battery pack. If you see more than one LED light up strongly at once, you probably have one of them in backwards, or perhaps a solder bridge on the board. If one combination doesn’t produce any light, while others do, you probably have either a dead resistor or LED, or a soldering problem such as a dry joint. If all the LEDs check out OK, remove the batteries from the battery pack, cut the leads suitably short (15mm or so), thread them from the back of the board to the front through the hole above C1. Solder the wires back through the board in the normal way to the pads marked + and –, being careful of polarity! If you now reinsert the batteries, nothing should light up; if it does, you have a short somewhere. Next remove the batteries again and use double-sided foam tape to stick the battery holder to the bottom of the board (see photos at left). Finally, you’re ready to insert the microcontroller. Taking antistatic precautions (touch an earthed case first!), carefully insert the PIC into the IC socket, with the notch on the IC toward the capacitor. Make sure that none of the PIC leads are bent or skewed in the process. Now insert the batteries again and you’re finished! At this point, the Capacitor Codes Value (mF value)   IEC    EIA     Code    Code 100nF 0.1mF 100n 104 siliconchip.com.au The wires from the battery holder come up through the board from underneath, then solder back through the board in the normal way. This helps take the strain off the cables and pads. Where from, how much: Pre-programmed PIC 12F683:......... $12 Pre-programmed PIC + PC board:... $17 Complete kit of parts (including clear LEDs, excluding batteries):..... $39 All plus $5 post and packaging within Australia Contact details for ordering kits are: Via website: www.gooligum.com.au Or email: david<at>gooligum.com.au display may start by itself but more normally, the star will do nothing until you momentarily press the button. The display sequence should now start. Operation Very simple – push the button to start, and press it again to stop. But if you forget and leave the display running, the star will shut itself off after around 3 hours. If this happens, just press the button again to restart. Creating your own patterns Although the PIC source code has not been (and will not be) released by the author, the command codes which define the display patterns are held in unprotected EEPROM, which you can update, independently of the protected code held in flash memory, with a suitable programmer. You’ll find the information you need to reprogram overleaf. PIC programmer An excellent low-cost programmer is Microchip’s PICkit2, available from Farnell for around $65, or as part of a starter kit for $92. It comes with software that allows the PIC’s EEPROM to be updated without affecting the program code in flash memory. The new command codes can be typed directly into the PICkit2 EEPROM window and loaded to the microcontroller. But it’s very important to uncheck “Program memory”, so that the program code itself is not overwritten. See the screenshot at right. If you don’t uncheck this box (ringed in red above) when reprogramming your Christmas Star, you will overwrite the program itself, rendering the star useless! Resistor Colour Codes No. o 1 o 1 Value 10kW 47W siliconchip.com.au 4-Band Code (1%) brown black orange brown yellow violet black brown 5-Band Code (1%) brown black black red brown yellow violet black gold brown OVERLEAF: Pattern Sequence Command Codes and Pattern Definitions for those who want to re-program the patterns. November 2006  45 Pattern sequence command codes Code Command 0 Pause 1 - 91 Pattern Description All LEDs off. Use for a short pause between pattern sequences Display a pre-defined pattern of up to four LEDs which are on “at once”. For a list of and details of each pattern, refer to the next page. LEDs are lit, one at a time, in pseudo-random order, in quick succession to create an overall “twinkling” effect. 92 - 126 Twinkle Twinkle rate = (code-91)ms between changes. If the code value = 92, a different LED is lit every 1ms – you may think too fast for the eye to see. But due to imperfections in the “random” number generation, you’ll still see a shimmer at this maximum twinkle rate. 127 End of sequence 128 End loop For code = 126, the twinkling is at its slowest, around 29Hz. Marks the end of the programmed sequence. Not necessary if your display codes fill the whole EEPROM, as the interpreter will restart at the beginning if the end of the EEPROM is reached. Go back to first pattern in current loop – see below. Use this to create loops, to avoid having to fill the EEPROM with repeated sequences of codes to create a repeating effect. Instead, place a “start loop” instruction at the start of the sequence, and an “end loop” (128) instruction at the end. 129 - 191 Start loop Repeat count = code-128 EG. to repeat a sequence of patterns four times, you would place a code of 132 (= 128 + 4) before the first pattern code, and a code of 128 after the last. Note that nested loops are not supported. An “end loop” code will always return to the most recent “start loop”. Sets the display rate, i.e. the time spent displaying each pattern before moving to the next in sequence. It allows you to vary the speed of the display in different parts of the presentation. 192 - 255 Set Speed Freq = 1000000/[8192(256-pattern)] Hz The default display rate, if you don’t set your own speed, is 6.8Hz Max. freq. (code = 255) is 122Hz. Min. freq (code = 192) is 1.9Hz. As an example of how to put it all together, here’s some code to twinkle at a moderate rate for 10s, then turn off (pause) for 1s, then repeat: Code Comment 195 display speed = 2.0Hz 148 repeat following patterns 20 times (128+20=148) 101 twinkle at 101-91=10ms per change (100Hz) 128 end loop 0 pause (all off) 0 pause again – at 2Hz we need 2 pauses to make 1 second 127 end sequence (repeat from beginning) 46  Silicon Chip siliconchip.com.au Christmas Star Pattern Definitions Code Description LED 1 LED 2 LED 3 0 All off LED 4 Individual LEDs 1 1 only 1 2 2 only 2 3 3 only 3 4 4 only 4 5 5 only 5 6 6 only 6 7 7 only 7 8 8 only 8 9 9 only 9 10 10 only 10 11 11 only 11 12 12 only 12 13 13 only 13 14 14 only 14 15 15 only 15 16 16 only 16 17 17 only 17 18 18 only 18 19 19 only 19 20 20 only 20 Alternate LEDS - 4 per diagonal 60 SE 1 3 NW 1 3 3 10 15 5 61 SE 2 4 NW 2 4 7 8 16 18 62 NE 1 3 SW 1 3 14 19 2 11 63 NE 2 4 SW 2 4 13 20 6 9 64 SE 1 3 NW 2 4 3 10 16 18 65 SE 2 4 NW 1 3 7 8 15 5 66 NE 1 3 SW 2 4 14 19 6 9 67 NE 2 4 SW 1 3 13 20 2 11 Inner and outer - 2 per arm 68 SE arm 3 8 69 NE arm 14 20 70 NW arm 15 18 71 SW arm 2 9 Arms 21 SE arm 8 10 22 NE arm 14 13 23 NW arm 15 16 24 SW arm 2 6 7 19 5 11 3 20 18 9 Rings 25 ring 1 - inner 3 14 26 ring 2 - inner mid 7 13 27 ring 3 - outer mid 10 19 28 ring 4 - outer 8 20 29 Small points 12 4 15 16 5 18 1 2 6 11 9 17 Complimentary pairs 30 NS 1 12 31 EW 4 17 32 SE1 NW1 3 15 33 SE2 NW2 7 16 34 SE3 NW3 10 5 35 SE4 NW4 8 18 36 SW1 NE1 2 14 37 SW2 NE2 6 13 38 SW3 NE3 11 19 39 SW4 NE4 9 20 Inner and outer - 4 per diagonal 72 SE NW 3 8 15 18 73 NE SW 14 20 2 9 Middle LEDS - 2 per arm 74 SE arm 7 10 75 NE arm 13 19 76 NW arm 16 5 77 SW arm 6 11 Middle LEDS - 4 per diagonal 78 SE NW 7 10 16 5 79 NE SW 13 19 6 11 Inner and outer half arms - opposites on diagonal 80 SE inner NW outer 3 7 5 81 SE outer NW inner 10 8 15 82 NE inner SW outer 14 13 11 83 NE outer SW inner 19 20 2 18 16 9 6 Inner and outer half arms - perpendicular opposites 84 85 86 87 88 89 90 91 Half arms 40 SE inner 3 7 41 SE outer 10 8 42 NE inner 14 13 43 NE outer 19 20 44 NW inner 15 16 45 NW outer 5 18 46 SW inner 2 6 47 SW outer 11 9 Complimentary halves 48 SE NW inner 3 7 15 49 SE NW outer 10 8 5 50 SW NE inner 2 6 14 51 SW NE outer 11 9 19 Alternate LEDs - 2 per arm 52 SE 1 3 3 10 53 SE 2 4 7 8 54 NE 1 3 14 19 55 NE 2 4 13 20 56 NW 1 3 15 5 57 NW 2 4 16 18 58 SW 1 3 2 11 59 SW 2 4 6 9 16 18 13 20 SE inner NE outer SE inner SW outer NE inner SE outer NE inner NW outer NW inner NE outer NW inner SW outer SW inner SE outer SW inner NW outer 3 3 14 14 15 15 2 2 7 7 13 13 16 16 6 6 19 11 10 5 19 11 10 5 20 9 8 18 20 9 8 18 Commands 92-126 Twinkle Rate: (code-91)ms between changes 127 End of sequence 128 End of loop Go back to first pattern in current loop 129-191 Start loop Start of loop: repeat count = code-128 times 192-255 Set Speed Freq = 1000000/[8192(256-code)] Hz SC siliconchip.com.au November 2006  47