Practical PIC Projects

 

 

Serial Addressable RGB PWM LED Driver

 


Latest Developments

Testing 3 channel RC Servo driver code.


Tiny Pan & Tilt RGB LED

see video clip on YouTube


16 channel RGB LED driver board

 
 

More photo's


 


Overview

Ever since I made the serial controlled RGB LED PWM driver I've had many requests for an addressable driver.  Well I've finally got round to producing one.  The code is now completed and tested and the prototype boards are fully working.

The design process behind this project was to enable anyone with a bit of electronics knowledge to build an array of cheap RGB LED drivers that they can control from a PC without having to spend lots of money on expensive hardware, software etc. I specifically didn't want to go down the DMX512 route as there are hundreds of commercially available products out there; if you need DMX512 you probably won't be trying to build RGB controllers on the cheap (however, if you do check out this site for a DMX512 RGB LED).  The hardware for this project is designed around standard readily available parts and the serial interface uses a standard PC serial port and protocols.  You should be able to put together a single controller and get it hooked up to a PC for under £10 (assuming you have a PC)

I originally wrote the code to run on a 16F88 but subsequently converted it to run on a 16F690 as these are about 30% cheaper.  The '690 also has 2 extra I/O pins one of which has been used to enable the full version of the code to drive either common anode or common cathode 7-segment displays on the control panel.  I've  also taken the code for the free RGB PWM driver and ported it to the PIC 16F628A / 627A. Code and schematic can be found on this page.

The serial packet protocol is completely open so anyone can write their own software to control the drivers.  It is described in detail on its own page here.

During development I had an enquiry asking if the PWM output could control a servo.  I thought about this and came up with a three channel RC type servo driver that operates using the same serial control protocol. This makes it possible to put RGB Drivers and Servo drivers on the same serial bus and control them with a common command set.  Using the same algorithm that controls fading on the RGB driver, the three servos can be made to move at different speeds from one position to another autonomously.

I've deliberately kept the Microcontroller board separate from any LED driver electronics because the type of LEDs it could be used to drive, from low power 5mm LEDs to high power 3 watt star LEDs, are wide ranging and the potential applications enormous.  For the same reason, the control panel display on the full version is also optional and separated from the main MC board since it might be useful to some, while not to others.

While I primarily expect people to use a PC to send the control data to the drivers, there is a lot of potential for stand-alone controllers and interfaces using low-speed infrared or 433Mhz RF transceivers. In fact that's one of the reasons for providing operation at bit rates down to 1200bps.

As time permits I'm am working on additional LED driver circuits and looking at PCB layouts as well as the PC software side of things and I'll be making it available on this page.

If anyone can help out with PC software to share with other enthusiasts please contact me as I'm really struggling to find time to do all the work.

Update: Feburary 2008

I had intended to make two versions of the code available; a basic free version and a full feature version. I've given up on that so now the full feature version is available to download for free. 

The Full Version of both the RGB and Servo code can be download free of charge here

RGB LED PWM Driver Feature List for PIC 16F690   Full version
Full 8 bit 3 channel PWM @100Hz   a
Support for 128 device,  24 group and one broadcast address   a
On board colour fading   a
Serial receive bit rate 1200, 2400, 9600bps   a
Serial receive bit rate 19200, 38400bps   a
Change device address in software   a
Change serial bit rate in software   a
Jumper selectable active high or active low PWM output   a
Optional 7 segment LED display to inspect/change address and bit rate   a
Software shutdown / enable of PWM outputs   a
Automatic PWM output shutdown when serial data inactive   a
    Download

 

RGB LED PWM Driver Feature List for PIC 16F628A   Full version
Full 8 bit 3 channel PWM @95Hz   n/a
Support for 128 device,  24 group and one broadcast address   n/a
Serial receive bit rate 1200, 2400, 9600bps   n/a
Change device address in software   n/a
Change serial bit rate in software   n/a
Jumper selectable active high or active low PWM output   n/a
Software shutdown / enable of PWM outputs   n/a
     

 

RC Servo Driver Feature List for  PIC 16F690   Full version
3 channel RC Servo driver ~18mS refresh   a
Support for 128 device, 24 group and one broadcast address   a
On board servo slewing   a
Serial receive bit rate 1200, 2400, 9600bps   a
Serial receive bit rate 19200, 38400bps   a
Change device address in software   a
Change serial bit rate in software   a
Optional 7 segment LED display to inspect/change address and bit rate   a
Software shutdown / enable of servo channel outputs   a
Automatic servo channel shutdown when serial data inactive   a
    Download

Schematic

16F690
RGB LED PWM Driver Schematic
(use with zf690b.HEX )

see log

16F690
3-Channel Servo Driver Schematic
(use with zfservo.HEX )
see log

16F628A/627A
RGB LED PWM Driver Schematic
(use with zf628a.HEX)
see log

 

Prototype for software development work

 

Code development rig for 16F690 based SAD.  Three separate SADs built onto one board

Code development rig for 16F690 based SAD with user control panel

 

16 channel driver board

16F628A version

Testing code port for 16F628A

 

