Micro-Controller Controlled Led Matrix Design - Question.  - Page 1
Forum section: electronics / projects

author: erezmaster
author_rank: Contributor
timestamp: May 17, 2013, 08:37:58 am
content: Heya guys,I plan on designing a 16x20 Led Matrix that will be controlled with a Row Latch and a Column Latch, via an MCU.Look at the picture,I am going to address each row at a time,because obviously addressing leds from different rows at the same time wouldn't work (Current aspect).Question is,Is this matrix planed properly?Will it work?Picture of small sample of the whole circuit is provided (Original is 16x20 Leds).Any thoughs will be greatly appriciated,Thank you.

author: Strada916
author_rank: Frequent Contributor
timestamp: May 17, 2013, 09:33:03 am
content: You can also use transistors in a dil package such as uln2003 there are 7 in one ic. Can't remember if it pn or np. You can also use 74xx595 shift register to minimise the number of outputs.

author: lewis
author_rank: Frequent Contributor
timestamp: May 17, 2013, 12:03:18 pm
content: the column transistors should be PNP with the bases driven from an NPN open collector. This will allow the transistor to saturate potentially giving increased brightness. It's essential if the LEDs are to be run from a higher supply voltage than the MCU. Also, the resistors on the row latch transistors would conventionally go in the collector leg with the emitter going to ground. Add some resistors in the base. But... what you've got would actually work pretty well if you get the resistor value correct, the row transistors are currently configured as switchable current sources with the collector current (and hence the LED current) being determined by the voltage going into the base, minus one diode drop, divided by the emitter resistor value. But only if the LED supply voltage was sufficient - you'll lose about 4.4V across the emitter resistor in this configuration so your supply voltage has to be high enough to take this, and the LED voltage drop, and the saturation voltage of the column transistors, into account.Since only one LED is on at any one time, you could drive the entire matrix directly from the MCU if the current of each LED is lower than the maximum port pin output current. You wouldn't need any transistors at all if your matrix was small enough.

author: Strada916
author_rank: Frequent Contributor
timestamp: May 17, 2013, 12:22:23 pm
content: Also. Most leds will tollerate 50mA at no greater than 5ms. infact my led matrix is 7 by 64 and I run them at about 100mA for no more than 5ms. if you run it only 20mA the display will be quite dim.

author: mariush
author_rank: Super Contributor
timestamp: May 17, 2013, 12:25:23 pm
content: Quote from: Strada916 on May 17, 2013, 09:33:03 amuln2003a has 7 darlingtons (npn pair), uln2803a has 8 of them but is generally a bit more expensive. There's versions without the "a" at the end, those don't have a base resistor on each npn built in.. these with a at the end simply save you pcb space and soldering time integrating resistors at the base of the npn pairs. All of them also have protection diodes on each darlington in case you'd run fans or motors or whatever.You still need resistors at the outputs of the darlingtons because they have something like 1000-10000 hFe (beta) so they'll push lots of mA into the leds without a current limiting resistors - therefore they're a bit overkill for your application compared to a simple npn but again, you have 7-8 npns integrated into a small package easy to work with.yeap, shift registers + darlingtons / npns ... takes you 3-4 pins on your microcontroller.

author: erezmaster
author_rank: Contributor
timestamp: May 17, 2013, 03:35:43 pm
content: Thank you guys for your awesome answers!Just two things,1) to Lewis,I didn't get the point where Column transistors should Be PNP driven fron NPN to allow the transistor to saturate potentially giving increased brightness.How does the above configuration affects increment of the brightness of a LED?2) to Strada916,The emitter resistor will be calculated so current of approximately 20ma will be forced through the LED, thus,supply voltage at the will be about 12v from external battery.With that said, why are you talking about such high currents, like 50ma or 100ma?Why with a current of 20ma the LED would be dim?I checked it on a static simple circuit on a breadboard and the brighness seems great even at 17ma. (Blue LEDs)Thank you again,looking for your answers.

