RGB LED Control

randomcows

New Member
I basically need some advice on the viability of the project which I'll describe below. I'm not brilliant at electronics but I'm picking stuff up pretty quickly, and I'm also not brilliant at explaining things, so please bear with me :]...

Ok, I want to control 54 RGB LEDs (Or 162 LEDs, 54 of each Red Green & Blue, won't look as good but much cheaper than proper integrated RGB LEDs). Ideally I want to be able to address each LED individually to set the colour anywhere in the colour spectrum.

I had a look at http://www.picaxeforum.co.uk/showthread.php?t=9747 and it appears that it would be possible using pulsout on various outputs to create a PWM type effect. The problem with this is that 54 LEDs would require at least 6 expensive 28X1 PICAXEs, using my ingenious (although I'm sure someone has done it before) method of connecting all the LEDs to the same 3 outputs for RGB, then having the 4th cathode or anode leg of each LED on its own output so I could cycle through the LEDs rapidly whilst changing the RGB pulses to create the colours. I wasn't too sure on the speed of the chips, although it had quite a bit of flicker on a PIC08, I'm sure would work fine/with less flicker on a faster 28X1.

I discovered an IC today which I think may solve the problem and only require a single PICAXE for the whole project. I may have misunderstood it's use however, so this is the part where hopefully someone with a bit more knowledge can help out...

Using the 74HC164 IC (8bit serial-in parallel-out shift register) in a big 24 chip daisy chain (apparently possible), would it be possible to use just a single output on the PIC chip (a 28X1 or 40X1 because I need the 20 inputs) to send a serial *pulse* every 10ms or so to create a pwm effect. Say with 5 LEDs, using 2 74HC164 chips, sending something like RGBRGBRGBRGBRGB with a 1 or 0 value -lets call it 101001011111011- would create Magenta, Blue, Cyan, White, Cyan would it not? (Just as a note I think the daisy chaining is done through the 8th bit as it were, so 2 chips gives 7+8 =15 outputs)

My hope is that sending the *pulse* will be fast enough that the lights wont flicker and will be able to show the full spectrum, but I only require 6 unique colours for this project so if worst came to worst, just having Red, Green, Blue, Cyan, Magenta, Yellow (or White) would be fine. Flicker also doesn't matter too much, it's an A level project, I need something to evaluate at the end ;]

I hope I've made enough sense for someone to work out if the arrangement using a single PICAXE with the shift registers would actually work, thanks in advance to anyone who can :]

--Mike
 

Dippy

Moderator
The point of PWM to produce colour perception is that the frequency is fast enough to have that effect on the eye. And that, for a given frequency, th duty cycle can be varied such that the brightness appears to change but not flash.

Using shift registers at 10mS is SO slow that you would end up wth a pile of flicker.
I'm sure you realise that pulsing a shift register just makes it bobble along one at a time, so to get the on/offs of a line of 54 would take 54 clocks before the correct array is completed. And this would have to be repeated to get a duty cycle effect very rapidly.
I'm not even sure if a 10 microsecond clock would be fast enough.

And, by the way, from bitter experience, some of these devices flicker more than others as it bobbles along (sometimes contrary to text in Data Sheets!!). I've done simple bar graphs using this technique (with a BS2) and some looked awful.

I'm sure the method is OK if 1000x faster, but I think you may have to look again at a method to do this if you want it to look pretty. I really think you are going to struggle with speed unless you can find a special controller ic.

If I've misunderstood your plan then ooops, post a neat sketch of your proposed idea.
Picture, thousand words etc....
 

randomcows

New Member
I think you have basically understood it, but by sending the pulse every 10ms, I meant updating the whole thing that often. The trouble is I have no idea how fast serout is, having never actually used it. How long would it take to send 162 bits, is that to do with the baud rate? Presumable a baud rate of 4800 means at least 4800 bits per second (the magic of wikipedia tells me that baud rate is symbols per second, not bits, but I'm sure it's close enough for a rough calculation...) 4800/162 = 30ish, so a *refresh rate* of 30Hz if I'm not mistaken, minus a few for other processing times on the PIC... I'm guessing 30Hz would have some flicker, but that would be solved by what I stated earlier about just using 6 colours, so each of the three colours is either on or off, rather than pulsing them to get every colour...

I may just buy a few chips from rapid to play with, I've got an 18X from my GCSE project left over (thanks btw to those who helped me with it, the simon says game - it worked for a while but on the day before it was due in was resoldering a motor because the joint was dry, and somehow the PIC died ]:, bought a new PIC a few months ago but will probably need to get a new board made due to my extremely rushed soldering efforts...)

Anyway back on topic... If I buy 12 chips or something and some LEDs to have a play, it'll be under 10 quid, as long as my school has some breadboards (moved schools a year ago, this one doesn't get £200000 grants to buy engineering equipment ]:)

One final question, do the shift register chips keep their values until cleared and updated? Or is it a momentary thing?

I'll get a neat sketch drawn up, you probably don't want me to upload the 15 pages of mess I've drawn so far ;]

Thanks for the reply,
Mike
 

Dippy

Moderator
I've never tried the method you are using, so I'm running on reading the Data Sheet.

When you send data to the HC164 you send data and a clock pulse. So, two things are required.
Unless someone has a clever technique, I can't see (at the moment) how you can just send Serout data.
If you look at a Serout 'byte' on a 'scope you would see ups and downs i.e. highs and lows.
But remember 2 lows in a row, for example, just visually look like a long low. There is no little pulse you can use as clock.
So, you have to clock the shift register with a separate pulse. The clock tells the Shift register to 'look now'.
If you held the S/R input low and clocked it (i.e. pulsed it) 3 times the S/R would read that as 3 lows.
It would appear then that you will have to provide clock pulses synchronised to your Serout.

