WS2801 – 3 Channel PWM

The WS2801 is a 3-channel constant current LED drivers that is designed for controlling chains of RGB LEDs. The IC is controlled by a 2-wire serial control scheme that allows multiple WS2801 to be chained together. You can find the WS2801 in the link below. This demo code basically shifts out 24 bits (8bits per color) using a 2-wire protocol. This code only works for one WS2801. There is a object designed for multiple WS2801 already in the propeller OBEX. That design uses too many resources for use on my pinball machine so I wrote this to use as little resources as possible (no new cog).

The idea would be to have the WS2801 PWM a set of mosfets which would in turn be connected to the string of LEDs. This way you could light up a bunch of RGB LEDs without allot of CPU time taken from the Propeller. The Propeller only has to mess with the WS2801 when it needs to change the PWM signals.

Where to buy the WS2801.
Demo Driver


'Parker Dillmann
'The Longhornengineer
'www.longhornengineer.com

'WS2801 PWM Driver

'This driver is designed to control 1 WS2801 chip
'Usually setup the WS2801 so that it drives 3 mosfets which can control any number of RGB LEDs
'The purpose of this driver is to minimize cog time on the propeller and not waste a cog doing PWM work

'Call Init in your main program to setup the driver.
'Pass the CLK pin as an arguement.
'The driver assumes that the data line will be the next pin. 
'
CON
    
  _CLKMODE      = XTAL1 + PLL16X                        
  _XINFREQ      = 5_000_000

  Pin_Low  = 0
  Pin_High = 1

VAR

  byte CLK                

PUB Init(CLK_T)

  CLK := CLK_T

  DIRA[CLK] ~~
  DIRA[CLK+1] ~~

  OUTA[CLK] := Pin_Low
  OUTA[CLK+1] := Pin_Low
  
return

PUB Color(RED,GREEN,BLUE)

  repeat 8
    OUTA[CLK] := Pin_Low
    OUTA[CLK+1] := RED
    OUTA[CLK] := Pin_High
    RED := RED >> 1

  repeat 8
    OUTA[CLK] := Pin_Low
    OUTA[CLK+1] := GREEN
    OUTA[CLK] := Pin_High
    GREEN := GREEN >> 1

  repeat 8
    OUTA[CLK] := Pin_Low
    OUTA[CLK+1] := BLUE
    OUTA[CLK] := Pin_High
    BLUE := BLUE >> 1

  OUTA[CLK] := Pin_Low

return

One comment on “WS2801 – 3 Channel PWM

  1. Pingback: Propeller: WS2801 – 3 Channel PWM | The Longhorn Engineer