SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By Tomasu
#31464
I've done some small little demo projects here and there, with crappy tools, and crappier supplies. And I have this one project that I want to do first, something that I think I'll be able to get finished by Nov/Dec.

Why Nov/Dec? Its a Christmas tree ;) Basically I want to make a 1-2 foot high fake Christmas tree lit with a ton of different coloured LED. I have the beginning of the project all laid out, PIC18F4550 mcu (because I have samples ;)), a maxim MAX7221 led matrix controller, a couple switches for on/of and "preset" changing (lighting patterns and all that), and upwards of 40-60 LEDs. :)

I'm sure some might think it could be done sooner, but I'm really not that experienced yet, and I'm a fiddler, I like to fiddle, so I'll end up making infinite revisions and mistakes.

So I have a few questions. Some tool and supplies related, and others about the actual project.
  1. What kind of tools and supplied do I absolutely need? I'll list some I know I need:
    • A soldering iron that isn't from radio shack (I plan on getting the smaller AUOE soldering iron + reflow unit from SFE)
    • A ton of solder
    • PIC programmer that isn't broken (I bought a PG2C last year and fried it with in a week or so of owning it. blew a transistor, and managed to scorch the PCB with my firestarter, and even some hookup wire to re join the points I thought were broken didn't bring it back to life :( )
    • PIC dev board (maybe not absolutely necessary, but I think it'll speed up initial dev with the pic, I plan on getting this)
    • Misc components, resistors, capacitors (ceramic and electrolytic), crystals, LEDs (a ton ;D), wire, transistors, diodes, etc. I actually have a lot of components, just a little short on transistors and LEDs.
    • Anything more? Like solder paste, flux, solder wick? I do plan on working with SMD down the road, hence getting the reflow+iron unit.
  2. From what I've been reading, everything says "put all your components as close as possible to the power/pins/ground", yet with a project like mine, the closest the LEDs will be is around 5 inches possibly more (talking trace/lead/wire distance). Will this cause any serious issues? Or do I just not worry about it and crunch all the numbers with the resistance/impedance of the extra wire included?
  3. I'm not quite sure how I'm supposed to hook up the LED matrix driver to the individual LEDs. Basically the driver chip has 16 outputs, 8 for the "digit"s and 8 for the "segments", but it allows you to controll the segments individually. Theres a part or three in between the LEDs and the driver that I'm missing, and can't figure out exactly what I need.
I thought I had more questions. I always seem to forget one or two while writing up the first couple.

A couple notes, I do know how to program, I've been writing in various languages for 8+ years now, C, C++, Perl, and some very limited asm. Also wrote my own "VM" of sorts a couple times, along with a test assembler for the virtual processor. So I'm no stranger to low level stuff. Might be a little intimidated by the lack of available memory on mcus, but I think I can manage.

I'm also looking for any tips and advice people here could offer. I have a ton of reference material from all over the web, but no books, so if theres any people would suggest, that'd be cool.

Thanks for reading this looong post.
By Tomasu
#31467
Thanks to a 2x4 upside my head from a person in irc://chat.freenode.net/electronics I managed to figure out the wiring of the LEDs. I always have to overthink things, no idea why. So question 3 is solved :)

edit:

Ok, one more question, I'll look for answers myself as well, but, with a PIC18F4550 or any similar pic, do the "port" pins need to be attached to anything if they aren't being used?
By oPossum
#31468
Soldering iron: Metcal MX-500 (current model) or STTS (previous model). Don't get any of the other Metcals - they are lower cost and it shows. Quite expensive new, but $100 to $250 on ebay. Weller WTCP would be my second choice. Much less expensive than the Metcal - $150 new.

Solder: Kester "44" is a good general purpose solder.

PIC Programmer: USB Prog for a programmer. ICD-2 (or good clone) for a debugger/programmer.

Misc parts: Seel this thread and this one

Parts placement: Place 100 nF caps close to the power pins. The crystal or resonator should be close to the pins it connects to. For everything else distance matters most for fast signals (generally busses). For slow I/O it ususally isn't important.

Unused port pins should be set to output *or* connected to ground or power via a resistor (10k typical, not critical).
By winston
#31469
If you're starting out, it might be as well to do the project with just raw logic (4000 series is good for this, for the wide range of voltages it will work off). Sure, it'll be quite a few chips, but you'll learn a lot of very valuable lessons in the meantime. I'm glad I started out that way - my first project was a 7 tube nixie display, driven by a computer's RS232 port. I built the UART out of nothing but 4000 series logic - gates, shift registers, counters etc.

For surface mount, certainly when starting out you don't necessarily need to start with reflow and solder paste. On Friday, I hand soldered an SSOP-28 onto a home-made PCB (no solder mask to help) and it all worked first time:

http://www.alioth.net/Projects/USB-Brea ... akout.html

Just a pointy soldering iron tip, 0.5mm solder and solder wick to do it (plus a magnifying glass!)
By Tomasu
#31470
oPossum: thanks, I'll look into all that.
If you're starting out, it might be as well to do the project with just raw logic (4000 series is good for this, for the wide range of voltages it will work off). Sure, it'll be quite a few chips, but you'll learn a lot of very valuable lessons in the meantime.
Do the entire project in just logic chips? It'll be rather hard to re program the lighting patterns ;)
For surface mount, certainly when starting out you don't necessarily need to start with reflow and solder paste.
Yeah, I've gone through that video tutorial on SMD stuff on SFEs tutorial page. Drag soldering and solder wick seem to work most of the time, I assume it just takes practise and patience.
By NleahciM
#31471
oPossum wrote:Soldering iron: Metcal MX-500 (current model) or STTS (previous model). Don't get any of the other Metcals - they are lower cost and it shows. Quite expensive new, but $100 to $250 on ebay. Weller WTCP would be my second choice. Much less expensive than the Metcal - $150 new.
That seems a bit overkill to me. I have a Hakko 936-12 (~$90) and it can handle anything I throw at it. I just don't see why he'd need to spend more money than that. There's even some knockoffs (sold by Circuit Specialists, among others) of the 936 that cost even less, but aren't quite as good.
By Philba
#31476
I can vouch for the Hakkp 936 - It's been a good iron for me. You can get even cheaper though I don't know the quality. Definitely get a temperature controlled one.

On your project, you may discover that an LED matrix doesn't provide sufficient brightness since the LEDs are multiplexed. I'd look at using something like the TPIC6C595 power shift register. each one can drive 8 loads at 100 mA and you can daisy chain them so you only need 3 pins to control a very large number of lights. I'd put up to 5 LEDs on each output of '595 so even one chip could light up 40 LEDs at full brightness. There may well be even better solutions.
By Tomasu
#31477
On your project, you may discover that an LED matrix doesn't provide sufficient brightness since the LEDs are multiplexed.
Its not actually going to be a matrix. Just some pretty lights on a tree. 40+ LEDs at full brightness is going to blind people ;)
I'd put up to 5 LEDs on each output of '595 so even one chip could light up 40 LEDs at full brightness. There may well be even better solutions.
Thats not really what I want though. I want each led to be individually controlled for brightness. I suspect I'll end up using 40-60 individual leds. And I'll want to controll them all individually. The MAX7221 chip allows this sort of thing. If the max chip doesn't work out, I can always try the TPIC6C595 shift registers you mentioned (btw, thanks for pointing them out :)), but I think the MAX7221 will work fine for my application.

