Hi, I am trying to make a POV using a TLC5940 and an ATMega168 with a 16Mhz ceramic resonator. I have built it all on a strip of PCB. I uploaded the BasicUse code to the ATMega, and it works! Yay
Although, I then load on the BasicAnimation code, and the LED's flash, then just sit there with maybe 9 or so LED's lit, and doesn't do anything.
So it works, but it doesn't??
Anyone know what could be happening? It's almost like it tries to start the animation, but then locks itself up somehow ...
So put some debug printing statements to see if it is running and what values it is using.
It would also help if you included a link to the code you are trying to use. However the odds are you have it wired up wrong.
I'm having a similar problem. I'm using an Arduino Mega with 3 TLC5940NTs. I've triple checked that everything is wired up correctly according to this diagram, using the pinouts for the Arduino Mega. I have 2.2k ohm resistors on each of the TLC's IREF pins, and approximately an 11k ohm pull-up resistor tied from high to the BLANK pin on the first TLC.
The only difference between that setup and mine is that I'm using 8 common anode RGB LEDs across the three TLCs (only using 8 pins of each TLC) instead of 16 regular LEDs across each TLC. All red leads go to the first TLC, all green leads to the second, and all blue leads to the third. The configuration and circuit diagram would be the same, so I don't see how this difference could be the source of problem.
Now for the problem details. When I run a sketch, as soon as Tlc.init() or Tlc.init(0) is called the LEDs come on, and the first 4 are red and the last 4 are yellow. If I call Tlc.init(4095) some LEDs are magenta, some are red and some are white. I can run a sketch looping through each channel and turning it high and low, which yields some results, but not the results that are intended. It's very strange behavior, suggesting that all of the TLCs are sinking current, even when they are initialized not to.
The odd thing is that when I was only using one TLC, everything worked fine. I have changed the NUM_TLCS to 3 in the tlc_config.h file, but even if I change it back to 1 I get the same problems. The whole issue seems to be a problem with daisy-chaining the TLCs as far as I can tell. Any ideas? Even on what else I should debug. Thanks.
First off I can't see any decoupling capacitors in this setup. You should have a 0.1uF between power an ground on each chip.
Next is is a matter of going through each TLC output one at a time. Write the code to light up one LED and one only. If it does not do as you think then that gets you something simpler to go and do the fault finding with.
Thanks for the response. Somehow I just knew you would suggest decoupling.
Well, I added 0.1 µF capacitors between Vcc and ground, and that at least made the intensities of the LEDs consistent. I went down to one TLC5940NT, and everything worked as expected. I added a second TLC5940NT, and I got a more easily describable problem this time. First off, current is being sunk on pins 5, 6, 7, 8 of the second TLC5940NT as soon as Tlc.init() is called, and the pins remain sunk until the end of the sketch. Next, when I set pins on the first TLC5940NT the previous grayscale data are shifted out to the next TLC5940NT in the daisy-chain. For example, when I run a loop lighting each LED one at a time, 1st iteration: pin-1 of TLC-1 is sunk, 2nd iteration: pin-2 of TLC-1 and pin-1 of TLC-2 are sunk, 3rd iteration: pin-3 of TLC-1 and pin-2 of TLC-2 are sunk, etc.
I'm beginning to think this is an issue with the TLC library. I am using an Arduino Mega, and the version of the library I am using was the first release that supported the Mega. I wonder if there aren't some bugs in it, yet. I downloaded the library here. I think it's the latest version available (r014). I might have to get in touch with aceleone if I can't get this figured out. I know he's registered on this site. It would be nice to know if anyone else has had success with this library on a Mega.
One other thing. I came across this thread earlier. I was having the same exact problems with brightness variations as these guys, and a 0.1 µF decoupling capacitor tied from Vcc to ground evened everything out. It worked almost too well, actually... kind of scary. :o I'm not used to things working out so well. Anyways, I just thought it would be a good idea to let someone know that decoupling was the solution to that problem, as neither of those guys really confirmed it in the other thread.
So in my attempts to figure this thing out I've created some new problems, solved them, and here I am stuck with the original problem I had. The TLCs work perfectly individually, but when I try to daisy-chain them, the second chip does not respond to its given commands as the library says it should. Once Tlc.init() is called, Pins 4 through 8 on the second TLC are constantly lit no matter what, and the data from the first TLC are shifted to the second no matter what. I can't control any LEDs individually past the ones on the first TLC.
Hopefully, someone can shed some light on what seems to be a simple problem.
In the meantime, here are some of my findings for anyone else working with the TLC5940 and Arduino Mega:
Decoupling each TLC with a 0.1 µF from Vcc (Pin 21) to Gnd (Pin 22) was necessary to even out the intensities of the LEDs. Don't quite believe everything they show you in the pictures on the Arduino Playground. Maybe decoupling capacitors aren't needed for that specific setup on a Duemilanov or Diecimila, but why not put them on there just to be safe? You'll most likely need them when you scale up your project anyways.
Tying a pull-up resisitor to the Blank pin may work fine in that initial setup, but be careful because you can overheat the TLC. I'm using an external power supply (5v 1amp regulated) to power my LEDs/TLCs, and I fried my only spare TLC by tying it high through a pull-up resistor to that supply. I can live with the flickering lights when the Arduino starts up; I can't live with any more burnt chips.
The Arduino Playground did have a vague warning about this in the "older information" section on that page, but it was easy to miss.
This last one is just some general information about power supplies. Be careful when using power from the Arduino's 5v and Vin pins. You can only pull 1 amp max through Vin, and the voltage regulator on the 5v pin can overheat if you aren't careful about what you're putting through it. Also, USB ports only have 5v and 500ma max available to use, so if you're powering the Arduino by USB, be aware of that. The recommended input voltage for the Arduino Mega is 7v to 12v. Supposedly less than 7v can make the board unstable (whatever that means).
I just tried this setup with an Arduino Duemilanove, and I get the exact same problem as before. So, the problem is definitely on my end.
Is there something I'm not understanding about the TLC5940 code library? I doubt it. Calling Tlc.init(0) should set all channels on the TLC to off. That's easy to understand. The library works for other people on the Duemilanove, and I'm not using it incorrectly.
Since the code is correct and the problem is reproducible on both of my Arduinos, that leaves me with a hardware issue: faulty chips or faulty wiring.
I've checked my wiring more times than I care to count, and the only things I've done differently are added decoupling capacitors and removed the pull-up resistor on BLANK. Both are optional and shouldn't affect how the TLCs function during a routine sketch.
That leaves faulty chips. I have 9 TLC5940NTs from Arrow electronics. I've changed out chips and I get the same problem. Unless the whole batch is faulty or somehow incorrect, the chips shouldn't be causing the problem.
So that leaves me with nothing. What am I overlooking here? Has anyone else had a similar problem? This is driving me nuts. It's a simple step by step process that works for other people, but not for me.
I'm not sure what you mean by bypassing the first TLC. The serial data seems to be coming out of the Arduino correctly if that's what you mean... well for the first TLC in a daisy-chain anyways. A serial connection from the Arduino to either of the TLCs works fine. But, when I daisy-chain them together,
Arduino -> SIN | TLC1 | SOUT -> SIN | TLC2 | SOUT
that's when I get problems. The first TLC always works how it should, the second one has 4 lights that always stay on and it otherwise mirrors whatever happens on the first TLC. Besides those 4 lights, it's like the data is shifted right out of the first TLC. But that's not how the library should work, at least how I understand it.
I was suggesting to run a jumper between SIN of TLC1 to SIN of TLC2, remove TLC1. This would verify the connections (SCLK, XLAT) are correct.
It has been a year since I worked with the TLC5940, but when I did I had no problem chaining together 3 of them. I was using a Duemilanove, not a Mega.
Ah, I see. Yeah, I've tried that already. I'm going to get some new ICs and see if that's the problem.
EDIT: Nope, tried the rest of my unused chips and still have the same issue. This is really weird. It's such a simple setup, there's not much room for error. I hate to blame it on a bad batch of chips, but I don't know what else it could be.
The chips and the library most definitely do support daisy-chaining. I've seen countless projects on the internet using my exact same setup and similar setups to achieve control of > 16 LEDs. Unless I've missed something blatantly obvious about their setups, I'm doing things correctly. In fact, the creator of the library used the same setup as I am. The only difference is that his worked. :-/
What version of the IDE are you using? Have you verified that the old TLC object files are deleted before compling (aftering changing the parameters in the .h files)?
I've changed NUM_TLCS in tlc_config.h. I don't believe there is a TLC5940.o file anymore, I think the library recompiles itself. There is a TLC5940.h file and TLC5940.cpp , though. I'm not too familiar with these file types. The more I think about it, it does seem like a configuration issue.
I'm using Arduino version 0018 and r013 of the library.
When I change NUM_TLCS I just open tlc_config.h change the number and save it. That's all I need to do, right? I'm starting to second guess myself. Does the "libraries" folder need to be anywhere specific? I'm assuming it's in the right spot since everything compiles without error. It's in C:\Program Files\arduino-0018\libraries\Tlc5940 not My Documents\arduino\libraries\Tlc5940 if that makes a difference.
/* Copyright (c) 2009 by Alex Leone <acleone ~AT~ gmail.com>
This file is part of the Arduino TLC5940 Library.
The Arduino TLC5940 Library is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
The Arduino TLC5940 Library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Arduino TLC5940 Library. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef TLC_CONFIG_H
#define TLC_CONFIG_H
#include <stdint.h>
/** \file
Configuration for the Arduino Tlc5940 library. After making changes to
this file, delete Tlc5940.o in this folder so the changes are applied.
A summary of all the options:
- Number of TLCs daisy-chained: NUM_TLCS (default 1)
- Enable/Disable VPRG functionality: VPRG_ENABLED (default 0)
- Enable/Disable XERR functionality: XERR_ENABLED (default 0)
- Should the library use bit-banging (any pins) or hardware SPI (faster):
DATA_TRANSFER_MODE (default TLC_SPI)
- Which pins to use for bit-banging: SIN_PIN, SIN_PORT, SIN_DDR and
SCLK_PIN, SCLK_PORT, SCLK_DDR
- The PWM period: TLC_PWM_PERIOD (be sure to change TLC_GSCLK_PERIOD
accordingly!)
How to change the pin mapping:
- Arduino digital pin 0-7 = PORTD, PD0-7
- Arduino digital pin 8-13 = PORTB, PB0-5
- Arduino analog pin 0-5 = PORTC, PC0-5 */
/** Bit-bang using any two i/o pins */
#define TLC_BITBANG 1
/** Use the much faster hardware SPI module */
#define TLC_SPI 2
/* ------------------------ START EDITING HERE ----------------------------- */
/** Number of TLCs daisy-chained. To daisy-chain, attach the SOUT (TLC pin 17)
of the first TLC to the SIN (TLC pin 26) of the next. The rest of the pins
are attached normally.
\note Each TLC needs it's own IREF resistor */
#define NUM_TLCS 2/** Determines how data should be transfered to the TLCs. Bit-banging can use
any two i/o pins, but the hardware SPI is faster.
- Bit-Bang = TLC_BITBANG
- Hardware SPI = TLC_SPI (default) */
#define DATA_TRANSFER_MODE TLC_SPI
/* This include is down here because the files it includes needs the data
transfer mode */
#include "pinouts/chip_includes.h"
/* Set DATA_TRANSFER_MODE to TLC_BITBANG and change the pins below if you need
to use different pins for sin and sclk. The defaults are defined in
pinouts/ATmega_xx8.h for most Arduino's. */
#if DATA_TRANSFER_MODE == TLC_BITBANG
/** SIN (TLC pin 26) */
#define SIN_PIN DEFAULT_BB_SIN_PIN
#define SIN_PORT DEFAULT_BB_SIN_PORT
#define SIN_DDR DEFAULT_BB_SIN_DDR
/** SCLK (TLC pin 25) */
#define SCLK_PIN DEFAULT_BB_SCLK_PIN
#define SCLK_PORT DEFAULT_BB_SCLK_PORT
#define SCLK_DDR DEFAULT_BB_SCLK_DDR
#endif
/** If more than 16 TLCs are daisy-chained, the channel type has to be uint16_t.
Default is uint8_t, which supports up to 16 TLCs. */
#define TLC_CHANNEL_TYPE uint8_t
/** Determines how long each PWM period should be, in clocks.
\f$\displaystyle f_{PWM} = \frac{f_{osc}}{2 * TLC\_PWM\_PERIOD} Hz \f$
\f$\displaystyle TLC\_PWM\_PERIOD = \frac{f_{osc}}{2 * f_{PWM}} \f$
This is related to TLC_GSCLK_PERIOD:
\f$\displaystyle TLC\_PWM\_PERIOD =
\frac{(TLC\_GSCLK\_PERIOD + 1) * 4096}{2} \f$
\note The default of 8192 means the PWM frequency is 976.5625Hz */
#define TLC_PWM_PERIOD 8192
/** Determines how long each period GSCLK is.
This is related to TLC_PWM_PERIOD:
\f$\displaystyle TLC\_GSCLK\_PERIOD =
\frac{2 * TLC\_PWM\_PERIOD}{4096} - 1 \f$
\note Default is 3 */
#define TLC_GSCLK_PERIOD 3
/** Enables/disables VPRG (TLC pin 27) functionality. If you need to set dot
correction data, this needs to be enabled.
- 0 VPRG is not connected. <em>TLC pin 27 must be grounded!</em> (default)
- 1 VPRG is connected
\note VPRG to GND inputs grayscale data, VPRG to Vcc inputs dot-correction
data */
#define VPRG_ENABLED 0
/** Enables/disables XERR (TLC pin 16) functionality to check for shorted/broken
LEDs
- 0 XERR is not connected (default)
- 1 XERR is connected
\note XERR is active low */
#define XERR_ENABLED 0
/* You can change the VPRG and XERR pins freely. The defaults are defined in
the chip-specific pinouts: see pinouts/ATmega_xx8.h for most Arduino's. */
#if VPRG_ENABLED
/** VPRG (TLC pin 27) */
#define VPRG_PIN DEFAULT_VPRG_PIN
#define VPRG_PORT DEFAULT_VPRG_PORT
#define VPRG_DDR DEFAULT_VPRG_DDR
#endif
#if XERR_ENABLED
/** XERR (TLC pin 16) */
#define XERR_PIN DEFAULT_XERR_PIN
#define XERR_PORT DEFAULT_XERR_PORT
#define XERR_DDR DEFAULT_XERR_DDR
#define XERR_PINS DEFAULT_XERR_PINS
#endif
/* ------------------------- STOP EDITING HERE ----------------------------- */
#if DATA_TRANSFER_MODE == TLC_SPI
/** SIN (TLC pin 26) */
#define SIN_PIN TLC_MOSI_PIN
#define SIN_PORT TLC_MOSI_PORT
#define SIN_DDR TLC_MOSI_DDR
/** SCLK (TLC pin 25) */
#define SCLK_PIN TLC_SCK_PIN
#define SCLK_PORT TLC_SCK_PORT
#define SCLK_DDR TLC_SCK_DDR
#endif
#if !(DATA_TRANSFER_MODE == TLC_BITBANG \
|| DATA_TRANSFER_MODE == TLC_SPI)
#error "Invalid DATA_TRANSFER_MODE specified, see DATA_TRANSFER_MODE"
#endif
/* Various Macros */
/** Arranges 2 grayscale values (0 - 4095) in the packed array format (3 bytes).
This is for array initializers only: the output is three comma seperated
8-bit values. */
#define GS_DUO(a, b) ((a) >> 4), ((a) << 4) | ((b) >> 8), (b)
#if VPRG_ENABLED
/** Arranges 4 dot correction values (0 - 63) in the packed array format.
\see setDCtoProgmemArray */
#define DC_QUARTET(a, b, c, d) ((a) << 2) | ((b) >> 4), \
((b) << 4) | ((c) >> 2), \
((c) << 6) | (d)
#endif
#endif
I would assume NUM_TLCS should be 3 (you have them for RGB, don't you?), and I would not change anything with bitbang and spi....
It's in C:\Program Files\arduino-0018\libraries\Tlc5940 not My Documents\arduino\libraries\Tlc5940 if that makes a difference.
If you have two copies it will take the one from your local path. This could cause confusion... You can introduce a syntax error in one of the copies to find out which will be taken...
Okay, so funny coincidence... I told you where the library was located and where it wasn't, just to clarify that it was in the right spot. You thought I meant I had two separate folders in those locations. I didn't, but I did create a backup of the library in the same directory and renamed it TLC5940_Backup. Turns out I must have accidentally renamed the original, and that's what was being used. I really should have considered that in all my troubleshooting. :-/ Oh well, I'm too relieved to care right now haha.
Thank you for taking a look at this thread. I had gotten so bogged down by this problem that I needed an outside perspective.
Now all I need to do is get a 5v 2amp regulated power supply and hook it up to all of the LEDs and chips. I've had off and on luck with that. Sometimes the chips will get hot and sometimes they will be fine. There must be something I'm missing, I'll have to read up more on power supplies.
I'll post pics in like a month or however long it takes me to finish this, but again, thanks for your help.