Author Topic: transistor output drive led and 5v pin together  (Read 5201 times)

0 Members and 1 Guest are viewing this topic.

Offline cosminnciTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: ro
transistor output drive led and 5v pin together
« on: January 28, 2014, 10:06:10 am »
I use an LM741 as a photoresistor comparator and the output goes in an port expander, the way the led and the resistor are connected output voltage on high is 2.6v instead of 5v.
normally I need it to pull low the pin and that is ok but does this 2.6v output when high affect the expander wich has a pullup to 5v?

regards,
Cosmin
« Last Edit: January 30, 2014, 07:01:36 am by cosminnci »
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: transistor output drive led and 5v pin together
« Reply #1 on: January 28, 2014, 08:01:19 pm »
Schema?
 

Offline cosminnciTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: ro
Re: transistor output drive led and 5v pin together
« Reply #2 on: January 30, 2014, 07:03:04 am »
I uploaded the schema, forgot to attach it first time :)
 

Offline papo

  • Regular Contributor
  • *
  • Posts: 93
  • Country: ch
Re: transistor output drive led and 5v pin together
« Reply #3 on: January 31, 2014, 12:43:26 pm »
Hello

Something is weird with your circuit. To turn on the transistor, you need a base-emitter voltage of at least 0.7 V or so do drive it out of cutoff. I'm wondering how you manage to do that since even with 5 V at the OpAmp output you'll have something like 0.45 V at the center of the R6-R13-divider.

This assumes infinite input impedance of the BJT (which it does not have, of course) and the ability of the 741 to hit the positive rail, which it can't do either. Violating these assumptions worsen the problem, though.

So how is it possible to pull the output pin low? Is this a simulation or did you build this up? In any case, it looks like you are operating the circuit at the bare boundaries of what the components can do. I would consider replacing the OpAmp with something that can go closer to the rail, maybe a real comparator.

Considering the expander problem, do you mean that the expander is open-drain and that a resistor ensures a high state when the input is floating? If so, that resistor would be in parallel with the LED and R1. I don't see a problem with that but I would investigate the 2.6 V issue.

Regards
Matt
 

Offline cosminnciTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: ro
Re: transistor output drive led and 5v pin together
« Reply #4 on: January 31, 2014, 02:20:08 pm »
Hello,
thank you Matt

I tested several values, one that works is R6 = 5k6 and R13 = 1k2
I use this with a photoresistor and a mcp23017 powered at 5 v with pullup enabled.
when c1_out is not conected to the mcp it has 2.6V when I connect it to the mcp it has 5V (the mcp`s pullup)

maybe calculating a propper voltager divider could solve the 2.6V issue?

regards,
Cosmin
 

Offline papo

  • Regular Contributor
  • *
  • Posts: 93
  • Country: ch
Re: transistor output drive led and 5v pin together
« Reply #5 on: January 31, 2014, 04:14:42 pm »
I tested several values, one that works is R6 = 5k6 and R13 = 1k2

Ah so with the 10k and 1k you have in your original schematic, it does not work? Just to clarify... since my initial guess was that this should not work. The updated values rise the level closer to the threshold voltage of the transistor but it's still pretty low.

I use this with a photoresistor and a mcp23017 powered at 5 v with pullup enabled.
when c1_out is not conected to the mcp it has 2.6V when I connect it to the mcp it has 5V (the mcp`s pullup)

So just to clarify even more, this is when the OpAmp output is low and the LED is off, right? You don't have any problems turning on that LED?

maybe calculating a propper voltager divider could solve the 2.6V issue?

Yes but to do that, you have to know the output voltage of the OpAmp. The problem is that this is difficult to figure out; An ideal OpAmp can have any output voltage between whatever you supply to it. In your case that is between 0 V and 5 V. But a real OpAmp does not work like that. A real OpAmp needs some "head room" between the supply rails and the output voltage. Maybe your output voltage is constrained to the range of 1 V to 4 V or even worse. Not only does this depend on the OpAmp, but also on the load you are attaching to the output.

That is unless you go for a rail to rail OpAmp, and even then, whether you can get close to the rail still depends on that load current. If you had an OpAmp that could go to 0.2 V and up to 3 V or whatever, you wouldn't even need that divider. At 0.2 V, your transistor is off and at 3 V, you can turn it on hard. You would still need a base resistor and maybe a pull-down but that's another story.

That said, the 2.6 V could be just due to leakage. The LED is off when you measure the 2.6 V, right? Reading 5 V when you have the expander in place points towards that direction. Anyway, does it work the way it should? If so and it's not drawing excess current anywhere (which I don't see how it could) you're fine I guess. Personally though I would not feel comfortable as there is the possibility that this works because you are on the edge of some parameters, so I would investigate this further to make sure that this is rock solid also when temperature changes etc.

Just out of curiosity, it would be interesting to measure the OpAmp output voltage and the base voltage of the transistor, both when the transistor is on and when it's off.

HTH, regards
Matt
 

Offline valentinc

  • Regular Contributor
  • *
  • Posts: 119
  • Country: ro
Re: transistor output drive led and 5v pin together
« Reply #6 on: February 01, 2014, 02:28:38 pm »
     I just quickly tried this circuit on a breadboard and works just fine... The output of the comparator goes very close to the supply rails (40-50mV below 5V and above 0V)...

     I also tried the same circuit with a TL072 op-amp, and had the same problem you had... The HIGH output was something around 3.5V and the LOW output around 1.4V...

      The comparator needs a pull-up resistor (R4) because the output is an open-collector configuration. Also note that because of this, the output of the comparator can only sink current, so only a PNP transistor can be used...

      In my opinion, you could use a better op-amp (which would get closer to the supply rails), but that would be more expensive than a simple comparator...
