PDA

View Full Version : Tristated output to two common Base transistor issue



flotulopex
- 5th September 2007, 19:33
Hello,

I have to power automotive LEDs that drain 50mA.

I use twenty LEDS and have a 16F630, so my circuit connects two LEDs to 1 I/O port and I use the Z state to switch them OFF.

To make this without destroying the PIC, I use transistors like this (one port example):
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1965&stc=1&d=1189016315">

Problem: when I have set the port direction to Input (=Z state), both LEDs still light; less than normal, but still enough to make this look not good.

The SMD transistors have built-in 22k resistors like this (the PNP one has same connections):
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1964&stc=1&d=1189016089">

I tried to add 1k resistors at each Tr's Base, but... still the same.

Is there a way to sort out this issue?

NB: how do I put text beside the images???

Acetronics2
- 5th September 2007, 20:03
Hi, Roger

Supposing your leds are 5v powered ...

inserting 3x "1N4148" in series in EACH "base" connexion, AND two resistors ( equal high value ) to set "third state" output to V+/2 ...

that should work !!!

Alain

PS: dis, tes montages tordus ..., tu vas les pècher où ??? ... LOL !!!

RussMartin
- 6th September 2007, 00:17
Can the circuit be simplified?

Is there a special reason that each LED must have its own transistor driver? And that one is PNP while the other is NPN?

Have you considered using one transistor to drive two LEDs in series? (Two LEDs in series use the same 50 mA of current!) It would reduce your parts count a lot.

Is there a special reason for setting the output pin to high-Z (input) to turn the LEDs off? (Are you then using the pin as an input?) Have you considered leaving the output pin as output, adding a pull-up (or pull-down) resistor, and simply toggling it high and low?

BrianT
- 6th September 2007, 01:39
With no PIC or any other drive, the PNP and NPN transistors are both turned ON by each other and the two series resistors (not shown) which are inside the cases. If you used regular PNP and NPN without intrinsic series resistors the circuit would instantly blow up two transistors.

IF the LED supply is the 12 volt auto battery things get worse. The PNP is always conducting because its base is at either 0 or 5 volts while the emitter is at 12 volts. The PNP base sees either 7 or 12 volts drive so it is always ON.

A rethink is needed.

HTH
Brian

chips123
- 6th September 2007, 03:11
I would think some diode isolation with a pull-up on the PNP base and a pull-down on the NPN base. Something along those lines anyway.

RussMartin
- 6th September 2007, 05:33
I assumed on the basis of information given that the LED supply is 5 VDC:

50 mA (current through LED) x 47 ohms (current-limiting resistor) gives a voltage drop of 2.35 VDC.

Here is what Brian is trying to tell you:

<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1971&stc=1&d=1189055533">

R1a and R1b are built into Q1; R2b and R2a are built into Q2.

As wired, the built-in 22K resistors create a voltage divider, shown in the circuit above. Brian is not quite correct in saying that "the PNP and NPN transistors are both turned ON by each other" (they are not), but he is right about the effect of the intrinsic resistors. When the input (at B) is in a high-impedance state (Z), the voltage at A is 3/4 of +VDC, at B, it is 1/2 of +VDC, and at C, it is 1/4 of +VDC.

In other words, if +VDC is 5 volts, and the pin connected to B is high-impedance (Z), the voltage at A will be 3.75 volts, at B 2.50 volts, and at C 1.25 volts. The voltages present at A and C will keep the transistors turned partly on, which sounds like the problem you described.

The effects of a logic high (nominal +5 VDC) or a logic low (nominal 0 VDC) at B I will leave as an exercise for those who are curious.

Acetronics2
- 6th September 2007, 09:11
Hi, Russ

Look at old audio C class fully transistorized power amplifiers output stage ... the scheme is quite the same ... and see how the quiescent current is adjusted ...

There is THE solution !!!

Alain

flotulopex
- 6th September 2007, 14:41
Okay, some additional infos here.

First, I thought to use transistors for the high-power LEDs because I have to drain more than the acceptable 20-25mA a PIC can hold.