author: lewis
author_rank: Frequent Contributor
timestamp: May 17, 2013, 04:04:41 pm
content: If you drive the NPN column transistors directly from a chip that's connected to a 5V supply, the bases of the transistors can only go up to 5V. This means the emitter will only go up to about 4.4V. So no matter what the supply voltage is for the LEDs, they'll only just over 4V from the column drivers. If you make the transistors PNP, pulling the bases down to ground will saturate them, turning them on fully, and pulling the base right up to the supply voltage will turn them off fully. So you need an open collector NPN, with the emitter grounded and the collector pulling the PNP's base down to ground through a resistor in order to drive the columns. Plus a pullup resistor on the PNP's base to turn the transistor off when the NPN goes off. Have a look at the top circuit in the attached image.The bottom circuit is similar but is muchmuchfaster and uses one less component. The NPN transistor does not get saturated in this configuration and turns off much quicker. The NPN acts as a switchable current source with the collector current defined by the base voltage minus a diode drop, divided by 1K. This causes a further voltage drop across the upper 1K resistor which turns the PNP on. Since the upper resistor is a lot lower in value, the PNP turns off much faster when the NPN goes off. This configuration will reduce the likelihood of the LEDs in the matrix bleeding into each other causing ghosting and blurring if you're multiplexing above a few hundred Hz, which you probably are.

author: erezmaster
author_rank: Contributor
timestamp: May 17, 2013, 05:22:48 pm
content: Lewis,thank you so much for such a detailed answer.Thing is,In both configurations the current forced through the column is always the same.means, no matters how many LEDs I intend to power up in the specific column,the current drawn from the column transistor configuration is constant, and probably gonna be high.The problem in such situation is, that if the circumstances require to light up only one (even 2, 3, 4..) LED, no doubt he will be burned.The current has to be adaptive,means it must be regulated according to the number of rows (LEDs) that are enabled at one time.Any thoughts?

author: lewis
author_rank: Frequent Contributor
timestamp: May 17, 2013, 08:42:06 pm
content: It's not trivial to design a matrix system to reliably light more than one LED at once, it's a lot easier to light just one at a time. But it's possible. I can post a circuit tomorrow for you if you like when I'm in the vicinity of the scanner, but you replace the upper 1K resistor in the bottom circuit with another transistor to form a PNP current mirror (google that to see what I mean).The current it generates is now roughly proportional to the base voltage. That way, when you want to light more than one LED you feed additional base voltage to increase the row or column current. Not difficult to do with some extra pins on your micro, or even some diode logic and resistors, to get roughly there.There's probably some IC to do all this, I had a quick look and found this:http://playground.arduino.cc/Main/LEDMatrixBut you might want to stick with lighting one LED at a time! It's a hell of a lot easier, although you'll get limited brightness.

author: Strada916
author_rank: Frequent Contributor
timestamp: May 17, 2013, 11:22:59 pm
content: In my led matrix I used red leds as at the time blue leds where new and cost was high. the reason you need such a high current is so you do not have a dim display. remember one led is on at any one time. 320 leds at minimum 25fps will be about 8ms on time if my calcs are correct.