edit: and now that I think about it, I'll need some extra parts along with the shift registers to be able to controll brightness along with the on/off state.

Ideally what I want is a method to controll 60 individual leds, grey scale for each. I initially started looking for ICs that had a massive number of PWM outputs I could just attach via SPI or some other interface that'd work with common mcus but I didn't find much. I stumbled on the MAX7221 via a couple threads here on this forum, and it seems to do what I want.
By Tomasu
#31479
After doing some research and seeing this particular thread, and finding some inexpensive Hakko 936 units on ebay, I think I'll get one of them instead of the ones SFE sells.
User avatar
By bigglez
#31485
Tomasu wrote: Its not actually going to be a matrix. Just some pretty lights on a tree. 40+ LEDs at full brightness is going to blind people ;)
Greetings Tomasu,

Read the MAX7219/MAX7221 data sheet - the device is MUX'd, the LEDs are wired in a matrix. There's no practical way to drive sixty (or so) LEDs from a 24 pin IC without MUX.
Tomasu wrote: Thats not really what I want though. I want each led to be individually controlled for brightness. I suspect I'll end up using 40-60 individual leds. And I'll want to controll them all individually. The MAX7221 chip allows this sort of thing.
Tomasu wrote:If the max chip doesn't work out, I can always try the TPIC6C595 shift registers you mentioned (btw, thanks for pointing them out :)), but I think the MAX7221 will work fine for my application.
The TPIC6C595 is an open drain output, so it can only sink current. It can be used with LEDs that are fed from a positive rail, but would require one channel per LED (60/8 ~ 8 chips....). The MAX ICs have eight open drain low side switches and eight high side switches (P-CH, Open Drains?) so the LEDs are wired in a matrix. M+N = 16 drivers, one IC, compared with M*N = 64 drivers if done with TPIC6C595s alone.
Tomasu wrote:edit: and now that I think about it, I'll need some extra parts along with the shift registers to be able to controll brightness along with the on/off state.
Not really. A shift register driver can control the brightness via PWM, as is done by the MAX7219/MAX7221 IC. A shift register alone lacks the programmable constant output current feature of the MAX ICs, so you will need a current limit resitor per output (or per LED is you do a direct drive scheme).