Yes, the circuit is +5V powered.

Acetronics, I will try with diodes but, if this works, I will have to add 30 diodes to the circuit!!!! (c'est pas une question de poids.... mais ça fait du monde sur le PCB :D).

BrianT, you may be right: I'm an electrician, not an electronician so I don't "master" those kind of Z-state subtilities and don't really know how to handle them a correct way...

RussMArtin, I need to light the LEDs separately, never simultaneously.

If my way of doing (thinking) is completely wrong, how would this kind of problem be resolved in an industrial environnement? Would they just use a 20 I/O ports PIC?

Finally, I ask myself if this can be done ... or not?

Acetronics2
- 6th September 2007, 16:29
Hi, Roger

the simplest (component count ) is to use "classic" transistors and use resistors for 3.5v Hi state switching, and 1.5v Lo state switching ...

That gives "R1" = 10k and "R2" = 2.2 k ... and class "C" transistors ( gain > 400 ).
The original Logic transistors can't work this way due to the too high b>e resistor

AND do not forget the +V/2 pullup 2 resistors ...

BUT ... what do you want to realize ??? other solutions possible !!!

Alain

RussMartin
- 6th September 2007, 18:10
If my way of doing (thinking) is completely wrong, how would this kind of problem be resolved in an industrial environnement? Would they just use a 20 I/O ports PIC?

Finally, I ask myself if this can be done ... or not?

This is why engineering is an art, not a science! :)

Let's sum up what we know so far:

1. It is a 5 VDC circuit.

2. The LEDs require more current than a PIC pin can source or sink.

3. There are three permitted states for any pair of LEDs--one or the other is on, or they are both off. They are never both on at the same time.

4. There are 10 output channels.

Beyond this, we don't know what you are attempting to do, or why. In other words, we don't know your intended application.

And there are questions: Do you have to use such current-hungry LEDs? Why? Of 10 channels, how many LEDs are likely to be on at the same time? Do you have size and/or board space limitations?

Alain suggests using "classic" transistors (I think he means ones without the built-in resistors). This sounds like one good approach. I would go further and suggest generic switching transistors driven well into saturation. Going to a 20-port PIC would also work, with the advantage of allowing you to use transistors that are all the same.

Jerson
- 6th September 2007, 18:28
Unless it is a course requirement, I suggest you use shift registers CD4094 to latch the states of the LEDs. For 24 LEDs you need 3 x 4094 devices; and they are dirt cheap. So, why struggle?

flotulopex
- 6th September 2007, 19:27
Well,

I'm still working on a "Knight Rider" stoplight...

Because of a extremely narrow space availability inside the original stoplight, I can't add lots of components to the circuit.

The LEDs have to be powerfull enough to look like, at least, the original bulbs.

I have made a prototype with "common" LEDs and it works well BUT it is far to weak (... and I have made it with yellow LEDs witch makes it unsuable as stoplight).
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1972&stc=1&d=1189102100">

I connected the LEDs like hereunder but this is not longer possible because of the use of transistors (btw this is just the LED connection part). The "curious" disposition of LEDs in this shematic allows me to switch-ON two consecutive LEDs and improve the fluency wipe effect - but this is another story.
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1973&stc=1&d=1189102257">

I couldn't find SMD transistors (at DISTRELEC for those who now this supplier) without built-in resistors so I thought it is a common thing (?).

Hope this helps a little...

Luciano
- 6th September 2007, 19:51
Hi Roger,

Here are two complementary transistors from www.distrelec.ch.

Best regards,

Luciano


==============================================
Distrelec Art.No: 610375
Type BC 817-40 (NPN SOT-23, 500mA)

Datasheet:
http://www.nxp.com/acrobat_download/datasheets/BC817_BC817W_BC337_5.pdf

==============================================
Distrelec Art.No: 611585
Type BC 807-40 (PNP SOT-23, 500mA)

Datasheet:
http://www.nxp.com/acrobat_download/datasheets/BC807_BC807W_BC327_5.pdf
==============================================

