need help with simple circut

Ron H

Joined Apr 14, 2005
7,063
You need to be aware that, with a 3V supply, the input common mode range may only range between 0V and +1.5V. That means that your comparator will not work over the full range of your pots.
 

Thread Starter

nitrosmd

Joined Jul 20, 2013
59
Supply voltage; 5V (+36 or ±18V)

Then what could the "5V" possibly mean?
Actually I wasn't really sure how to read that. So thanks for pointing this out.
So are "they" running it at 5V, but the max ratings are (+36V or ±18V)??? If this is right, then which one is the actual max 36V or 18V?

I'm still processing the remainder of these posts. Thanks all.
 

LDC3

Joined Apr 27, 2013
924
Actually I wasn't really sure how to read that. So thanks for pointing this out.
So are "they" running it at 5V, but the max ratings are (+36V or ±18V)??? If this is right, then which one is the actual max 36V or 18V?

I'm still processing the remainder of these posts. Thanks all.
It's 36V or +18V and -18V (for a total of 36V).
 

Thread Starter

nitrosmd

Joined Jul 20, 2013
59
and you want to place any comparators you are not using into well defined states..
Ok, I guess I will hook up the remainder of the inputs to positive and ground respectively. Is this necessary for my experiment or is it more something that should be done when I formalize the circuit.

Could we PLEASE see a schematic?
So I have a picture of something I drew up on graph paper. No judgments please! I'm sure there's a million holes. It's based on the schematic Bertus linked on page 1 of this thread (thanks).

I drew my broad stroke understanding and replaced the LDRs with photo transistors. I was trying to get one step working at a time. So I was trying to hook up the top comparator "output" to the base an npn transistor to activate an LED. Without further ado:
 

Attachments

Thread Starter

nitrosmd

Joined Jul 20, 2013
59
WBahn I will take your advice and experiment as you mentioned with the resistor. I should be able do do this tonight after my daughter goes to bed.
Thanks for your help.
 

Thread Starter

nitrosmd

Joined Jul 20, 2013
59
NO!!!!

Take a resistor an connect one end of it to Vcc. Now take your voltmeter and measure the voltage at the other end of the resistor relative to ground. What is the voltage?

When you have a resistor tied to Vcc and the output pin (pin 14), when the output is NOT asserting a LO (which will get you around 0.2V to 0.3V usually), the transistor is turned off, meaning it might as well be disconnected from the output pin, which means that ALL you have is a resistor tied on one side to Vcc and the other side, the side connected to the output pin, that is effectively floating.
I thought I might have been mangled the hi/lo definitions. I get it now.

I've think i've finally made some sense of what you've been describing. I want to state my latest understanding.

The output of the comparator is actually applied to the base of an npn transistor (integrated into the chip) and the collector is exposed (open collector). When the transistor is ON, it lets current run from output to ground. When it is OFF, it's practically disconnected enabling current to flow through the pull up resistor and opposite the direction of the collector (output).

Ok, so where does the 0.3v come from in the OFF state? I thought current can on flow from collector or base to emitter with an npn transistor?

Still waiting to experiment.
 

LDC3

Joined Apr 27, 2013
924
Ok, so where does the 0.3v come from in the OFF state? I thought current can on flow from collector or base to emitter with an npn transistor?
Even when the transistor is fully on, there is some resistance in the transistor. After all, it is called a semiconductor.
 

WBahn

Joined Mar 31, 2012
30,055
Actually I wasn't really sure how to read that. So thanks for pointing this out.
So are "they" running it at 5V, but the max ratings are (+36V or ±18V)??? If this is right, then which one is the actual max 36V or 18V?

I'm still processing the remainder of these posts. Thanks all.
One of the secrets to reading the datasheet is to look at what they say about the test conditions. There will usually be something at the top of the table telling you about conditions that are applicable to all specs in the table unless specifically indicated otherwise, and then each row will usually have additional conditions that only apply to that row.

Most of the entries in the data sheet are for Vcc=5V, but not all of them.

