8 channel RGB controller – car Christmas lights
1.
Introduction
This device is an 8 channel RGB controller provided as
Christmas lights for a small Christmas tree (e.g. for use in a car or motor
home). It provides control over 8 RGB strips (each containing max 9 RGB LEDs),
i.e. color and dimming. This is achieved with 24 software PWM channels.
This circuit is based around the PIC24HJ128GP504 microcontroller.
This chip is actually a small computer contained in a single chip, including
RAM memory, EEPROM, I/O ports, CPU and
so on. When you buy this chip, it comes empty with no program on it. You have
to compile the source code and download the resulting machine code into it, using a PC and a small
programmer attached to the PC and the chip. To get yourself familiar with this
stuff, I suggest you first read this link: Getting started with microcontrollers.
2.
Description
To control 8 RGB channels concerning intensity and
color, 24 PWM channels are necessary. The PIC24HJ128GP504 does not have that
many. Therefore we will use ordinary I/O ports and provide the PWM functionality
by implementing it in software, using the Timer1 interrupt.
The device has as many as 32 programs to select the
RGB pattern.
3.
Usage
The device is operated with a single pushbutton, to
select the program. The selected program number is shown on a simple binary
display consisting of 5 LEDs.
When powered, program 0 is executed. Press the button
to advance to the next program. Program 31 is a random combination of program 0
to program 30.
This is what is shown on the “display”:
_ _ _ _ _ program 0
_ _ _ _ X program 1
_ _ _ X _ program 2
_ _ _ X X program 3
_ _ X _ _ program 4
_ _ X _ X program 5
_ _ X X _ program 6
_ _ X X X program 7
_ X _ _ _ program 8
_ X _ _ X program 9
_ X _ X _ program 10
_ X _ X X program 11
_ X X _ _ program 12
_ X X _ X program 13
_ X X X _ program 14
_ X X X X program 15
X _ _ _ _ program 16
X _ _ _ X program 17
X _ _ X _ program 18
X _ _ X X program 19
X _ X _ _ program 20
X _ X _ X program 21
X _ X X _ program 22
X _ X X X program 23
X X _ _ _ program 24
X X _ _ X program 25
X X _ X _ program 26
X X _ X X program 27
X X X _ _ program 28
X X X _ X program 29
X X X X _ program 30
X X X X X program 31
4.
Connection
Connect 8 RGB LED strips to the PCB, and connect a 12V
DC power supply to the DC-in connector:
Below a picture of one LED strip, wounded as a spiral around
a piece of PVC tube (diameter 16mm):
Notice that for connecting a LED strip to the PCB I
designed my own type of connection. On the LED side, this is an L-shaped
combination of 3 male and one female header, on the PCB side, it is an L-shaped
combination of 3 female and one male header:
5.
Schematic
diagram
The main diagram:
Below is a block diagram that shows how the 8 RGB LED
strips, the button, 5-LED display and power are to be connected:
This diagram shows the design of the user interface
(button and LED display, only one of the two buttons is actually used):
6.
Explanation of the schematic
diagram
(Refer to the main schematic diagram).
Two voltage regulators are used: one to produce a
stable 12V for the LED strips, the other to produce 3.3V for the PIC.
The schematic shows 24 resistors and 24 transistors
which drive the LEDs (8 channels x 3 for red, green, blue = 24 ports in total).
An ICSP (In Circuit Serial Programming) interface is
provided by means of PAD35-36-37.
The 5-LED binary display connects to PAD40-41-42-44-45.
PAD39 is for future extension.
PAD43 connects to the pushbutton.
7.
The
printed circuit board
Main PCB
The pcb is designed for smd components.
It is double sided and designed with Eagle (from Cadsoft).
The PADs for the LED strips are supposed to hold
headers which can be soldered on the PCB with or without drilling a hole.
Notice there is no space for the ICSP connector, this
should just be a separate header connected with 5 wires to the correct PADs.
PDF file (top, mirrored) to print on a transparent: Print-layout
PDF file (bottom) to print on a transparent: Print-layout
Link to Eagle file brd file containing the PCB..
LED display
PCB
This is a small PCB to fit the 5 LEDs for the binary
display and the pushbutton. It is designed for SMD and single sided.
PDF file (mirrored) to print on a transparent: Print-layout
Link to Eagle file brd file containing the PCB..
Connectors PCB
This is just an aid to produce the connectors for the
LED strips, it contains 8x 4 pads which must be drilled and fitted with
headers. This PCB is single sided, non-SMD.
PDF file to print on a transparent: Print-layout
Link to Eagle file brd file containing the PCB..
8.
The final device
Below some pictures of the final device.
The first version of the PCB looks a bit messy,
because there were errors and patches had to be applied:
The PCB is put inside the flowerpot that comes with
the Christmas tree:
The user interface, for the case I used an SD-card box:
The Christmas tree with the LED strips:
9.
Programming
The software is written entirely in C (using the C30
compiler from Microchip).
The functions for the LED programs are called “program0()”
to “program31()”. You could write your own versions of these functions to
acquire your needs.
A “programXX()” function describes one iteration of a
LED program. The main loop takes care of repeating so don’t repeat yourself.
If you want to write your own “programXX()” functions,
the most important functions you might need are:
- SetPwm(port,
intensity) – sets the intensity of a port (0..23 where 0 = LED1 red, 1 = LED1
green, 2 = LED1 blue, 3 = LED2 red and so on) to a certain value (0..63 where 0
= 0% and 63 = 100%)
- SetColor
(ledNbr, color) – sets the color of a LED (1..8) to the specified RGB value
(0xRRGGBB where RR, GG and BB are a hex value between 0..0xff).
You also will need the delay_ms() function. Use
delay_ms() to delay a specified number of milliseconds. This function will
return instantly when the button is pressed.
It is advisable to regularly check for the pushbutton
being pressed inside your “programXX()” function, especially after a delay, in
order to return instantly to the main loop for button processing. This can be
done with “if (PUSHBUTTON == 0) return 0;”.
For programming you need the Microchip MPLAB X IDE and
the C30 compiler. Both can be downloaded for free from the MPLAB X IDE site.
You also need some programming hardware: the Microchip PICkit3 programmer.
Zip file containing all source code, header files and
project files: Link to MPLAB project.
Connection to a PIC programmer.
PADs 35-36-37, ground and +3V3 should be connected
(during programming) to the PICkit3 programmer (refer to the datasheets of both
the PICkit3
and PIC24HJ128GP504
for proper connection).
Home Back to Electronic
Projects