flotulopex
- 6th September 2007, 20:04
Luciano,

Je dois avoir les yeux dans mes poches, c'est pas possible autrement!

Nevertheless, it looks not possible to control the LEDs the way I thought I could...

Luciano
- 6th September 2007, 21:04
Hi Roger,

Try that:
http://img212.imageshack.us/img212/2348/2leds1iovq8.png
If you use standard LEDs, replace the 22 Ohm resistors with 100 Ohm resistors.

Best regards,

Luciano

EDIT: The note about the resistors is only if you use this circuit.
To drive two standard LEDs (max 20 mA) you don't need transistors.

Darrel Taylor
- 6th September 2007, 22:29
20 LED's,... 20 Transistors, 20 Resistors. Start adding diodes, half-watt resistors.... Yuck!

I think I'd just go with 3 of these

<table><tr><td><a href="http://www.allegromicro.com/en/Products/Part_Numbers/6277/6277.pdf"><img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1974&stc=1&d=1189113661"></a></td><td>

Don't even need resistors on each LED.

Up to 24V for LED drive.

Set it for 50ma constant current.
Shiftout the LED states

And that's it. :)
</td></tr></table>

http://www.allegromicro.com/en/Products/Part_Numbers/6277/6277.pdf
About $1.50 each in single quantities.
<br><br>

RussMartin
- 6th September 2007, 22:54
One problem I see with Luciano's suggested circuit is that the two 22-ohm resistors form a voltage divider (!) pulling a maximum of 114 mA (5 volts / 44 ohms = 0.114 amps) when the LEDs are doing nothing. 10 channels of this is 10 x 114 mA = 1.14 amps.

Luciano
- 6th September 2007, 23:13
Hi Russ,

The circuit is for the brake light of a car, so the circuit gets the power
only when the brake pedal is pressed. Also consider that power is generated
by the alternator, so this current will also decelerate the car when the driver
activates the brakes ...

Best regards,

Luciano

RussMartin
- 6th September 2007, 23:29
The circuit is for the brake light of a car, so the circuit gets the power only when the brake pedal is pressed.

Aha! Thanks! In that case, Roger should go ahead and give your circuit a try!

Luciano
- 6th September 2007, 23:48
Hi,

There are ony two 22 ohm resistors for the 20 LEDs.
http://img443.imageshack.us/img443/6160/2leds1io3aw5.png

Best regards,

Luciano

RussMartin
- 7th September 2007, 04:50
BrianT advised me by private message that I had oversimplified my earlier analysis, and he is right. I looked only at the voltage divider created by the resisitors built into the transistors and neglected to consider the diode drop across the base-emitter junctions of the transistors. The circuit, redrawn, looks like this:

<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1980&stc=1&d=1189136638">

With the diode junctions in place (a nominal 0.7 VDC drop across each), two voltages change: At A, 4.3 volts; at C, 0.7 volt. At B, it remains 2.5 volts. Both transistors are still "turned on" if there is no voltage present (a high-impedance state) at B.

Luciano
- 7th September 2007, 15:17
Hi Roger,

After testing my circuit on a breadboard I have found out
that the circuit works, but the current available for the LEDs
is too low for your application where the forward current of
the LEDs is 50mA.

Best regards,

Luciano

flotulopex
- 7th September 2007, 20:03
So,

Seems I have no other choice but to buy a 20 Outputs PIC.

Thank you all anyway for all your propositions and the time you spent on my problem.

BTW Luciano, I made the circuit too and yes, available current is far to low...

RussMartin
- 7th September 2007, 22:38
Luciano: After testing my circuit on a breadboard I have found out
that the circuit works, but the current available for the LEDs
is too low for your application where the forward current of
the LEDs is 50mA.


Roger: I made the circuit too and yes, available current is far to low...

Is it possible that the series base resistor (2.2K) is too large? The "brute force" method to assure that the switching transistor saturates is to give the base about ten times as much current as it needs to turn on.

Remember, the base current controls the collector current: Not enough base current means not enough collector current. Try 820 ohms, then on down (680, 560, and so on) until it works.

