Go Down

Topic: Matrix 5x5 with transistors (Read 982 times) previous topic - next topic

swat3d

Aug 02, 2012, 05:25 am Last Edit: Aug 02, 2012, 05:35 am by swat3d Reason: 1
Hi,

I am working on a 5x5 matrix... one more yes... The only difference is I need to drive the LEDs at maximum brightness and be able to control each individual LED brightness in software. I don't want to use any shift register or LED driver ICs in this circuit, I'm just learning by doing and I am trying to understand how transistors work properly.

This is going to be a Row/Anode Column/Cathode type matrix. My LEDs have a 2.2 FWD and 50ma peak current at 10% duty time.
The idea is to do column scanning method and run it at 100kHz. If i add a 6th row (fake) to the software, i can multiplex groups of 10 LEDs with a duty cycle of 1ms that gives me 10ms wich works perfectly.
So it will turn on row1, row3, row5, then turn on col1, off col1, on col2, off col2...until col5. After that switch off the rows, turn on row2, row4, row6(fake) and scan the columns again.
The brightness part os also more or less fine, by playing with the duty cycle i can control the brightness of the LEDs individually.

3 LEDs can be on at a time so that means 150mA have to be sink at max. The 2N3904 can have an Ic of 200mA so it should be fine if i use an extrenal power supply for the LEDs.

The software side is more or less under control but i'm very weak on the hardware side.

The original plan was to use PNPs for the rows and NPNs for the cathodes in a common emitter configuration. However i stumbled upon several schematics that use NPNs for both rows and columns.
I though that wasn't a good idea but i reproduced the circuit in a simulator. Attached is an schematic of what it looks like. I have taken some measurements in the simulator and it seems to be running ok but I would like to get some advice from you guys before i proceed with putting it together physically.

Does it make sense? What are the differences (other than using ground/positive for the base) between driving everything with NPNs or using PNP/NPN ?

Thanks a lot in advance for your time.

Osgeld

the emitter follower setup on your rows is not the most ideal thing in the world, but its worked ok enough for me, question is where is the emitters connected in your columns?

swat3d

Quote
the emitter follower setup on your rows is not the most ideal thing in the world, but its worked ok enough for me, question is where is the emitters connected in your columns?


This version is using NPNs for both, rows and columns. So the columns are connected to the collectors of the NPNs at the bottom and the emitters of those are connected to ground.

Originally I had the exact same setup but I was using PNPs for the rows instead. The only problem I found with that setup was that when using a higher voltage source for the LEDs, when the PNPs bases were set as HIGH (+5v), the base voltage was still lower than the emitter voltage (+9v) so current was still flowing from the emitter to the collector. So basically i had no way to switch the PNPs off.

Any ideas on how to fix that issue? Any thoughts on why is it a bad idea to use NPNs for the rows?

Thanks!!

Magician

Quote
The idea is to do column scanning method and run it at 100kHz.
Are you sure you can run outputs and matrix code at this speed?
Why do you need 6-th row? Why 3904, there are a lot of high power transistors.

swat3d

#4
Aug 02, 2012, 04:54 pm Last Edit: Aug 02, 2012, 05:00 pm by swat3d Reason: 1
Are you sure you can run outputs and matrix code at this speed?
Why do you need 6-th row? Why 3904, there are a lot of high power transistors.

Yeah i tested it already and the loop takes 10ms. The matrix code is very simple, is not doing much. I'm just updating the brightness of the LEDs, not playing any animations or stuff like that.
Basically I have 2 arrays[6][5], the first one  stores the target brightness for each LED and the second one stores the current brightness of each LED. What i do in the loop is:
1st I run the stepBrightness function. What this function does is goes through the current brightness array, checks if the current brightness equals the target brightness, if so, assigns a new random target brightness. Otherwise if the current brightness is higher than the target brighness it substracts a "brightnessStep" value from the current brightness. If the current brightness is smaller than the target, it adds the brightnessStep value to it.
Once the brightness has been processed I multiplex the LEDS and I use the currentBrightness value to determine the duty cycle of the LED.
So what i get is each individual LED blends between different brightness values endlessly.

It's not very processor intensive and I got it to run at 100fps. (Sorry did i say 100kHz?)

My only questions are about the hardware itself. What are the pros/cons between using NPNs for rows/columns or PNPs/rows NPNs/columns. As I mentioned earlier:

Quote
Originally I had the exact same setup but I was using PNPs for the rows instead. The only problem I found with that setup was that when using a higher voltage source for the LEDs, when the PNPs bases were set as HIGH (+5v), the base voltage was still lower than the emitter voltage (+9v) so current was still flowing from the emitter to the collector. So basically i had no way to switch the PNPs off.


To answer your questions:
Quote
Why do you need 6-th row?

Just to keep the code consistent, not a big deal. So i can step through 1/3/5, 2/4/6

Quote
Why 3904, there are a lot of high power transistors.

Are the ones i have available, I don't want to buy new stuff for this project and I just need to have 3 LEDs on at a time, that is 150mA.

Magician

Quote
My only questions are about the hardware itself.
Looks like this not only your problem. Running "software PWM" requires re-refreshing update  speed  much higher than you think, 100 Hz x N,  where N - number of brightness levels. For 256 levels, it would jump up to 25.6 kHz, or just 40 usec per cycle. I'm not saying it's impossible, but code optimization would be necessary, which is out of discussion till we see your actual code.