+36V and ±18V are the same thing. They are saying that (Vcc-GND) can be at most 36V. But they are also letting you know (in more ways than just this) that GND can be 0V and that it will work find with input/output signals that are also referred to the same 0V.
 

WBahn

Joined Mar 31, 2012
30,055
Ok, so where does the 0.3v come from in the OFF state? I thought current can on flow from collector or base to emitter with an npn transistor?
When the output is LO, this is accomplished by turning the transistor on hard, which places it in saturation. But there is a "saturation voltage" than is needed in order to conduct much current at all and that voltage is in the range of a couple tenths of a volt. As you require the output to sink more current, that voltage will rise, but only slowly.

What is important is that it remain at a low enough voltage so that whatever circuitry is connected to the output pin will recognize it as a logic LO. Usually, anything below about 0.8V will satisfy this (but it depends on the specifics of what you have connected to it).
 

WBahn

Joined Mar 31, 2012
30,055
Ok, I guess I will hook up the remainder of the inputs to positive and ground respectively. Is this necessary for my experiment or is it more something that should be done when I formalize the circuit.
For this part, you can probably get away with leaving them unconnected initially. But it is good practice to do it right from the get go. For one thing, how foolish would you feel spending hours trying to figure out why the circuit is behaving erratically only to finally discover that it is because one of the unused comparators is flailing around causing all kinds of power supply noise that is affecting your phototransistors? Second, there are some parts, such as CMOS logic parts, that can be destroyed by leaving the inputs floating. So, again, just get in the habit of always dealing with it from step one.

So I have a picture of something I drew up on graph paper. No judgments please! I'm sure there's a million holes. It's based on the schematic Bertus linked on page 1 of this thread (thanks).
The schematic looks fine. Nice and neat and easy to follow.

I drew my broad stroke understanding and replaced the LDRs with photo transistors. I was trying to get one step working at a time. So I was trying to hook up the top comparator "output" to the base an npn transistor to activate an LED. Without further ado:
The big thing is that you don't have any path for the current in the phototransistors. The inputs to the comparators are very high impedance inputs and allow essentially zero current.

Put resistors from the emitters to gound on each phototransistor.

Be aware that even if your comparators are rail-to-rail, your H-bridge transistors are configured as emitter followers which means that you are going to drop a total of about 1.4V across them, leaving only 1.6V or so for the motor itself.

And be sure to add the pullup resistor to each comparator output!
 

Thread Starter

nitrosmd

Joined Jul 20, 2013
59
Got results. Made progress. Still some issues though.

NO!!!!

Take a resistor an connect one end of it to Vcc. Now take your voltmeter and measure the voltage at the other end of the resistor relative to ground. What is the voltage?

When you have a resistor tied to Vcc and the output pin (pin 14), when the output is NOT asserting a LO (which will get you around 0.2V to 0.3V usually), the transistor is turned off, meaning it might as well be disconnected from the output pin, which means that ALL you have is a resistor tied on one side to Vcc and the other side, the side connected to the output pin, that is effectively floating.
I did the above. I only had 47k and 220k resistors to work with. I used the 47k as the pull up.

220k from ground tied to pin 8 (input 3-)
47k from vcc tied to 9 (input 3+)
47k pull up tied to 14 (out)

Reading from out to ground = 2.75V (WORKS)
Reversed inputs reading = 009.6mv (WORKS)

Now when I tried to use Vcc for both input resistors, it failed.
220k @ 2.45v on input 3-
47k @ 2.79v on input 3+
47k pull up tied to out

Reading from out to ground = 009.6mv (failed)
Reversed inputs reading = 009.6mv (same although technically this works)

Maybe this has to do with the following quote?

You need to be aware that, with a 3V supply, the input common mode range may only range between 0V and +1.5V. That means that your comparator will not work over the full range of your pots.
For this part, you can probably get away with leaving them unconnected initially. But it is good practice to do it right from the get go. For one thing, how foolish would you feel spending hours trying to figure out why the circuit is behaving erratically only to finally discover that it is because one of the unused comparators is flailing around causing all kinds of power supply noise that is affecting your phototransistors? Second, there are some parts, such as CMOS logic parts, that can be destroyed by leaving the inputs floating. So, again, just get in the habit of always dealing with it from step one.
Understood