---------------

I did a little looking on line. Is this the kind of thing you are doing?

http://www.customdynamics.com/knight_rider_led_light_bar.htm

and the cool video:

http://www.customdynamics.com/videos/knight_riderz_video.htm

Luciano
- 8th September 2007, 12:53
Hi Russ,

Saturation is not possible, here are the results:

http://img462.imageshack.us/img462/6609/2leds1io5yr1.png


Best regards,

Luciano

flotulopex
- 8th September 2007, 15:30
I was just wondering if something like that could work.
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1986&stc=1&d=1189261229">
But after I made some trials, it is still not doing the trick :(

RussMartin
- 8th September 2007, 17:07
Saturation is not possible, here are the results

Thanks for showing us an in situ analysis. Your measurements should enable you to immediately infer what is wrong:

The circuit, as configured, doesn't permit enough voltage across the transistor! (What is Vf for the LEDs?)

If you remove the 22 ohm resistor to ground, you will get different results.

Luciano
- 8th September 2007, 17:30
If you remove the 22 ohm resistor to ground, you will get different results.

This is not possible, the circuit needs the voltage divider.

http://img212.imageshack.us/img212/2348/2leds1iovq8.png

Roger will have to modify his design.

Best regards,

Luciano

RussMartin
- 8th September 2007, 18:32
If you remove the 22 ohm resistor to ground, you will get different results.


This is not possible, the circuit needs the voltage divider.

. . . and it is the voltage divider that is causing the problem.

I was not referring to your original circuit, I was referring to your test circuit, suggesting you compare your results by omitting one resistor.

Maybe we should start over. Let's go back to Roger's original circuit, which can be redrawn this way:

<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1987&stc=1&d=1189271646">

This is a first cousin to a half H-bridge.

You will recall the only problem he observed was that, when the input was tri-stated to high-Z, both LEDs were on, although not fully bright. This fault was traced to the resistors built into the transistors. Alain suggested, and I agreed, that the circuit be attempted with "classic" transistors (i.e., transistors without built-in resistors).

Has anyone tried that yet?

Luciano
- 8th September 2007, 19:02
Hi Russ,

The result for your circuit:

http://img509.imageshack.us/img509/2370/russ1uq9.png

Best regards,

Luciano

RussMartin
- 8th September 2007, 19:42
Beg pardon, my friend; not my circuit. It is a generic redrawing of Roger's original circuit. Which transistors did you use? :) And did you toast them? :(

Thanks for the drawing! It illustrates the problem very nicely! (The red current path is through two diode junctions.)

Luciano
- 8th September 2007, 20:24
Hi Russ,

The transistors are still working.

With this circuit the LEDs are always ON.

NPN BC546
http://www.fairchildsemi.com/ds/BC/BC546.pdf

PNP BC558
http://www.fairchildsemi.com/ds/BC/BC558.pdf

Best regards,

Luciano

Luciano
- 8th September 2007, 20:52
Hi Russ,

My interest was to find a solution for the LEDs board that Roger has already made.

If there is no solution for the original LED board, then a new board with I/O port
expanders ICs + transistors is in my opinion the way to go.
(One I/O + 1 transistor for each 50mA LED). That way all the LEDs can be
ON at the same time and each LED can be individually controlled.

Best regards,

Luciano

RussMartin
- 8th September 2007, 21:09
The transistors are still working.

Well, that's good news! :)

If you have a few extra minutes, try the circuit this way:

<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1992&stc=1&d=1189282112">

Let us know how that comes out. You may want to tinker with the values for Rcl, maybe starting with something between 100 and 150 ohms.

Do you have some small-signal P-channel and N-channel MOSFETs laying around?

RussMartin
- 8th September 2007, 21:45
Scratch this post.

Luciano
- 8th September 2007, 22:19
Hi Russ,

These are the test results. I have used the old transistors
and also new transitors but the results are the same. The
picture below is with the new transistors.

The picture shows the two LEDs ON with about 25% luminous intensity.

http://img505.imageshack.us/img505/953/russ2yy2.jpg


Best regards,

Luciano

Luciano
- 8th September 2007, 23:02
Hi,

With the circuits we are exploring here, the two LEDs are turned OFF by setting
the I/O of the PIC as input. (Input tristated). When the I/O is set as input,
the voltage present on the I/O pin must be recognized as logic LOW or as a
logic HIGH. Undefined voltage levels are dangerous for the input buffer of the I/O.
Floating inputs on digital pins are a no-no.

Best regards,

Luciano

RussMartin
- 8th September 2007, 23:58
Thanks for an excellent result! (And the photo!) And thanks for bearing with me . . . I'm doing this on paper, not on a breadboard. I don't know what your LEDs are, so I'm having to guess at the Vf (I'm using 1.6 V) and assuming an If of 20 mA.

