Go Down

Topic: RGB LED w/ PWM Control - TLC5940 vs 74HC595 (Read 3453 times) previous topic - next topic

pattobrien

Hi All,

In my project, I've been using a couple 74HC595's to control a couple RGB LEDs. In the next stage, I'm looking to utilize just under 16 RGB LEDs, all with ideally controllable brightnesses for each of the colors so that I can have a full range of colors. I don't need any fancy fading code, thats constantly updating the brightness of each LED, just a simple code to say LED1 is orange, LED2 is white, LED3 a dark purple, etc.

The problem with the 74HC595s right now is that my code is very time sensitive, and (from what I understand) in order to have the LEDs controlled at PWM frequencies, the Arduino needs to constantly send the PWM signal over SPI. That's why currently I could only have my code turn each color on or off (1 or 0) and then leave it until it's to be updated. This limits my colors to the basic 8 combinations for the three colors on each LED.

Today I came across the TLC5940, which has PWM built into it. This seems to fix all my issues with the HC595, as from what I can understand, I only need to tell the chip what PWM to set each pin to ONCE, which it'll remember and continuously control each LED at their respective PWMs until it receives an update from the Arduino. This eliminates the need to constantly update the chip with the Arduino. The fact that it's 16 channels instead of 8 is an added bonus.

I just wanted to verify all of this and that I understand the limits of each IC, and also see if there were any other pros / cons that I may have overlooked. Thanks in advance!

Pat

PaulRB

Have you looked into ws2812b leds? So much simpler!

Paul

Grumpy_Mike

Quote
I just wanted to verify all of this and that I understand the limits of each IC,
That is about right although there is some background processing that happens in the interrupts.

However, have you considered the PCA9685, it has an I2C interface ( less pins ) and is a true set and forget chip.

pattobrien

Have you looked into ws2812b leds? So much simpler!

Paul
Aside from not being practical for my exact specs (I have a certain LED in mind thats in the sized package that I need, among other things), I'd rather not pay so much money for something that I can do easily once I have the correct chip, especially with all the example codes for each of the ICs I mentioned.


That is about right although there is some background processing that happens in the interrupts.

However, have you considered the PCA9685, it has an I2C interface ( less pins ) and is a true set and forget chip.
The PCA9685 looked like the best solution, until I remembered that there will be too many devices on my I2C line to make it work. There are five address pins, which means 32 devices at a maximum. The most important part of my code is that I have Arduinos communicating with each other over the I2C protocol. There will be 12 Arduinos connected to each other, which unfortunately means (at 45 LEDs per Arduino) that there need to be more devices than there are available addresses.

I'm sure there's a potential workaround, but I've been working with LEDs and the 74HC595 for a while now so a little more complication isn't a problem at all... The TLC5940 obviously has more pins, but the schematics on the forums will make it plenty easy. But as far as the "background processing" that you mentioned, exactly what do you mean by that? Why would interrupts be involved? As long as it doesn't affect the timing of the code, that should be fine. Specifically, my code listens for button clicks / encoder changes (by interrupts), and sends messages over I2C when that event is caught. Only 3 of the six interrupts are used. As long as those executions can be made as soon as they happen, then any additional code is fine.

Thanks a lot for the help,

Pat

 

PaulRB

Pat, you know your requirements best, but for the record I doubt ws2812b leds would work out more expensive overall, and there is loads of example code around for them.

How about the other chips in the ws28xx familly?

Grumpy_Mike

#5
Nov 25, 2014, 08:53 am Last Edit: Nov 25, 2014, 08:53 am by Grumpy_Mike
You know it is rearly annoying when you ask for help and do not give the full information.
It is also annoying when you reject something on spurious grounds.
Sure you can have way more than 32 of those chips on one bus. How many do you want?

Paul__B

How about the other chips in the ws28xx family?
Or to be more precise, all the various LED assemblies available in different formats?

sean92128


You can control more led leads with the tlc5940nt, then that 74HC595.

Are your leds cathode or anode? Anode is the way to go and some cases the only way to go.


Check out: http://garycrowhurst.net/arduino/tlc9540

Check out the Arduino examples are very helpful.

pattobrien

Sorry for the delay, everyone. It's been a bit hectic around the holiday.

Pat, you know your requirements best, but for the record I doubt ws2812b leds would work out more expensive overall, and there is loads of example code around for them.

How about the other chips in the ws28xx familly?
I tried seeing if I could make the ws2812b fit in the space I need it to, but unfortunately it just does not seem possible. I was having a difficult time finding the other chips in the ws28 family, do you have any in mind that are multi-channel?

You know it is rearly annoying when you ask for help and do not give the full information.
It is also annoying when you reject something on spurious grounds.
Sure you can have way more than 32 of those chips on one bus. How many do you want?
I'm sure you're just living up to your name, but I find it interesting that you said it was annoying to not give all of my information - I figure I can write up a 100-page report and attach it here for you, or I can give you all of my I2C information when the topic moves to I2C, as I did. Please let me know if that's not the right approach.