Comments Welcome!
By Tomasu
#31486
Not really. A shift register driver can control the brightness via PWM, as is done by the MAX7219/MAX7221 IC
Really? I would guess it would have to support PWM directly? Please explain :)
Read the MAX7219/MAX7221 data sheet - the device is MUX'd, the LEDs are wired in a matrix. There's no practical way to drive sixty (or so) LEDs from a 24 pin IC without MUX.
Yup, I have this problem where I overthink things, and think things are more complicated than they really are. After looking at a standard wiring diagram for a led matrix, I had a "Duh" moment. I had thought extra parts were needed between the IC and leds to properly "switch/select" between the "segments" in the "digits", but thats all handled with how the matrix is wired.
The TPIC6C595 is an open drain output, so it can only sink current. It can be used with LEDs that are fed from a positive rail, but would require one channel per LED (60/8 ~ 8 chips....).
Thats what I figured. And really, 8 chips isn't super evil. But I still like the MAX7221 solution better. Makes things easier for me :)

Thanks for the very helpful reply :)
User avatar
By bigglez
#31487
Tomasu wrote:
Bigglez wrote:Not really. A shift register driver can control the brightness via PWM, as is done by the MAX7219/MAX7221 IC
Really? I would guess it would have to support PWM directly? Please explain :)
A shift register either outputs parallel data from a serial stream (in this case), or the opposite.

The LEDs are connected to the parallel outputs, which are driven by a serial stream from the uC (or PC via serial port). A stream of all ones will turn on all LEDs to full brightness, a sequence of all ones interlaced with all zeros will blink the LEDs, and if done above the persistence of vision (12 - 15Hz) will appear as a steady display of lower brightness.

The data stream can constist of any combination of data (selects the LEDs to light) and time multiplexed with zeros (to turn all the LEDs off) and effect brightness.

With eight shift register ports each LED can only get 1/8 of the cycle, so full brightness is not possible (unless the LED current is increased eight-fold). Also, the refresh rate should increase eight-fold (15 * 8 = 120Hz) to avoid flicker.

A work around is to double buffer the shift register, using a second bank of latches, which is done by the TPIC6C595 and similar devices. Read the data sheet.

Comments Welcome!
By Tomasu
#31488
The data stream can constist of any combination of data (selects the LEDs to light) and time multiplexed with zeros (to turn all the LEDs off) and effect brightness.

With eight shift register ports each LED can only get 1/8 of the cycle, so full brightness is not possible (unless the LED current is increased eight-fold). Also, the refresh rate should increase eight-fold (15 * 8 = 120Hz) to avoid flicker.
Thank you for the explanation. I really aught to have figured that out myself.

You can't see it, but I'm shaking my head at myself. ;)
By Philba
#31491
I think this was said but I will put it in my own words.

As peter said, the problem with a matrix driver is that it only illuminates one column (or row, depends on the design) at a time. So, a 64 LED matrix will have each LED on for a MAXIMUM of 1/8 of the time (8 x 8 matrix). In PWM terms, that's a max duty cycle of 12.5%. Now, you can increase the drive current of the LEDs to make up for this - the MAX7221 does do that. But... (a very large but) the intensity register applies to all the LEDs. You can can't individually control on LED. Maybe a column at a time (8 LEDs). They are usually designed for alpha-numeric displays where squeezing the most brightness out isn't the key issue.

The way you PWM a shift reg implementation:

- set up a cycle that continuously updates the SR chain from a bank of LED values (that define on/off state of each LED), one byte per SR. do this in an Interrupt Service Routine (based off of a timer interrupt or perhaps off of the SPI HW completion interrupt - you've much to learn, grashopper) so it runs continuously with no intervention by your mainline code. The time it takes to update the entire SR chain will be your maximum PWM frequency though you can run it slower.

- in a timer based ISR at a slower rate than your PWM rate, you can change the LED values - think of this as your twinkle programming. What I have done in the past is to create a table of byte values (256 works nicely) and just walk through the table, using each value as the PWM amount. When you get to the end of the table, start over at the top.

To simulate candle flicker, I used a phototransistor into an analog PIC port and recorded the actual flickering of a candle. I use that as my table of PWM values. To simulate flicker of multiple candles, I simply start at different points in the table so the flicker patterns are out of sync.

To get individual flicker, you will need to determine a PWM sequence for each LED so there is some complexity. I would start with a single LED to get the basic logic working, then go to one SR and then extend it to however many SRs you want. The trick will be in making it efficient to allow larger numbers of SRs to be supported.

On the multiple LEDs per pin. This can actually work well if you intermix them with LEDs from other pins. With enough independent LEDs, the eye will probably not detect a pattern. One of many tricks designers use to reduce the costs of hardware.
By Tomasu
#31494
Philba wrote:But... (a very large but) the intensity register applies to all the LEDs.
Ah, good catch. Individual brightness isn't actually the most important feature. But it would be nice to have.
Philba wrote:The way you PWM a shift reg implementation
Philba wrote:<some great advice>
Wow. Thats a lot to absorb. But very cool. And should be interesting to get working.
See, again with he overthinking, to get that sort of "flicker" or fancy pattern I had assumed I'd need some "fancy" math which I'm not all that great at (and neither is a PIC for that matter).

This is some great stuff guys, keep it coming. Thank you!