If you please, try increasing both Rcl's each by the same amount until the LEDs just go out, then test high and low at Rb again.

I appreciate your concern about floating inputs, but we can deal with that next. (I have something in mind.)

Darrel Taylor
- 9th September 2007, 02:54
Just to throw a little confusion in the mix, .... how bout ....

<table border=1><tr><td><img src="http://picbasic.co.uk/forum/attachment.php?attachmentid=1994&stc=1&d=1189302807"></td><td>
Or, it may need a normal NPN
<img src="http://picbasic.co.uk/forum/attachment.php?attachmentid=1995&stc=1&d=1189303431"></td></tr></table>
Also just on paper :)
<br>

Bruce
- 9th September 2007, 05:56
How about something like this?

Luciano
- 9th September 2007, 09:50
Hi Bruce,

Here are the results:
http://img410.imageshack.us/img410/9585/bruceledtu2.png

When Tab is open the whole circuit uses 1mA.
I have used 3 transistors BC558.

Thank you!

Best regards,

Luciano

P.S.

Do not connect LEDs in parallel like that with just one series resistor!
If you need to connect LEDs in parallel, use one resistor for each LED.

This was just a quick test to see if 50mA were available.

RussMartin
- 9th September 2007, 11:43
What a coincidence, Bruce! --Last night, I started sketching something that came out kind of similar to your approach, except I was using NPNs. Yours is better. (Did you set that up on a simulator?)

And, Darrel, I think I was going in your direction. This was to be my next step:

<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1997&stc=1&d=1189333924">

. . . with D1 and D2 generic small-signal or switching diodes (e.g., 1N914). I had long-forgotten about using a zener diode in that manner!

Bruce
- 9th September 2007, 13:04
Hi Russ,


(Did you set that up on a simulator?)

Yes. I ran it through Electronics Workbench. I would just go with some Alegro LED drivers,
but it does work if you have the board space.

Luciano
- 9th September 2007, 21:46
Hi,

This is the circuit posted by Bruce.

This version was tested on a breadboard with a microcontroller.
On the picture you can see the values of the resistors and the
type of transistors I have used.

Datasheet of the transistor BC558 (PNP)
http://www.fairchildsemi.com/ds/BC/BC558.pdf

http://img182.imageshack.us/img182/9887/bruceled2tb9.png

Best regards,

Luciano

flotulopex
- 10th September 2007, 06:22
I think I now understand clearly the difference between an electrician (me) and you clever engineers ;)

There's only one word to say: BRAVO!

... et merci 1000 fois.

NB: somebody talked about a "simulator". Is it really possible to simulate an electronic circuit that matches reality? Also with PICs?

sayzer
- 10th September 2007, 11:41
Ok; I removed my post.

Bruce
- 10th September 2007, 18:35
Nice work on testing/verifying all the various circuits Luciano.

I vote we keep this thread alive. I can't help but think there's
a better way to do this with fewer discreet components, and
even less quiescent current drain.

Seeing all the various circuit ideas is very interesting.

Maybe we should create a new topic category named Tips &
Tricks for hardware/software solutions similar to the Microchip
web forum & Tips & Tricks app-notes?

These spark a lot of interesting ideas/approaches to doing things.

