(I'm posting this here because I think the problem is with the TLC, apologies if it should be in Audio)
I'm using TLC5940 to control some RGB led strips (the 12v non-addressable ones). It works fine, and I'm now trying to make it audio reactive - using a basic microphone/opamp breakout board - but the readings I get from analogRead() are way out. They should hover around 512 (the breakout board is quite noisy, but this is the average value in silence)
I've attached a PDF of a graph of sample outputs of raw analogRead(). You can clearly see something is up with the TLC one, but I have no idea what is going on!
Anyone have any suggestions?
PS - I know there are quicker ways to do audio sampling than using analogRead() in a loop, but I'm trying to get the simplest case to work before making it more complex.
There's only one mention of "capacitor" in the datasheet:
The TLC5940 has graduated delay circuits between outputs. These circuits can be found in the constant current
driver block of the device (see the functional block diagram). The fixed-delay time is 20ns (typical), OUT0 has no
delay, OUT1 has 20ns delay, and OUT2 has 40ns delay, etc. The maximum delay is 300ns from OUT0 to
OUT15. The delay works during switch on and switch off of each output channel. These delays prevent large
inrush currents which reduces the bypass capacitors when the outputs turn on.
Where should a "bypass" capacitor go, is it the same a decoupling capacitor i.e. go across the gnd and vcc in of the chip?
Ah thanks, I'll stick a 100nF capacitor in there and see if it makes any difference. I've already soldered it all together so it might take some doing!
I've also found out that the TLC chip needs a clock from the arduino for the PWM. This is supplied using an interrupt in the TLC library. Here is the code if anyone is knowledgable enough to understand it!
/* Timer 2 - GSCLK */
#if defined(TLC_ATMEGA_8_H)
TCCR2 = _BV(COM20) // set on BOTTOM, clear on OCR2A (non-inverting),
| _BV(WGM21); // output on OC2B, CTC mode with OCR2 top
OCR2 = TLC_GSCLK_PERIOD / 2; // see tlc_config.h
TCCR2 |= _BV(CS20); // no prescale, (start pwm output)
#elif defined(TLC_TIMER3_GSCLK)
TCCR3A = _BV(COM3A1) // set on BOTTOM, clear on OCR3A (non-inverting),
// output on OC3A
| _BV(WGM31); // Fast pwm with ICR3 top
OCR3A = 0; // duty factor (as short a pulse as possible)
ICR3 = TLC_GSCLK_PERIOD; // see tlc_config.h
TCCR3B = _BV(CS30) // no prescale, (start pwm output)
| _BV(WGM32) // Fast pwm with ICR3 top
| _BV(WGM33); // Fast pwm with ICR3 top
#else
TCCR2A = _BV(COM2B1) // set on BOTTOM, clear on OCR2A (non-inverting),
// output on OC2B
| _BV(WGM21) // Fast pwm with OCR2A top
| _BV(WGM20); // Fast pwm with OCR2A top
TCCR2B = _BV(WGM22); // Fast pwm with OCR2A top
OCR2B = 0; // duty factor (as short a pulse as possible)
OCR2A = TLC_GSCLK_PERIOD; // see tlc_config.h
TCCR2B |= _BV(CS20); // no prescale, (start pwm output)
#endif
TCCR1B |= _BV(CS10); // no prescale, (start pwm output)
update();
}
Could the interrupt be, well, interrupting the audio sampling and causing problems? TBH I'm not clear how it could cause the analog readings to be out (delayed maybe, but not wildy wrong?), but there's a lot I don't understand about how either the TLC or Mega chip works!
I've put a capacitor between the VCC and GND pins on the TLC as suggested but it's made no difference. Attached is a screen shot and you can see the noise!
Below is the code for the sampling. It works OK when the 5v TLC line is disconnected.
Layout-wise the TLC is on a seperate PCB connected to the arduino pins with jumper wires as described before. All 5v & gnd lines are connected to each other on a breadboard, and the output from the microphone breakout board (it has a built in opamp so also has 5v and gnd lines) is connected to A0.
I don't know what else to do, does anyone have any more suggestions please?!
Thanks,
Mark
All 5v & gnd lines are connected to each other on a breadboard,
No you want to connect the ground and power or the microphone direct to the arduino not through the bread board.
I've put a capacitor between the VCC and GND pins on the TLC as suggested but it's made no difference
That is only one place where decoupling can be applied.
Keep the audio wires away from those carrying high current.
Attached is a screen shot and you can see the noise!
Without a scale on any axis it is difficult to make anything from that. Any chance of a dual trace one showing the TLC's PWM signal and the other the audio so we can see if there is a definite correlation.
It works OK when the 5v TLC line is disconnected.
A bad thing to do but at least you have proven that it is a decoupling hardware issue rather than anything in the software.
I've read several firsthand accounts of the TLC5940. They all say the same thing. If the LEDs are driven from the same power supply as the processor, "larger" decoupling capacitor(s) are needed. Most folks use a single 47 uF to 100 uF capacitor. A few folks toss in a combination of capacitors. A single 47 uF close to the point where the LEDs connect to power made a huge difference for me.
In other words, @markvr you very likely have a hardware problem and @Grumpy_Mike is giving you very sage advice that will help solve that problem.
No you want to connect the ground and power or the microphone direct to the arduino not through the bread board.
I'm using an Uno (although this will be moved to a nano for permanent use), which has 3 gnd pins, based on your advice I've now connected each of the grounds I have (12v line, the TLC gnd, and the audio breakout board gnd ) to those individually which has unfortunately made no difference. I only have one 5v line/pin from the arduino though, which is (partly) why I'm using a breadboard. How would I do what you suggest for the 5v line without the breadboard? (I'm not doubting it, I'm just not sure how to do it!)
Without a scale on any axis it is difficult to make anything from that. Any chance of a dual trace one showing the TLC's PWM signal and the other the audio so we can see if there is a definite correlation.
Unfortunately I don't have a oscilloscope, the screenshot before was from rendering the arduino Serial.write ouput in Processing as in here - http://accrochages.drone.ws/en/node/90. It's obviously not high enough frequency for real audio analysis, but shows the general idea of the signal.
@codingbadly
A single 47 uF close to the point where the LEDs connect to power made a huge difference for me.
I'll put this in, but I'm not sure exactly where you mean. There is a schematic here - TLC5940, ULN2803 and 12v RGB strips - LEDs and Multiplexing - Arduino Forum - (sorry it's a bit huge by mistake!) but there are now 5 ULN chips, each chip driving 3 (RGB) ribbon channels, so 5 sets of LED ribbon. It also now has 100nf between the VCC and gnd pins of the TLC as well. Where would the 47uf cap go on this diagram? I'll draw up a more complete diagram shortly as wel which might help.
I'll put a bigger cap across the TLC pins as well and see if that helps.
Hardly worth the name schematic, it dosn't show the power going to the TLC, it doesn't show the current setting resistor and it shows 5V going into the Vin of the arduino, there is no current limiting resistor on the LED and from what you draw I can't see the point of having the darlington buffers at all. I hope none of those are correct. The point about a schematic is it is supposed to show what you have so we can spot the mistakes.
You also have not shown any of the input circuitry. How about a photograph then if you can get a clear shot.
Attached are some hopefully more complete diagrams. The schematic only shows 2 of 5 ULN arrays and sockets. I thought more would add clutter without any benefit. I've been battling Fritzing a bit, but hopefully they are more useful?
The PCB is what has the TLC, ULN and 10k pull ups all soldered together. It has 12V in from an external power supply, and then a 5v line from the Arduino into the headers (in the photo). The GND lines from the external power supply are connected from the PCB to the GND on the arduino (the yellow cable in the photo) - which is all other GNDs as well.
The arduino is powered from USB, and the 5v from the arduino goes to a breadboard, and then a line goes to the PCB/TLC, and the Mic breakout board.
I'll add decoupling caps wherever! i can try and add a bigger one to the TLC on the PCB (I've already added a 100nF one), and then would it help to add one across the 12v/GND lines on the PCB? And maybe also across the 5v/GND lines on the Mic breakout board? Or any other suggestions to quieten the noise on the Analog read?!
Thanks,
Mark
Move the 5V line so that it is not chained from the microphone to the TLC. Wire both direct to the arduino. Yes put a capacitor across the 5V and ground on both boards. Use a ceramic 100nF and. Large one in parallel.
Try to shorten the wires to the microphone, try twisting the 5V and ground together.
Do the analogRead spikes occur if the TLC5940 outputs are all set to zero?
No! With the TLC enabled, but with setAll(0), the output from the mic is like normal. Because the PWM is reversed, this means the strip is at full brightness.