author: mariush
author_rank: Super Contributor
timestamp: May 18, 2013, 12:21:02 am
content: Well there's no reason he should light up one pixel at a time, that would be terribly inefficient.Divide the 16x20 into 16 rows of leds with 20 leds each, get 5 shift registers ( 3 x 8 = 24 leds max in row, 2 x 8 = 16 rows) and a bunch of resistors. If you get a high pin count mcu, you can run the 16 rows directly from microcontroller, as you only need 3-4 wires to the shift registers so you could just use 16 io pins to connect straight to npn or darlingtons or mosfets/whatever.You only use one resistor per column as you will only light one led out of 16 in the column at a time. You turn on and off each row so fast that the human eye won't notice only one row is turned on at a time.Turn off all lines, shift in the data (the 24 bits because you have 3 shift registers, just send 4 zeroes initially if you only have 20 leds)... the output of the shift register goes into the base of an npn transistor through a resistor and basically connects the column of leds to power or not. Add a resistor to limit current in the column and you're done.Once you shifted those bits for the whole row, turn on the whole row with another npn transistor (or darlington array like uln2003a, uln2803a, a mosfet etc), wait a few ms, turn off the row, repeat with next row.Code:mcu -> 3-4 wires-> [ shift register 1 ] --- [ shift register 2 ] --- [ shift register 3 ]| v v v| [ uln2003a/uln2803a ] [ uln2003a/uln2803a ] [ uln2003a/uln2803a ]| v v v|   | | | | | | | | | | | | | | | | | | | | | | | | ||..--[npn 1]--...............|..--[npn 2]--...............|..--[npn 3]--...............||..----...............D = leds^ <-----> <-- a row| <--- column|v.... cathodes of leds in row connected together to npn1, npn2, npn3 (or darlington array elements).... anodes of leds in column connected together to R above and to darnlington element or npn transistor at topuln2003a/uln2803a are darlington arrays and have a base resistor on each darlington, you can replace them with individual npn transistors with base resistor.uln2003a has only 7 darlingtons, so you'd need 4 ics, not three, ascii drawing above is for uln2803a which has 8 darlingtons in each IC.if you replace the npn1 to npn16 with two uln2803a ( or 3 uln2003a) nothing changes, you can power those two/three uln chips straight from 16 io pins from mcu, or just use 2 shift registers to reduce the io pins to another set of 3-4 wires.so it's possible to shrink this to 6-8 io pins.so as you can see it's doable with 6-8 pins. Keep a row lit for 2-5 ms, turn off the row, shift fresh data for the next row that's supposed to be lit, turn on next row, repeat going through all 16 lines then start again from top line... looping 24/7. 1/16 duty is not a problem, even 10mA per led should be bright enough.

author: Strada916
author_rank: Frequent Contributor
timestamp: May 18, 2013, 01:14:37 am
content: lighting one led at a time very quickly gives you hi flexibility as to what can be display. It's called multiplexing as you have illustrated in your text diagram. You could Charlie plex it too. also as you have pointed out we have mentioned 595 and uln2303.

author: glatocha
author_rank: Regular Contributor
timestamp: May 18, 2013, 02:00:43 am
content: What current you want drive the LED. Instead of the Row transistor you can use directly the uC pin with output "0".Also the resistor I would put between the LED and the Collector.Why you are driving it from 12V? If you would use the uC Voltage it will simplified the Collector Transistor circuit.

author: erezmaster
author_rank: Contributor
timestamp: May 18, 2013, 10:02:44 am
content: Thank you.Quote from: glatocha on May 18, 2013, 02:00:43 amThe initial schematics that I've posted are already irrelevant.Have so many mistakes in there - i.e. 12v was irrelevant to the circuit, just a waste of space for another battery.Quote from: mariush on May 18, 2013, 12:21:02 amYour reply is so informative, you just blew my mind, thank you.Let me see, if I've got this straight,The general idea is to lit up one led at a time in an infinite loop, (so far is what I though initially)It is done by scanning each row led by led, while each 'moment' only one led is enabled by the related column (ULN) via the shift registers.When scanning of 1 whole row is finished, it moves on to thenextrow, and again starts to scan from the first led in the row until the last one.and scanning goes on and on, updating real time.By this technique its not 1/16 cycle as you said,but (1/16)/20 cycle (Not scanning only rows, but scanning columns also, that occurs within each row scan cycle),and the danger that pops up - that the human eyemaynotice the scanning.I hope you understood me,Any thoughts?