Possibly the worlds smallest pan & tilt RGB light?  I just knocked this together to demonstate the concept.
It uses a pair of HiTec HS-55 servos and a 5mm Piranha RGB LED

 


Description

The RGB Serial Addressable Driver (SAD) generates 3 x 8-bit PWM outputs at a frequency of ~100Hz.  The PWM outputs can be jumper selected to either active high or active low to suit different LED driver circuits.

The Servo Serial Addressable Driver provides three servo channel outputs with a 1-2mS pulse width refreshing at between ~16 and 19mS.

The SAD receives data over a standard RS232 serial interface like that found on a Personal Computer.  Data is sent to the SAD in 7 byte packets which contain either data or commands.  

The operation of the serial control protocol is a two step process.

1.  data is sent to the SAD which latches it but doesn't do anything else with it.
2.  a command is then sent to the SAD telling it to transfer the data to the outputs

This allows different data to be sent to many drivers while enabling changes to the PWM output to be initiated across the SADs simultaneously.  For example you might send 10 different colours to ten SADs, then sending a single transfer command to the broadcast address, the ten SADs all update their respective outputs with the new colour at the same time.  Any SADs receiving the transfer command that haven't been sent any new data ignore it.

To support the control of the SAD I've written a couple of applications that run under Windows.  The first is a menu-driven control program that is intended to aid test and initial configuration of the SAD.

The second application is a command interpreter that runs under Windows. It uses a simple command language which I've developed specifically to support the SAD.  Full documentation and file download can be found here.

When the firmware is first programmed into the PIC, the default address is 0 and bit rate is 9,600bps.It can be reset to these defaults at anytime by grounding RA3 (pin 2) while powering up the SAD.  On the full version with the control panel hardware, holding down SW2 while powering on will also reset it to defaults.

At power on, and after a save command restart, all three PWM channels are driven at ~4% for 2 seconds to indicate the SAD is active before turning off.

The packet protocol supports three addressing modes;  There are a 128 unique addresses from 0 to 127 which can be user assigned to the individual SADs.  A broadcast address which all SAD will accept packets from. Finally there is the Group addressing mode; each device has two group address, a row address and column address.  This is described in more detail on the Packet Protocol description.

RGB colour and fading data is sent to the SADs by one of the three addressing modes.  The SADs latch the colour data addressed to them but don't immediately drive the PWM output with it.  The data is only transferred to the PWM outputs once a Transfer Command has been received.  This allows multiple SADs to be loaded with different RGB data and then, using either a group, or broadcast address they transfer the new RGB data simultaneously to the PWM output.  The use of group and broadcast addresses for the transfer does not preclude the use of a Unicast address if needed.

The SAD can accept data at a continuous 38400bps which gives a maximum packet rate of ~548 packets/second.  It also supports data rates of 19200, 9600, 2400, 1200bps.  Both the address and bit rate can be changed by sending commands to the SAD over the serial interface.  The new settings don't take effect until they have been saved and the SAD reset. 

The full version of the SAD firmware also supports a control panel comprising a 3-digit 7 segment LED display and 2 switches.  This allows the current address, bit rate and auto-shutdown settings to be inspected and if required changed and saved.

The auto-shutdown feature will turn off the PWM outputs if no valid packets are received by the SAD within 260 seconds (4m20s). As soon as a valid packet is received the shutdown timer is reset and the PWM outputs restart.  The reason for this feature is that when I was driving a number of SADs from a PC, I wanted them to automatically shutdown their PWM outputs without having to turn them all off or remember to send a shutdown command to them before shutting down the PC.  By default this feature is inactive. It is also not available in the free version of the firmware.

Changes made to the address, bit rate or auto-shutdown settings will not take effect until they have been saved and the SAD reset.  The Save command automatically resets the SAD once the settings have been written to the on-board EEPROM (NVRAM)

The full version of the firmware supports autonomous colour fading.  The SAD takes the current RGB values being output and calculates the required step rates for each colour to reach the new RGB values at the same time.  The largest difference between current and new values determines how many steps are required for the fade.  The base step rate is 4mS and this is multiplied by the fade rate value sent to the SAD.

For example.  In the illustration below, the difference between the current and new blue values is clearly the largest so this is the primary step value.  If the current Blue PWM is 0 and the new PWM value is 250 the number of steps required is 250-0 = 250. With a fade rate of 1 it takes 4mS x 1 x 250 = 1.00 second to reach the new PWM. The red and green steps are calculated so that all three colours will arrive at the new values at the same time.

 

With larger fade rate values the number of steps remains constant but the base step rate of 4mS is multiplied by the fade rate value as the illustration below shows.  (4mS x 5 = 20mS)

The 4mS step rate was chosen because at the minimum fade rate of 1, a full fade from 0 to 100%  takes ~1 second.

If a fade is still in progress when a new fade command is received, the current fade is stopped and a new fade calculated based on the RGB PWM values currently reached when the new command was received.

Autonomous fading is not available in the free version of the firmware; SADs running the free version will use the RGB data in packets with a fade rate value >0 but set the fade rate to 0 and update the PWM output immediately.


Software

The PIC microcontroller needs programming before use.

Read disclaimer and conditions of use before downloading.