You may be able to do that with the PWM PICAXE pin but I'm not sure how you would synch it up.
When I did it I used a (slow but sure) bit banged approach so I knew exactly when the start was and could send the data bit and clock pulse at the right times on 2 separate PIC pins.

But you seem to be forgetting something (or I haven't understood it).
You are hoping to change colours based on RGB. So the individual R,G,B LEDs will have to change intensitiy.
I know you know that. And you also know that the easiest way is by PWM.
So, not only do you have to get the data out quickly, but also repeatedly and switch them on/off for different periods. And so fast that the eye perceives this as intensity as opposed to flicker. The S/R can bang out things quickly as its all hardware, but I reckon you'll have big problems getting PICAXE Serial Out to run fast enough.
I have no doubts you can get the LEDs operating but not sure about the flicker factor especially as shift registers will flicker as the Data is loaded.
What you really need is to load the data then enable the outputs. I don't know what device can do that.
I think a little more hunting for a suitable component is needed or , maybe, cut down the number of LEDs.(or cut down your expectations:))

"One final question, do the shift register chips keep their values until cleared and updated? Or is it a momentary thing?"
- they keep them until updated or you trigger the MR reset.


It's a nice project and I wish you all the best.
 

randomcows

New Member
Ok how about this...

Btw I haven't actually mentioned but the project is an electronic Rubik's Cube, basically 6 sides, 9 lights per side, and then 12 buttons per side to control direction (there is only actually 18 *directions*, 6 each for X,Y & Z axis).

As far as I understand from what you've said, I could have 3 LEDs making up one RGB unit, this gives 162 LEDs which I can control with the shift registers. I only need 6 colours as it's a standard 6 sided cube, so I don't actually need PWM effect (that was just in the hope of making it look cool, but is probably too complex for me to do at the moment). Instead I have the option of 7 colours, Red, Green, Blue, Red+Green=Yellow, Red+Blue=Magenta, Green+Blue=Cyan, Red+Green+Blue=White. These don't need PWM, just simple on or off at any one time.

I hadn't understood the need for the clock signal, but if I do use the 2 output bit banging method it wouldn't take more than a second or two to send out all 162 bits would it?

Then I could have a transistor switch or a relay (isolating all the lights from the 0V rail) to momentarily turn off the lights whilst it was updating to *hide* the flicker. On startup, the program could read an array of the values, setting the right outputs, then would only have to update if a button was pressed, at which point (depending on the button pressed) the values would *move* around the cube. If you imagine the cube, pressing a button affects 5 faces maximum, 4 of which actually change in value and 1 which would rotate the values, I could do this with three extra variables to hold the first three values until all the others had been shifted up by three, then add the first values as the new last values.

That probable makes no sense, so I'll explain it a bit better...
Lets call the sides A,B,C,D,E & F shown below as a cube net..
__A
E_B_F
__C
__D

If a button on a column between A&B, B&C, C&D or D&A was pressed, the values of that column in A would go to D (or vice versa), and the other sides would shift up. If it was one of the edge columns, E or F would also be affected, but only in a rotational sense.
Say side F will be affected...
1 2 3
8 9 4
7 6 5

Depending on the direction the side is moving (clockwise or anticlockwise), 1 will become 8, 2 becomes 1, 3 becomes 2 etc etc or in the opposite direction 8 becomes 1 and so on. 9 will always remain the same if the side is rotating. This would require one extra holding variable.

In short, when a button is pressed (not including the middle columns), 4 variables additional to the 21 affected variables will be needed, just as temporary holding whilst the other values are shifted, either by 3 (switching sides) or by 1 (rotating face).

Updating these values shouldn't take more than a second, then sending out the data, providing it's not too slow by the bit banging method, would mean after pressing the button the lights would go off for 2/3 seconds then return with the new configuration...

It's the best I can come up with at the moment, please let me know if there are any major flaws in this plan...

I've been working on some diagrams, not quite done yet though

Thanks again,
Mike
 

Dippy

Moderator
Oh well that makes life easier. I'm sure it would be fast enough for that to look OK.
Yes, a transistor for the 'light enable' sounds good.

The coding is your job :) enjoy. Quite a bit of planning required and quite a drop of code.
And it'll be an impressive project when you finish it.
All the Best.
 

randomcows

New Member
Many thanks for the help, it was much appreciated and probably stopped me trying to do something stupidly complex :p

I think with the coding, I could use the scratchpad as a kind of array. For instance on startup, I would populate the values for each side from original values which will be hardcoded (as in what colour each side is). Then it would be a matter of a separate routine for each button, which hopefully will just about fit on the chip. 12 routines each handling 25 variables and 6 routines handling just 12.

Should be fine, it wont be the most efficient code ever but I've still got about 7 months to complete and improve it ;]

Mike
 

randomcows

New Member
Just ordered some samples :] (5 of 'em just because I could, along with 2 temperature sensors and an analogue switch thing, no relation to this project, also just because I could, although the temp sensors I can probably find a use for :] ) I'll let you know when I get them and how I get on. The slight problem is that I blew my PIC08 today whilst testing a number of programs :S Think maybe I'm too static :p Playing with it on the sofa in my lounge probably didn't help...

I do have an 18X but it's on a custom board which will be a pain to get working with this so I might have to wait until I put in my next Rapid order for some new chips...

-Mike

BTW: This project now uses 9 RGB LEDs, I'm making a single sided Rubik's cube, where you can switch faces using arrow buttons. It's cheaper to make and I can say it's a feature "makes it more challenging". Ahh the joys of A Level Product Design ^^
 
Last edited:
Top