The big thing is that you don't have any path for the current in the phototransistors. The inputs to the comparators are very high impedance inputs and allow essentially zero current.

Put resistors from the emitters to gound on each phototransistor.
This reminds me of the pull up concept. Makes sense. It's probably good I used resistors in my tests.
 

WBahn

Joined Mar 31, 2012
30,055
I did the above. I only had 47k and 220k resistors to work with. I used the 47k as the pull up.
You can always put two or three 47kΩ resistors in parallel to get a lower value.

Now when I tried to use Vcc for both input resistors, it failed.
220k @ 2.45v on input 3-
47k @ 2.79v on input 3+
47k pull up tied to out

Reading from out to ground = 009.6mv (failed)
Reversed inputs reading = 009.6mv (same although technically this works)

Maybe this has to do with the following quote?

Originally Posted by Ron H
You need to be aware that, with a 3V supply, the input common mode range may only range between 0V and +1.5V. That means that your comparator will not work over the full range of your pots.
This is exactly what it has to do with. Once you exceed the spec'ed input common mode range you are operating out-of-spec, which means anything goes. It could blow up, catch fire, give bogus outputs, start a global thermonuclear war, or do exactly what you would like it to do -- all of those are equally valid as far as the specs are concered.

Make a voltage divider using 110kΩ as the top resistor (two 220kΩ resistors in parallel) and a 47kΩ resistor as the bottom resistor. This should give you about 0.9V at the junction. Build one of these for each input. This will nominally place both inputs at the same voltage, but one of them will be a bit higher than the other and the output should respond accordingly.

Now take a 220kΩ test resistor and place it in parallel with the top resistor on the +input. This should raise it enough to for the output HI. Now place it in parallel with the bottom resistor on the +input. This should force the output LO. Do the same for the -input and see if you get the opposite results.

With 5% tolerance resistors, this should work but there is a slight change the component variations make make it fail. But using two 220kΩ resistors in parallel as your test resistor should ensure that it works.

One concern I have is that the input bias current of the LM339 could be as high as 250nA. But since your voltage divider has a current of 3V/(220kΩ+47kΩ)=11μA. this shouldn't be a big problem.
 

Thread Starter

nitrosmd

Joined Jul 20, 2013
59
I finally got 1.5v and -1.5v readings through my comparator/h-bridge setup which is incredibaly rewarding. !! HURRAY !!! However, it won't quite do any work (light led, turn motor).

Before I ask more questions, I want to express my grattiude again. Thanks Ron H, WBahn and others for your help.

I bought a variety pack of resistors and plugged 1k's for the pull-up resistors as wBahn mentioned. I measured amps, after the resistor (before the hbridge) and got 2.6mA (2.8v) when high. This is right.

After the first (upper) npn transistor in the hbrdige, it gains to 24mA (2.22v). If I bypass the second corner of the hbridge, my led will light up. So I know I need about this much for an led.

Adding the second corner in drops it down to 15mA (1.6v). Is there any way to increase the throughput here? Ron H had warned me of this I know.

I tried two things, first I lowered the value of the pull-up resistor. I lowered it down to 100 ohms. Am I ok here? What's the optimal resistance for saturation without pushing too much through the base. Using 2n222a(npn) 2n3906(pnp). Maybe my transistors are not ideal either.

Second I doubled the total supply from 3.0v to 6.0v using 1k resistors with no luck turning the led on either, but I'm going to have to get you the numbers on that I'm sure.

I'd like to keep the voltage down so I can charge batteries up via solar cells. I have a bunch of .05v 3amp cells, but they are a bitch to cut.

Finally, it's very possible I wired my circuit wrong so I'm going to post pictures. I don't know anything about wiring conventions (red is positive :) and had limited jumper wire. Hope it's understandable.

WBahn, I know the inputs are largely floating, I'll fix that but I had some questions. Should I leave the remainder of outputs floating or hook them up too? Also should I hook resistors up to the inputs or is bare wire fine?

Thanks again!
 

Attachments

WBahn