Regarding hardware, you mixing up two different issue, choice of  NPN / PNP   transistors and +5 / +9 Voltage.  PNP would works with +5V as good as NPN, even better as they would provide lower "drop off" voltage, meaning more voltage available for the load and less heat dissipation in transistors itself (even it's not a problem with your design with 2.2V LEDs).
If you select +9V as voltage source, than "level shifting" issue would apply to NPN transistors as well.

swat3d

Quote
Looks like this not only your problem. Running "software PWM" requires re-refreshing update  speed  much higher than you think, 100 Hz x N,  where N - number of brightness levels. For 256 levels, it would jump up to 25.6 kHz, or just 40 usec per cycle. I'm not saying it's impossible, but code optimization would be necessary, which is out of discussion till we see your actual code.


If i understand right, the technique you are proposing to have brightness control via software is as follows:

Given a matrix of 5x2 (10 LEDs) and 64 levels of brightness at 100Hz.
You would loop through the entire matrix 64 times in 10ms.
In every loop the LED would either be on or off based on the brightness desired.
So if we want a brighness level of 32, it would be on for the first 32 loops and off for the other 32.

My approach is different, I don't know if it's better or worse, i'm pretty new to this.

Given the same scenario as above.
I would determine the on/off time based on the brighness level. 100% brightness would mean 1ms on, 0ms off. 50% brightness means 0.5ms on, 0.5ms off.
I balance the on/off time so the maximum time spent in each LED adds up to 1ms.
The total time to loop through the matrix is then 10ms so it is refreshing at 100Hz.

Does that make sense?

Regarding the hardware I did some research about the "level shifting" that you mentioned, spot on, that's my problem! I'm trying to switch higher voltages from lower voltages using transistors, so it doesn't work.

But before proceeding with that, let me go back to a more basic question. Do I really need more than 5v to drive  3 LEDs at 50mA?

I'm assuming that yes. A FWD voltage of 2.2 each, 2.2*3 = 6.6 + (0.7 * 2) (transistor drop) = 8v. Each one will have it's own transistor for the anode and a common transistor for the cathode. The 2n3904 can handle 40v and 200mA so it should be fine with a 9v input. Does that make sense?

Magician

Quote
I balance the on/off time so the maximum time spent in each LED adds up to 1ms.
The total time to loop through the matrix is then 10ms so it is refreshing at 100Hz.

Does that make sense?
No, it doesn't. You are saying , that duty cycle per led would vary from 0 to 10%. There is no other way, than to check "ticking" timing for every led in every cycle. Well, dropping brightness level to 64 may works, you still can use digitalWrite.
Quote
I'm assuming that yes. A FWD voltage of 2.2 each, 2.2*3 = 6.6 + (0.7 * 2) (transistor drop) = 8v.
I don't follow your math, LEDs in parallel,  2.2 + 2 * 0.9 (100 mA , data sheet that I have doesn't show saturation voltage for 150 mA ) = 4 V. Resistors value should be lower than 33 OHm, 20 or even less.


Grumpy_Mike

Quote
Originally I had the exact same setup but I was using PNPs for the rows instead. The only problem I found with that setup was that when using a higher voltage source for the LEDs, when the PNPs bases were set as HIGH (+5v), the base voltage was still lower than the emitter voltage (+9v) so current was still flowing from the emitter to the collector. So basically i had no way to switch the PNPs off.


So you swaped it for a circuit that can deliver no more than 4.3V no matter how high you put up the supply voltage. Smart or what?

The answer to the PNP "problem" is either to use a potential divider driving the base, or an NPN driving transistor.

swat3d

Quote
The answer to the PNP "problem" is either to use a potential divider driving the base, or an NPN driving transistor.


Right, now I'm starting to understand, bear in mind that I am a complete newbie learning by myself.
I found a pretty informative link, I'll go through it and see what results i get.

http://www.w9xt.com/page_microdesign_pt12_hv_pnp_switching.html

swat3d

Ok I think i figured it out, here is an schematic it gives me around 2.2v across the LED and 24-26mA. So i guess it's ok.

Grumpy_Mike

Yes that will do it.

If you want to eliminate Q1 make R3 470R and R2 3K9 and connect the other end of R2 direct to the arduino. This will work for a supply voltage of 9V only and uses the internal clamping diodes in the arduino running at just under 1mA.

However I would recommend what you drew.

Have you seen this:-
http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html

swat3d

Ok cool, yeah i have seen that link many times. However i'm having trouble putting everything together.

With only 1 row and 1 column ON, i get a current of 26.78 mA and a voltage across D1 of 2.249V. When i enable the second row, i get a current of 22.35 mA and a voltage across D1 of 3.363V.
I don't understand why the voltage is increasing and the current decreasing. Shouldn't the voltage and the current remain always the same, as i'm feeding every row independently from the voltage source and the NPN for the column is able to handle it?
I've attached a new schematic.

swat3d

Ok nevermind, the NPN was not into saturation, i changed the base resistor to 1K and everything works fine now :)

Grumpy_Mike


Go Up