author: glatocha
author_rank: Regular Contributor
timestamp: May 18, 2013, 10:33:34 am
content: What he meant is that at one time you switch ON all the LED in one raw. Then you skip to the other.So you scan raw by raw, but columns will go at the same time.See this video:https://www.youtube.com/watch?v=R9kUadTXpzsHe shows the multiplexing in slow motion. Same like your case, column same time, raws scanning.

author: nctnico
author_rank: Super Contributor
timestamp: May 18, 2013, 11:18:08 am
content: About the drivers: look at the tpic6c595 chips from ti/st. You have a shift register and open drain driver in one chip.

author: Strada916
author_rank: Frequent Contributor
timestamp: May 18, 2013, 11:23:40 am
content: due to POV you will always see some flaring. O0

author: madworm
author_rank: Frequent Contributor
timestamp: May 18, 2013, 11:29:34 am
content: Use UDN2981 as the source drivers, MBI5168 (shift-reg with constant current) or MBI5030 (integrated PWM) as sink drivers.

author: Corporate666
author_rank: Unknown
timestamp: May 18, 2013, 01:50:07 pm
content: I've done lots of multiplexed displays and used various techniques.What I've found works best is a constant current shift register driving the rows, and discrete transistors on the columns. I like the ST Micro STP08 line of chips. $0.45 for an 8-bit shift register, and you can chain them by connecting the last output bit of one to the next, making as long a row as you like. I've got one display with 35 rows, 7 columns of discrete 0805 high brightness LED's. I think I run them around 100mA each and each row is of course 1/7th duty cycle.That display is extremely BRIGHT - even in direct sunlight. And the component count is pretty low. The chips just need 4 lines from the MCU plus a resistor to set the current - and that's it.

author: erezmaster
author_rank: Contributor
timestamp: May 18, 2013, 04:45:04 pm
content: Thanks you guys,Your replies gave me a great direction to where to follow.To my application, I prefer switching the columns, thus, I'll use a ULN2803A on the Rows side and a shift registers on the Columns.If the output current from the ULN is 500ma (Data Sheet), how a single led should tolerate such amount?The big thing is,that I cannot control the current through the LEDs because I even don't know what the voltage output should be from the Shift Register (Says just 120ma constant at MBI5168 ),thus, I dont even know how to calc the limiting resisitor, if even needed.Dig me out of this mess.

author: elgonzo
author_rank: Unknown
timestamp: May 18, 2013, 05:41:15 pm
content: Quote from: erezmaster on May 18, 2013, 04:45:04 pmDigging...If you are going to use the MBI5168, just look at its data sheet. It describes how to calculate Rext(and thus LED current) and how the LED voltage is supplied.When looking at the example circuit in the datasheet (excerpt of the MBI5168 datasheet attached), you will note that the LED cathodes are connected with the MBI5168 (opposite to what you have drawn in your schematic).That means, the MBI5168 is sinking the current, not sourcing it. The ULN is where the energy flow is coming from, and there you will have to feed a given voltage matching your LEDs.

author: erezmaster
author_rank: Contributor
timestamp: May 18, 2013, 06:03:31 pm
content: Oups, apparently, I am not that focused today - Thanks.MBI5168 even has designated Pin (15) for 'R-ext' to control the output current.But anyway, the polarity of the current in that IC may not fit, so I am not sure about it yet.Share your thoughts on the other issues.

