Wearable LED Christmas tree

DSC06987

XmasTree3

There are a lot of LED Christmas projects, I wanted something I could wear as a pin or necklace, this is the result. It is 2.5 inches (6.35cm) tall by 2 inches (5cm) wide. It is powered by a CR2032 coin cell battery and will run continuously for a month or more. I had built a larger though-hole version of this a few years back and used a Charlieplexed approach. I didn’t love the results, so this time I choose a direct drive approach. I used a PIC16F1509 using the internal clock running at 31khz, and I make heavy use of the Watch-Dog-Timer for timing tasks. When it came to writing the firmware, I got a bit tired of writing functions to do the various displays that I wanted and decided to take a different approach. The result was a small RISC (Reduced instruction set computing) type approach.

Instruction definition

INSTRUCTION SET

Bit Description
31 Port A, bit 7 — Not used
30 Port A, bit 6 — Not used
29 Port A, bit 5 — D1
28 Port A, bit 4 — D2
27 Port A, bit 3 — Not used
26 Port A, bit 2 — D6
25 Port A, bit 1 — Not used
24 Port A, bit 0 — Not used
23 Port B, bit 7 — D12
22 Port B, bit 6 — D10
21 Port B, bit 5 — D9
20 Port B, bit 4 — D8
19 Port B, bit 3 — Not used
18 Port B, bit 2 — Not used
17 Port B, bit 1 — Not used
16 Port B, bit 0 — Not used
15 Port C, bit 7 — D11
14 Port C, bit 6 — D5
13 Port C, bit 5 — D3
12 Port C, bit 4 — Not used
11 Port C, bit 3 — D4
10 Port C, bit 2 — Not used
09 Port C, bit 1 — D7
08 Port C, bit 0 — Not used
07 Opcode, Bit 1
06 Opcode, Bit 0
05 Delay, Bit 1
04 Delay, Bit 0
03 Count, Bit 3
02 Count, Bit 2
01 Count, Bit 1
00 Count, Bit 0

Each of the I/O ports on the PIC have some LED bits assigned, organized mostly to make board layout easier. The instruction reflects this by having a bit assigned for each bit in the I/O ports. This is wasteful in terms of bits, but easier define and faster to execute, the RISC approach. The opcode occupies the bottom bits of the instruction:

OPCODE DEFINITION

Value Description
11 Loop Counter: Set ports, delay, set loop counter to COUNT
10 Branch: Set ports, delay, branch back COUNT instructions, decrement loop counter
01 Repeat: Set ports, delay, clear ports, delay, repeat COUNT times
00 NOP: set ports, delay, advance to next

Each instruction can control any and all LEDs. Each instruction also calls for a time-delay which is used to set the WDT (Watch Dog Timer). To implement a time delay, the WDT is configured, the a PIC sleep instuction is executed. The PIC will go into low-power mode until the WDT triggers which wakes up the PIC.

DELAY DEFINITION

Value Description
11 16 Seconds
10 256ms
01 128ms
00 64ms

The firmware implements a simple state-machine that processes a table full instructons which allows me to easily define various visual effects. Because the processor is running at only 31khz, and during delays very low power consumption battery life is very good, easily a month with a fresh battery.