Valentin
 

Offline papo

  • Regular Contributor
  • *
  • Posts: 93
  • Country: ch
Re: transistor output drive led and 5v pin together
« Reply #7 on: February 01, 2014, 03:12:12 pm »
In my opinion, you could use a better op-amp (which would get closer to the supply rails), but that would be more expensive than a simple comparator...

Yep, that's what I meant. Looks much nicer than the original one. I would put a base resistor there, otherwise you are relying on the sinking capabilities of the comparator (or lack thereof, rather) to prevent excess currents. And within limits, you could still use an npn I think.

Regards
Matt
 

Offline papo

  • Regular Contributor
  • *
  • Posts: 93
  • Country: ch
Re: transistor output drive led and 5v pin together
« Reply #8 on: February 01, 2014, 03:28:07 pm »
Actually, this will not work with the expander in place because your emitter does not go down to ground due to the collector resistor. I'm sorry for having missed that. How about something like the attached schematic?

Regards

Matt

Edit: Of course you'd have to make sure to size the two resistors according to the current requirement through the diode, the 10k are just to get an impression. And this is assuming the open collector comparator as suggested by valentinc.
« Last Edit: February 01, 2014, 03:31:24 pm by papo »
 

Offline papo

  • Regular Contributor
  • *
  • Posts: 93
  • Country: ch
Re: transistor output drive led and 5v pin together
« Reply #9 on: February 01, 2014, 03:38:17 pm »
Or even simpler, get rid of the base resistor and size open-collector pullup accordingly. If you use an NPN you can do that, as there is no base current when the comparator outputs low.
 

Offline cosminnciTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: ro
Re: transistor output drive led and 5v pin together
« Reply #10 on: February 03, 2014, 12:21:32 pm »
Hi Matt, Valentin

the transistor base voltage is 0.6v led on and 0.3v led off
the op amp output is 4.25v led on and 1.41 led off
yes the 2.6v is when the led is off so it is current flowing trough the led and the resistor.

what if I would drive the mcp directly from the opamp output? the voltage looks right but I need it fliped.

regards,
Cosmin
« Last Edit: February 03, 2014, 12:25:11 pm by cosminnci »
 

Offline papo

  • Regular Contributor
  • *
  • Posts: 93
  • Country: ch
Re: transistor output drive led and 5v pin together
« Reply #11 on: February 03, 2014, 04:35:06 pm »
Hello

the transistor base voltage is 0.6v led on and 0.3v led off
the op amp output is 4.25v led on and 1.41 led off

I tried to determine the base current but I think you are down to measurement noise here. That said, for sure your base current is very low.

yes the 2.6v is when the led is off so it is current flowing trough the led and the resistor.

I'm really suspecting leakage here. Also, note that when you measure the collector voltage, you might pull down the collector a little bit with your meter.

what if I would drive the mcp directly from the opamp output? the voltage looks right but I need it fliped.

Would the mcp recognize the 1.41 volts as low? A brief look at the datasheet suggests this would not be the case (input low voltage = 0.2Vdd). Also I saw that you can disable the pullup if that's a concern for you. Can't you just invert the bit in software? In any case, you would run into exactly the same issues if you try to do the inversion with a BJT.

Really, I would decide how reliable you want this to be. If it just works for you and you are not concerned about temperature effects and the circuit not working anylonger if you swap out the transistor or the OpAmp for a different device of the same model, go with what you have. My understanding is that it works fine at least when the 100k pullup in the MCP is on.

If you are not happy with the circuit, investigate the comparator alternative.

HTH, regards

Matt
 

Offline cosminnciTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: ro
Re: transistor output drive led and 5v pin together
« Reply #12 on: February 04, 2014, 07:13:50 am »
Hi Matt,

yes it works fine, I inverted the state in the MCP and fed the opamp output into the mcp, this works ok too.
I`m happy how it works for now.

Thank you.
regards,
Cosmin
 

Offline cosminnciTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: ro
Re: transistor output drive led and 5v pin together
« Reply #13 on: February 19, 2014, 12:56:27 pm »

I have tested little more extensively the circuit and has some flaws.
could someone recommend an circuit for detecting light from a photo resistor, and outputting  ttl logic level for microcontroller.

regards,
Cosmin
 

Offline papo

  • Regular Contributor
  • *
  • Posts: 93
  • Country: ch
Re: transistor output drive led and 5v pin together
« Reply #14 on: February 19, 2014, 01:15:29 pm »
Hi

I have tested little more extensively the circuit and has some flaws.
could someone recommend an circuit for detecting light from a photo resistor, and outputting  ttl logic level for microcontroller.

Can you tell us about the flaws? Because I used a similar circuit before and it wasn't that bad. The problem I was addressing though was to detect a specific light source and my measurement was affected by ambient light. So I ended up with pulsing the light source and adding a bandgap to the receiver but I don't have the impression that this is what you are trying to achieve.

If you just want TTL, I don't see why the first half of the circuit (potentiometer, voltage divider with a fixed resistor/trimmer and the LDR, comparator) shouldn't do the job.

Regards

Matt
 

Offline cosminnciTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: ro
Re: transistor output drive led and 5v pin together
« Reply #15 on: February 20, 2014, 06:48:27 am »
the project is an laser barrier wich is read by an mcp23017 and then a arduino.
the laser does a good job and ambient light is not a problem, and the setup works at slow speed, but when I pass faster it skips somme.

I boosted the i2c speed to 400Khz and still have these random misses.
I believe maybe because the out is only 2.6v in High level and the mcp pullup pulls till 5v maybe the rise time could be a problem.

but I would like to build a new version that works, input from photo resistor  and output ttl level.

regards,
Cosmin
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf