Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
sinn3r
 
Posts: 7
Joined: Fri Aug 16, 2013 4:41 am

Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by sinn3r »

Hi,
I am really interested in your TLC5947 24 channel PWM LED driver.
Will there be some tutorials on how to connect and use it on the PI with some python samples?

As I need more than 24 channels, how to daisy-chain the modules? As far as I can tell there is no ID jumper like on the 16 channel I2C servo controller.

Is it fast enough to fade the brightness of connected LED strips?

Many thanks in advance,
Marc

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by adafruit_support_rick »

I don't know if there are any tutorials in the pipeline - I'll have to check on that.

Connect the input side of the first module to the Pi as follows: SPI MOSI to DIN, SPI CLK to CLK, and SPI CS (chip select) to LAT, and GND to GND (not V+; use a separate power supply)

Daisy chain output side of the first module to the input side of the next module: DOUT to DIN, CLK to CLK, and LAT to LAT.

Use a separate power supply.Connect power and gnd to V+ and GND on the first module (creates a shared ground with Pi). Daisy chain power and gnd from the first module to the second module.

There is one more pin - /OE. This is the output enable ("BLANK" in the datasheet). It is active LOW. When this pin is low, the PWM outputs are enabled. Bring the signal HIGH to turn off all PWMs and reset the boards.

sinn3r
 
Posts: 7
Joined: Fri Aug 16, 2013 4:41 am

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by sinn3r »

Thanks for your quick answer!
I finally got the 24 channel driver along with some other great adafruit sensors.
My code is also running fine testing it with simple LEDs on the pwm outputs.

But there is one thing left to do, that doesn't seem to work.
I need to controll 24 LED strips with the board, so I also got 24 P16NF06L FETs (as recommended in your LED Strip tutorial), but after some tests I found out that the V+ pin on the board is not controlled by the PWM but the ground pin is. So it seems that I cannot use these FETs to control the strips, or can I ?
I found some other forum entry that states that it can be used, but has inverted output (which would not be a problem as I can control it in my software), but as I have no clue about this kind of stuff maybe you can help me again.

Thanks in advance,
Marc

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by adafruit_support_mike »

You're right that the TLC5947's output pins are made to work on the low side of the connection, but you can use them to drive mosfets by adding a pull-up resistor:
image.jpg
image.jpg (11.78 KiB) Viewed 2307 times
The circuit is fairly simple, but every component reverses the effect of the one before:

- When the TLC5947's OUT pin is turned OFF, no current flows through it. That means the voltage at the bottom of the pull-up resistor will be HIGH. That will turn the mosfet on, current will flow through the mosfet, and the LEDs will light up.

- When the TLC5947's OUT pin is turned ON, current will flow through it. That takes the voltage at the bottom of the pull-up resistor to GND. That will shut the mosfet off, no current will flow through the mosfet, and the LEDs will go dark.

The upshot is that the LEDs do the opposite of the OUT pin, so you will need to invert the control signals.

sinn3r
 
Posts: 7
Joined: Fri Aug 16, 2013 4:41 am

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by sinn3r »

Great!
This works. What's the correct value for the pull-up resistor when running on 12V?
I tried 1kO, 10kO and 100kO, didn't seem to make any difference.

After finally connecting some FETs and LED strips to the TLC5947 I discovered another strange thing:
Let's say I set the value for out1 to 0 and the LED strip runs at full brightness and I now fade-in out2 by sending about 100 value changes from 4095 to 0 then the strip at out1 flickers (though I always send 0 to that output). I thought that maybe the FET input gets an unstable voltage so I removed the FETs and added 2 simple LEDs with a resistor directly to the outs of the TLC5947 and discovered that they flicker the same way(though it's not detectable that easy as they are not very bright at all).
Any idea why this may happen and what I could do to fix it?

Thanks in advance,
Marc

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by adafruit_support_rick »

Ick. I think the flicker is a side-effect of Mike's inverse logic.

Let me make sure I have this right. To turn LED1 OFF, you have to actually keep out1 turned on - i.e., a PWM duty-cycle of 100%.

Now, to shift the new value into out2, you have to toggle LAT. The rising edge of LAT causes all outputs to be turned off. Because of the inverse logic, turning off out1 turns the LED on, causing the brief flash.

I'll flag Mike...

sinn3r
 
Posts: 7
Joined: Fri Aug 16, 2013 4:41 am

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by sinn3r »

Some additional Infos:
I returned to my original version without reversed values and tried again with some plain LEDs and without the MOSFET.
The flickering it the same, just barely visible.
Example:
2 LEDs connected to the TLC5947, one on out1 and one on out2, nothing on out0
I then send by code always 4095 to out1 and a changing value from 0 to 4095 to out2
The LED on out2 fades from off to full brightness, the LED on out1 flickers (while fading LED2, not before, not after)
Even when Setting both LEDs to 4095 and fading out0 (without anything connected), both LEDs flicker while sending out the data so it doesn't seem to be a power supply problem.

I am using the "spi-bcm2708" system module and just write the values as 24*10 bit to /dev/spidev0.0 (using wiringPi v2)
There is no difference when using voltage from the pi (5v) or when using a separate power supply for the TCL5947 (12V).

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by adafruit_support_rick »

Weird - I'll have to see if I can replicate it here.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by adafruit_support_mike »

It looks like I missed a detail that I missed when scanning the datasheet. The chip does send all outputs LOW when you latch new data to the output registers, then picks up the PWM again when the central counter rolls over to zero. The built-in clock runs at about 4 MHz and the counter rolls over at 4096, so each counting period (generally called a 'frame') lasts about 1 millisecond.