I'm really not that savy when it comes to I2C, so how would one get more than 32 on one bus with only 5 address pins? There will be 12 arduinos connected to each other, so with about 48 LEDs per Arduino, I'd need 36 chips on the bus.

But following up with what you initially said, what would be the extra underlying programming with interrupts for the TLC5940 that you were talking about? I hate to keep pushing that, but as I said, my code currently functions well with all the LEDs on SPI, and if there are truly no real pros/cons to the TLC5940 vs the PC9685, it seems like it'd be easiest to stick with the SPI device, even though I'm sure the PC9685 would be easy to implement. This really stems from the fact that the timing of the I2C communication between the Arduino's is the most critical part of the code, so if I have more things communicating over the same protocol, I'll most likely have to retest and possibly rework the code.

Thanks again for all of the help!

Pat


Grumpy_Mike

#9
Nov 29, 2014, 09:40 pm Last Edit: Nov 29, 2014, 09:40 pm by Grumpy_Mike
Quote
I'm really not that savy when it comes to I2C, so how would one get more than 32 on one bus with only 5 address pins?
You wire them with fixed addresses for the first four address lines. You do this for as many batches of 16 chips as you want. With the fifth address line you wire each batch of 16 to a different Arduino output. Then these outputs are all set to say zero. When you want to access one batch of chips you set the Arduino output attached to A5 in that batch to a one and access that range of I2C addresses. In that way you can have as many batches of 16 chips as you want.

Quote
but I find it interesting that you said it was annoying to not give all of my information
By withholding some of the information you leave us unable to give you valid advice and so the advice we do give is useless. I find this annoying as you are wasting my time. I am sure others find that too.
 
Quote
I figure I can write up a 100-page report and attach it here for you
I am sure you could but 99 pages of that would be waffle. I used to be a Physics Lecturer ( Professor if you speak U.S. ) so I know what reports can be. I am sure you can summarises you system succinctly. 

Quote
if there are truly no real pros/cons to the TLC5940 vs the PC9685
Your choice but you have seen the data sheets. The PC9685 is much more flexible in when the LEDs are turned on allowing the power supply to better cope with the initial current surge.

 
Quote
what would be the extra underlying programming with interrupts for the TLC5940 that you were talking about?
It is in the libiary.

pattobrien

#10
Nov 30, 2014, 11:40 pm Last Edit: Dec 01, 2014, 12:13 am by pattobrien
You wire them with fixed addresses for the first four address lines. You do this for as many batches of 16 chips as you want. With the fifth address line you wire each batch of 16 to a different Arduino output. Then these outputs are all set to say zero. When you want to access one batch of chips you set the Arduino output attached to A5 in that batch to a one and access that range of I2C addresses. In that way you can have as many batches of 16 chips as you want.
That's an awesome work around, I see what you meant now. Unfortunately, doing so still seems like its going to yield more complicated results. For example, if two Arduinos are attempting to control a different batch of LEDs at the same time (I misspoke, since there are 45 RGB LEDs, that would be 9 TLC5940s per Arduino), then there will be a conflict. Of course I could rework the code to wait for all other Arduinos to finish their respective I2C processes, but then this adds delay and complication, which I can't afford as immediate I2C communication between Arduinos is extremely important. I hate to keep pressing this, but I2C is really the last route I'd want to go.

It is in the libiary.
I see what you mean now, the Blank and GSCLK timers/interrupts are very critical to it running properly, and the fact that my Arduino would have to constantly break code to send Blank signals is unacceptable. However, the fact that it uses SPI still makes it the most appealing, if I can find a work around for the timer/interrupts. I'm wondering if I could use some ATtinys that I have lying around to send GSLCK, Blank, and XLAT signals, with the former two being sent at the correct period (4096 pulses), and have all of the SPI data coming from the primary Arduino. The primary Arduino would have a latch pin to the ATtiny, which would tell the ATtiny to raise the XLAT signal after the current grayscale period. It seems complicated but feasible, from what I can gather from the data sheet, and if that could eliminate the need for my primary program to do the timer/interrupt work, that'd be perfect. Is this something I should inquire feasibility about in a separate thread? Regardless, I think I'll begin by getting a couple TLC5940s, PCA9685s, and some others that I've found while researching, since they're inexpensive and most likely good to have around.

Thanks again for the help,

Pat

Grumpy_Mike

If you have two Arduinos on the same I2C bus then you need a multi master library  which is not the same thing as the standard one. This will prevent tow masters talking on the bus at the same time. Slave I2C devices can not talk except to respond to requests from the master, so if the Arduion is a slave device it can not access other devices on the bus.

Go Up