Proper way to extract 12 Bit Bianary from a Word Variable for SPI

sodeaf

Senior Member
Hey Guys

I have been Searching the web for a while now trying to learn how to use a 20x2 with a TLC5940 Chip. I have been able to extract a little info here and there and have something working now. Although I am far off from where I need to be.

Right now I am sending the "12 Bits" the hard way

spiout sclk,ssin,1, (%10000000/8)
spiout sclk,ssin,0, (%0000/4)
spiout sclk,ssin,1, (%10000000/8)
spiout sclk,ssin,0, (%0000/4)
and so on for all 16 channels.

It works to set each channel brightness, buy changing the values. I use a binary converter and away we go..

But is there not a better way.. For instance they chip uses 4096 steps of Brightness. I would light to be able to hold the brightness value in the form of a number.. like W1=2562 and W2 = 3695 and so on..
I have been trying silly things to get this to work

spiout sclk,ssin,1, (W2/8) - Don't work
spiout sclk,ssin,0, (w2/4) - Don't work

I am a newbie, and have been reading a lot about this.. as well on binary.. Any help in the right direction would be great,

The TLC 5490 has been discussed before and I have read every post on them several times, which has been helpful.. But I wanna try to figure a different way around this silly chip..

Thanks

Steve
 

PaulRB

Senior Member
Hi Steve. It does look slightly tricky, but here's some hints:

The 'mode' parameter for spiout should always be 1 for the 5940 chip.

W0 is equivalent to B0 (least significant byte) and B1 (most significant).

The 4 bits you then want to send from B1 need to be in positions 4 to 7, rather than 0 to 3 where they start out. Use the << 4 function on B1 to fix this.

Then you can send B1 (4 bits) followed by B0 (8 bits).

Paul
 

westaust55

Moderator
plus you can incorporate the byte bytes os data into a single SPIOUT statement:

spiout sclk, ssin, MSBFirst_L, (%10000000/8, %00000000/4) ; MSBFirst_L is predefined in the PE and is more "readable"/understandable at a later date

or
b1 = b1 << 4 ; same as b1 * 16
spiout sclk, ssin, MSBFirst_L, (%b1/4, %b0/8) ; the /8 after b0 is optional - sending msb first for must send b1 before b0

or

w0 = w0 << 4 ; shifts both b1 and b0
spiout sclk, ssin, MSBFirst_L, (%b1/8, %b0/4) ; the /8 after b1 is optional
 

sodeaf

Senior Member
Hey guys thanks for the help... It is all making sense to me now.. I now have a single 20x2 Picaxe running the TLC 5940.. Pretty cooL!

As I move along in this project, my goal is to run 16 of those 5 meter LED strips... Seems like this is talked about a lot these days.. I am looking to use 2 Amp NPN Transistors. on each output.. I was thinking of just using an Inverter from the output side of the TLC5940 then to the NPN.. Would this work? Any suggestions on a good Transistor for the job..

Thanks again..

Steve
 

premelec

Senior Member
Hi Steve, I hope you will post your code for setting the TLC5940 - as to drivers I like appropriate MOSFETs which will handle large currents but you'll need drivers if using higher switching speeds. There are so many transistors that will handle the current and voltage that your best bet might be whatever you have in your junk box or can obtain locally [or out of an old stereo set etc...]. Shouldn't be too critical and what you suggest seems likely to work...
 

sodeaf

Senior Member
Hey Premelec..

Yeah I sure will post working code I have now.. (when I get home) it will be handy for people just learning (Like myself) I must give props to all the other posters for there help.. for I stole little bits from here and there!

I have found http://www.fairchildsemi.com/ds/FQ/FQP13N06L.pdf which is a great N Channel Mosfet.. Capable of 13 Amps... From what I have read.. Considering the TLC 5940 is a "Sinking output" (I think that right, goes "LOW") to turn on leds.. I will use a
http://www.ti.com/lit/ds/symlink/sn74hcu04.pdf
The inverter will take the "Low" and convert to "High" for the N-Channel Mosfet. Should be able to drive them just fine.. Cost isn't to bad as well..
My goal is to build a general board with the 20x2 and TLC5940 with standard 16 Channel LED outputs. Then have small piggy back boards that include 1 x Inverter and 6 N-Channel Mosfets that can then drive the high current.. Kinda makes it universal this way.. I will order some Mosfets this week and try it out..

If anyone has any opinion on this please feel free.. I'm no expert, and have built the knowledge base I have now from all of you.. I cannot thank you guys enough.. 2 Years ago I dreamed of building cool little projects.. and because of Picaxe.. I have been able too!

I will post the code tonight..

Steve
 

MikeAusP

Member
. . . . For instance they chip uses 4096 steps of Brightness. I would light to be able to hold the brightness value in the form of a number.. like W1=2562 and W2 = 3695 and so on.. . . . .
Yes, the technology is capable of 4096 steps - but the eye can't detect changes in brightness less than about 20%.

So you could store each desired brightness settings in a byte rather than a word. When you want to output the brightness setting, just multiply the byte by 16 to pad out the lowest four bits with 0s before sending to the TLC5940.
 
Top