Acetronics2
- 11th September 2007, 08:41
Hi, Folks

From the brainBoard ...

Et c'est la France qui repasse en tète ...

"The fingers in the nose" ... as we say here ...

Alain

PS : Tested ans Verified ... with 20 mA per Led ...

RussMartin
- 11th September 2007, 15:32
Bravo, Alain!

If you haven't seen it, here is Alain's tested circuit:

<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2007&stc=1&d=1189520806">

(His PDF file is easier to read.)

The input is at 2.75 VDC, eliminating the worry about a floating input pin when the input is set to high-Z.

I think I mentioned the possibility of using MOSFETs several posts back. I was going to try it with Luciano's original circuit, something like this:

<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2008&stc=1&d=1189520908">

Exchanging the positions of R6 with D1 and R5 with D2 in Alain's version will accomplish the same result, but without the voltage divider.

Luciano
- 11th September 2007, 23:07
Exchanging the positions of R6 with D1 and R5 with D2 in Alain's version
will accomplish the same result, but without the voltage divider.

Hi Russ,

This is not possible because on the original board made by Roger,
the anode of one LED is connected to the cathode of the other LED.

The purpose of the voltage divider was to keep the board as it is.
(The voltage divider can be made by adding one wire to the board).

http://img115.imageshack.us/img115/6162/ledboardbn7.png

Best regards,

Luciano

Acetronics2
- 12th September 2007, 10:08
This is not possible because on the original board made by Roger,
the anode of one LED is connected to the cathode of the other LED.

Luciano

Hi, Luciano

In your great science, do you have an answer for that :

" But why does always Roger make boards before thinking to how they should work ...??? "

Will "Swiss precision" only be a legend ???

LOL ...


Hi, Roger ...

Try to tell us about your Projects BEFORE heating the soldering Iron ...

... so much time saved !!!

Just Jokin' ...

Best Regards

Alain

Luciano
- 12th September 2007, 10:46
" But why does always Roger make boards before thinking to how they should work ...??? "
Will "Swiss precision" only be a legend ???
LOL ...

Hi Alain,

He must be a musician! Did and redo...Didgeridoo. (Note the assonance).

* * *

See this document about the three input pin variations of a 16F87x:
http://www.basicmicro.com/downloads/book/Smith_halfChp4.pdf

Best regards,

Luciano

flotulopex
- 12th September 2007, 21:57
As said, the first board I made was fitted with standard leds (picture in post #12).

But, following a good old swiss habit, I observe and think how to make things even better... and get into trouble.

Frankly, I thought this kind of question would have been common, maybe even boring.

A few days ago, I made a second prototype where I used my SMD NPN's and paired the leds. The visual effect is quite good (will make a video).

Now, if I have to make a third board with MOSFETs, this won't be so terrible (the iron is still hot).

And, please remember Leonardo Da VINCI: he invented so many things but built so few. I try to balance and do the opposite :D

Many many thanks to all.

NB: "Swiss precision" is not a legend and if you have a closer look to a chocolate bar, you'll notice that even the hazel nuts are lined-up! And yes, I'm a musician.

sayzer
- 14th September 2007, 09:42
Hey Roger,

I am getting a lot of good stuff via this post and all is free.

But, going back to your original issue, I was wondering why don't you consider using something like 74HC164 ? You can use three or four I/O pins and control cascaded 74HC164 ICs for 20 LEDs.

You can set all 20 LEDs with uS of times at once.

-------------------------------------

flotulopex
- 14th September 2007, 14:35
As you can see the image in my post#12, the led's PCB is quite small (narrow). It is ment to be put inside an existing stop-light case ("boîtier" in french).

I haven't enough space to put either the µc nor the power regulator on the led's PCB; this is why I made a second PCB for the "power & µc section". It is located outside the stop-light (still inside the car but not inside the case).

Finally, and this is why this all is about, I wanted to reduce the amount of wires between those two PCBs.

Voilà.

Another general info: I made my second proto with 15° leds; this viewing angle is to small, 24° must be better.