Joined Mar 31, 2012
30,055
Congratulations. Glad you are making progress. I haven't looked at your circuit pics yet, so won't comment on most of the stuff. But will answer your last few questions:

WBahn, I know the inputs are largely floating, I'll fix that but I had some questions. Should I leave the remainder of outputs floating or hook them up too? Also should I hook resistors up to the inputs or is bare wire fine?
I never leave inputs floating without a damn good reason, even on a breadboard. So I recommend you do fix that promptly.

In almost all cases, you want/need to leave unused outputs floating. There are exceptions, but this can be lumped into the basic rule of thumb that unused outputs are left floating unless there is a damn good reason.

Just do be aware that damn good reasons do exist, rare as they might be.

As for exactly how you deal with unused inputs, that depends. In a breadboarding scenario, just tying them to ground is usually sufficient. Using bare wire is generally just fine, as long as your take the usual care to ensure that you don't short it to something. For something further along, more careful consideration should be given to the best way (or a way that is truly "good enough") to handle this. Often times this would involve tying the unused input to a supply rail through a resistor. In the case of comparators and opamps, you generally want to tie the two inputs to different voltages to ensure that the device isn't flailing due to noise as a result of having the inputs tied to the same level. There are several simple approaches you can take to address this adequately.
 

Thread Starter

nitrosmd

Joined Jul 20, 2013
59
Update:

None of the remaining inputs are floating now :)

I’m not getting much current through the h-bridge, I dropped the value of the pullup resistors to get more current, but I hit a wall. I first tried 1k and got about 30mA through the h-bridge. Then I tried:

680Ω (about 45mA)
330Ω (about 70ma).
180Ω (about 73ma).

I didn’t make it much lower 380Ω… 180Ω worked and even though the current read more, the LEDs didn’t shine as bright. This made little sense to me and the only way I could justify is by saying current was more inclined to pass through my multimeter then the LED.

The bottleneck seems to occur between the pnp transistors and the 2nd comparator output when it’s low (short circuited to ground). I think there’s resistance along the short, because if I supplement the base with a bare wire to ground, I get around 800mA.

I have a feeling that if I just put a bigger battery on it (more voltage), I’ll get the h-bridge to open up more, but I don’t want to do that, I even I think 3 AAAs is two much.

Does anybody have suggestions for current dilemma above?

Other observations:

Under inside lighting conditions, this circuit works well as a solar tracker. It’s not really meant to be, but it’s fun to watch the phototransistors compete. I’m using 2 leds to represent the motor turning in either direction. When I hit the sweet spot and photos are equally lit, both h-bridge LEDs are off. Else either one LEDs is on OR the other (unless there’s no light, then there both off).

Outside, in sunlight, only one light turns on, NEVER the other. It breaks giving me .8v only unless I cast a shadow on one or the other only then do I get positive and negative voltages respectively. Sometimes both LEDs turn on (is it oscillating?). This was interesting thought and made me curious about what a comparator does when input voltages are exactly equal (I’m assuming that both transistors are fully saturated). I read that different comparators do different things. What should I expect of the LM339?

My biggest concern at this point is current, so if someone can help me out there, I will be forever grateful :)
 

Thread Starter

nitrosmd

Joined Jul 20, 2013
59
I'm just clueless.

In my previous test, I thought I had it traced it to the pnp transistor. Which maybe holds true. It's hard to tell.

I simply can't lower the value of these pull up resistors past a certain point which I need to do in order to fully open the transistors. If I move down from 380 to 180 ohms on the pullups, I don't get a much voltage through the h-bridge. If I lower just one pull-up, things I get lots of current, but as soon as I equalize the pull-up on the other side, it stop functioning.

Maybe the base in both upper corners of the h-bridge are active at the same time. With such low resistance values, which again, leads me to believe that there's not enough of a drain through the comparator in it's low state. I just don't know.
 

WBahn

Joined Mar 31, 2012
30,055
This has dragged on for many pages and many tweaks to the circuit, which is fine. But it also makes it very hard to know what the exact circuit is that you are working with presently. Could you post an updated schematic to get us all back on the same page?
 
Top