author: mariush
author_rank: Super Contributor
timestamp: May 18, 2013, 06:05:29 pm
content: If the output current from the ULN is 500ma (Data Sheet), how a single led should tolerate such amount?That's why there's a series of resistors in my ascii drawing at the output of each darlington. Keep in mind I use the darlingtons as basically switches: put 5v at the base, the darlington goes into saturation and conducts .. the column gets power.put 5v at the base of the darlington at the row and the darlington is in saturation and conducts, so the row gets connected to ground.You don't care about that 500mA (or mW power consuption) of the individual darlingtons in the uln package, the resistor you put on each output has the job to limit the current. .I'm not sure the shift registers have enough power to light up 8 leds at a time (if each output of the shift register is on). Also, since you drive them at 5v, the maximum voltage would be 5v, with a darlington you can send 5v at the base of each darlington from the shift register, but have a different voltage on the output, you can put up to 30-40v to the led if you want to.Either way, you have to limit the current going through led, and the simplest and cheapest way to do that is using a resistor.There are more simple devices that limit the current no matter what voltage you have such as these ones:10mA :http://uk.farnell.com/on-semiconductor/nsi50010yt1g/ic-led-driver-50v-0-01a-sod123/dp/1794979RL20mA :http://uk.farnell.com/on-semiconductor/nsi45020at1g/ic-led-driver-45v-0-02a-sod123/dp/179497330mA :http://uk.farnell.com/on-semiconductor/nsi45030at1g/ic-ccr-led-driver-linear-sod-123/dp/1787605Anyway, back to the resistor method.. you just have the formula V = I x R ... you need to drop a particular voltage on the resistor, so you have to take out first the forward voltage of the led , the voltage lost on the non or darlington when it switches... let's say your led is 2.1v forward voltage, the darlington has about 1.1v saturation voltage and you power the leds from 5v5v - 1.1v - 2.1v = 0.01 (10mA) x R = > 1.8v = 0.01 x R => R = 1.8v / 0.01 = 180 ohmSo you can use 150-220ohm and have the current around 10mA on the led.If you use a darlington at both ends (row and column) you may have to decrease 2.2v instead of 1.1v , or double whatever saturation voltage the darlington has, so the resistor value will change.Simple npn transistors have less voltage (0.2-0.5v) but they also may have a hard time (overheat, blow) when the current from all 20 leds from the row (20x10mA = 200mA) goes to ground through them.later edit:Seems you don't understand that 500mA thing... it's how much current the collector can handle. The collector doesn't "create" 500mA, it can just tolerate UP TO 500mA going through it to the emitter, on each darlington (as in you could link two collectors together to tolerate up to 1000mA )The shift register in your example a few posts above outputs voltage and current, goes to the led... but if you don't limit the current you burn the led .. hence a resistor before the led, to limit the current. then the cathode of the led goes to the darlington which just passes the 10ma to the emitter which should be connected to ground.

author: madworm
author_rank: Frequent Contributor
timestamp: May 18, 2013, 06:12:36 pm
content: Don't want to spoil the broth some more, but the ULN2803 won't do you any good together with the MBI5168.The ULN2803 is an array of open-collector NPN Darlington transistors, they only sink current. You need a source: PNP bipolar transistor, P-ch mosfet, dedicated source-driver IC (see prev. post).Depending what you use, the supply voltage for the LEDs must compensate for things like saturation voltage of the involved transistors. Best to get an adjustable power supply, so you can tweak the voltage. If it's too low, the LEDs will be unnecessarily dim, if it's too high you will heat up and/or fry the constant current driver.Most likely the optimal voltage will not be something like 5.0V or 12.0V, more likely 5.6 or 13.1V, odd values. An adjustable power supply is worth it. I've used ones of the "Meanwell" brand, very efficient, quite small, silent. They can be tweaked with a pot to about +-10% output voltage. Another way would be to get an adjustable buck / boost regulator from ebay or spin your own.And most if not all LED driver ICs out there are current sinks, so you will need a source driver that can drive a whole row / column at once. Plain shift registers can be abused to do that (been there, done that), but the achievable brightness is almost not worth the trouble. Don't go that way if you need daylight visibility.

author: elgonzo
author_rank: Unknown
timestamp: May 18, 2013, 06:18:06 pm
content: Quote from: madworm on May 18, 2013, 06:12:36 pmNo, you make it more tasty instead of spoiling itI mean, you already have mentioned UDN2981 in conjunction with the MBI5168. It was just silly me, who can't pay attention...