Given the way the human eye responds to light, it's easy to see a 1ms pulse of light from a normally dark LED, and easy to ignore a 1ms gap from a normally lit LED. The circuit I suggested swaps the ON/OFF values, thus turning an easy-to-ignore gap into an easy-to-see flash.

We can fix that, but it will take more hardware.

We're dealing with two related types of transistor circuits: the 'inverter' and the 'open drain'. An inverter turns a HIGH input signal into a LOW output signal and vice versa. An open drain half of an inverter.

The schematics look like this:
mosfets.jpg
mosfets.jpg (9.97 KiB) Viewed 2239 times
As you can see, an open drain is just a mosfet with one end connected to GND, and an inverter is an open drain with some kind of resistive connection to VCC.

The mosfets that you've connected to the LED strips are working as open drains, and the TLC5947's output pins work exactly the same way. Open drain outputs are handy for situations where you need to control an unknown load working from an unknown voltage (like making a general-purpose LED driver). When I added the resistor to the TLC5947's output, I turned those open drains into inverters that would drive your mosfets. Unfortunately, the TLC5947's latching behavior produces unwanted side effects when you do that.

To get the original output values back, we need to put another inverter into the chain:
inverter-chain.jpg
inverter-chain.jpg (11.28 KiB) Viewed 2239 times
Working backwards through the chain:

- When the input to the mosfet driving the LEDs is HIGH, the mosfet allows current to flow, lighting the LEDs.

- When the input to the center mosfet is LOW, it doesn't allow any current to flow, so the input to the LED-driving mosfet will be HIGH (and the LEDs will light up).

- When the TLC5947's output pin allows current to flow (which would light an LED connected directly to the pin), it pulls the center mosfet's input LOW. That sends the center mosfet's output HIGH, which ultimately leads to the LEDs lighting up.

Rather than buying 24 more mosfets and building all the inverters from scratch, I'd suggest using a chip like the 74HC14.. a general building-block logic chip that contains six inverters and costs about 30 cents in small quantities: http://www.mouser.com/ProductDetail/Tex ... ZccgHx8%3d Four of those will be enough to handle 24 channels of output.


BTW - You were right that the size of the turns-the-open-drain-into-an-inverter resistor doesn't matter. Mosfets don't require any DC current at their input to operate. Their input (the 'gate') is basically a capacitor. When you charge it to a certain voltage, it attracts electrons in a way that allows current to flow.

It takes a little bit of current to charge or discharge the gate, but holding it at a given value doesn't take any current at all. A mosfet driven from a low-value resistor will charge faster than one driven from a high-value resistor, but it's a question of nanoseconds versus microseconds. That's important when you have a million of them running at 1GHz in a microprocessor, but isn't worth caring about in this application.

sinn3r
 
Posts: 7
Joined: Fri Aug 16, 2013 4:41 am

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by sinn3r »

Thanks Mike for this long answer!

Woudn't it be easier to switch all MOSFETs to p-channel types and directly connect them to the outputs of the TLC5947?

Best regards,
Marc

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by adafruit_support_mike »

You'd still need the resistors to provide a current path to VCC (otherwise the P-mosfets would never shut off) but yes, that would work.

The N-channel version above is a little more complicated, but would cost less. Ten 74HC14s and a hundred resistors would cost about $6.00, or about 25c per channel for 24 channels. If you only count the cost of the parts you actually use, it's about 7c per channel and your inventory of parts-on-hand would become about $3 more valuable.

It looks like the P16NF06Ls cost about 60-80c, and a P-type equivalent in a TO-220 package will probably cost about 50% more (N-type mosfets are easier to make.. it's a side effect of how semiconductors work). That comes to $0.90 to $1.20 per channel, with the P16NF06Ls adding about $15 to your inventory.

Shipping costs would add to both options of course, but would be about the same either way.

sinn3r
 
Posts: 7
Joined: Fri Aug 16, 2013 4:41 am

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by sinn3r »

Hey Mike, hey Rick,

thanks again for your answers.
Your service is unbelivable great!

I got myself some p-channel mosfet and now the led strips behave as planned.

What remains is still the flickering Problem. It doesn't seem to be caused by the mosfet, see my post before with just some simple LEDs.
All fully turned on LEDs flicker when moving data to the TLC5947, though the data doesn't change the values of the turned on LEDs.
Need to solve this last problem, everything else is working fine.

Thanks,
Marc

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by adafruit_support_rick »

The flickering is probably the LEDs turing off when the new data is latched. That's just the way the hardware works - I don't know of any way to fix it. According to Mike, the glitch will last about 1ms. I'm kind of surprised you can see it happening.

I can try to replicate the problem, but it will be later next week before I'll be able to get to it.

sinn3r
 
Posts: 7
Joined: Fri Aug 16, 2013 4:41 am

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by sinn3r »

Yes, it's exactly this. I found a way to get around it by "BLANKING" the TLC5947 after every XLAT.

I found this answer in the TI forum:
"The IC is intended for applications which show static pictures for a longer period of time. So whenever the picture is changing, BLANK can be set high to turn the outputs off and reset the GS counter and during BLANK=high, XLAT can be used to latch the new picture in."

Seems this synchs the pi and the TLC anyhow, so the flickering is not noticable.

Thanks for all your effords,
Marc

jnovack
 
Posts: 22
Joined: Sat Sep 14, 2013 1:43 pm

Re: Tutorial / python software for 24 channel 12bit PWM SPI on PI?

Post by jnovack »

So, for a complete electronics newbie who can't read a resistor value, how does this translate?

What Adafruit (or Radio Shack) part numbers do I buy?
Where do I hook them up?

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”