Author Topic: Circuit with op amp lm339  (Read 28381 times)

0 Members and 1 Guest are viewing this topic.

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Circuit with op amp lm339
« on: December 25, 2015, 10:31:14 pm »
Hello, i have build this simple  circuit on a breadboard to learn electronics.

But when I connect power supply, the led turns on.  I thought that the led will turn on only when I apply a magnetic field to the coil. How do I achieve that?

Because now the op amp works as a comparator, and when I apply the magnetic field it induces a current on both sides of a coil, but it should do  just on one of  the terminals to connect the gnd to power supply.  And then led should turn on. (Theoreticaly)

Can someone analyze the circuit and describe, what is actually happening here? Thank you.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Circuit with op amp lm339
« Reply #1 on: December 25, 2015, 10:45:29 pm »
Yes, that's what you should expect to happen. The op-amp's bias current will flow out of both the inverting and non-inverting inputs. The voltage at the inverting input will be slightly higher than the non-inverting input because the resistance of the coil will mean it develops a voltage across it.

When a magnet is moved across the coil then LED may flicker off if the coil generates a negative voltage for long enough.
 

Offline Seekonk

  • Super Contributor
  • ***
  • Posts: 1938
  • Country: us
Re: Circuit with op amp lm339
« Reply #2 on: December 25, 2015, 10:58:56 pm »
You could bias the negative input slightly, a few milivolts, to insure the op amp does not turn on until a signal is present. That circuit is not guaranteed to work with every chip.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Circuit with op amp lm339
« Reply #3 on: December 25, 2015, 11:27:11 pm »
LM339 is not opamp. It is a comparator. And beware od the pinout. :-+
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #4 on: December 26, 2015, 02:09:38 pm »
How do you know, that when I move a magnet across the coil, it generates a negative voltage?

How can I make with only these components the other way around? So that when I move a magnet across the coil it will light up the led.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Circuit with op amp lm339
« Reply #5 on: December 26, 2015, 04:19:27 pm »
Moving a magnet across the coil will produce both a negative any a positive voltage, depending on the field and direction of movement.

Have you measured the voltage on the coil using an oscilloscope?
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #6 on: December 26, 2015, 07:52:37 pm »
I can confirm that the circuit does work, using one of the opamps in a TL082. The LED is off, until I move a magnet rapidly past a coil taken from a small relay. Then the LED flashes briefly -- as it should, since the circuit isn't a "magnetic field detector" but rather a "change in magnetic field detector". See Faraday's Law of Induction. The voltage induced in a coil is proportional to the _time rate of change_ of the magnetic flux applied to the coil.

I don't know why nForce's LED is on all the time.


A ratiometric Hall effect sensor (Allegro A3503) makes a much better "magnetic field detector" than the relay coil does, though.

« Last Edit: December 26, 2015, 07:57:43 pm by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #7 on: December 26, 2015, 08:17:20 pm »
That's strange, there are two different explanations of how the circuit works. And it's a simple circuit.

My theory is this:

The output of the op amp (someone called it a comparator) is switching between a GND and 9 V. Because those two voltages (0V and 9V) are on the supply terminals of the op  amp. If there is 9 V on the output, there is no potential difference between the terminals and no current will run. If there is GND, there is a potential difference and the current will run, lightning up the LED. But there is something odd, why doesn't the LED burn out, because there is 9V? Maybe that 1K ohm resistors helps.

Well this is how I understand working of this circuit. Can someone with a lot of practice confirm it?

@Hero999 Sorry i don't have an oscilloscope, because i don't have the money for buying one. I have bought these electric components for $10.
 

Offline Seekonk

  • Super Contributor
  • ***
  • Posts: 1938
  • Country: us
Re: Circuit with op amp lm339
« Reply #8 on: December 26, 2015, 10:43:13 pm »
It is a hobby circuit designed to teach you not to trust what you see on the internet.  The 339 has up to 3mv of offset on the input.  Shorting the inputs to common the output is undefined.  You should always have  several mv  designed into the circuit to define the output to a certain state.  The input is not protected.  Spec says not to let input drop below -.3V.  Get near a good magnetic field and the chip may self destruct.  Good luck.
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #9 on: December 26, 2015, 11:19:50 pm »
The inputs are not exactly shorted to ground... well, one is, but the other one is on the other end of the relay coil. The relay coil I used for testing my version has about 50 ohms DC resistance.
« Last Edit: December 27, 2015, 12:01:10 am by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #10 on: December 27, 2015, 12:22:01 am »
May I suggest this slightly modified circuit?

I don't know if it will work with the lm339 but it's a lot of fun with the TL082. It will detect the motion of a magnet, moving quite slowly, from several inches away.

The easiest person to fool is yourself. -- Richard Feynman
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #11 on: December 27, 2015, 01:02:20 am »
That's strange, there are two different explanations of how the circuit works. And it's a simple circuit.

My theory is this:

The output of the op amp (someone called it a comparator) is switching between a GND and 9 V. Because those two voltages (0V and 9V) are on the supply terminals of the op  amp. If there is 9 V on the output, there is no potential difference between the terminals and no current will run. If there is GND, there is a potential difference and the current will run, lightning up the LED. But there is something odd, why doesn't the LED burn out, because there is 9V? Maybe that 1K ohm resistors helps.

Well this is how I understand working of this circuit. Can someone with a lot of practice confirm it?

@Hero999 Sorry i don't have an oscilloscope, because i don't have the money for buying one. I have bought these electric components for $10.

Yes, the op-amp is being used as a comparator in this circuit. The output changes state from HI to LO depending on which of the inputs has the higher voltage.

What you have said here is correct. Say the LED's forward voltage drop is 2.2 V. So to calculate the current through the LED and the 1000 ohm resistor with a 9V supply, you use Ohm's Law. V=IR, so I=V/R.

 (9-2.2) = 6.8 V  , and 6.8 V / 1000 Ohms = 6.8 mA, which is fine for a modern, bright LED.


Homework question: Say you want 20 mA through the LED. What should the value of the resistor be in that case?

« Last Edit: December 27, 2015, 01:06:52 am by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #12 on: December 27, 2015, 01:36:10 am »
Oscilloscope trace (single-shot) obtained by sweeping one pole of a NdBFe magnet rapidly past the end of the 50 ohm miniature relay coil. If I use the other pole of the magnet, the trace is reversed (first peak positive, second peak negative.)  If I go faster the voltages are greater. Faraday's Law of Induction in action!
The easiest person to fool is yourself. -- Richard Feynman
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Circuit with op amp lm339
« Reply #13 on: December 27, 2015, 11:13:13 am »
That's strange, there are two different explanations of how the circuit works. And it's a simple circuit.
No, only one explanation for how the circuit works has been given. I only provided a possible reason for the circuit not working.

It is a hobby circuit designed to teach you not to trust what you see on the internet.  The 339 has up to 3mv of offset on the input.  Shorting the inputs to common the output is undefined.  You should always have  several mv  designed into the circuit to define the output to a certain state.  The input is not protected.  Spec says not to let input drop below -.3V.  Get near a good magnetic field and the chip may self destruct.  Good luck.
Yes, unless the resistance of the coil is very high, the input offset voltage will dominate the bias current.

The circuit should work with the LM339, with a couple of modifications. Connect a 470k resistor between the non-inverting input to raise the input voltage a few mV above 0V. The bias current will develop a voltage across the resistor which should be greater than the offset voltage, thus ensuring the non-inverting input high enough above the inverting input to cause the output to go high and the LED turn off. Adding diode in reverse parallel with the coil will provide some protection against negative voltages.
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #14 on: December 27, 2015, 04:26:16 pm »
Two points: The circuit above is still not a "magnetic field detector", it is a _change_ in magnetic field detector. If the applied field isn't changing, there is no voltage induced in the coil and the circuit just sits there doing nothing.
 
And the circuit (on my breadboard using 1/2 TL082 and a 50 ohm miniature relay coil) still isn't very sensitive. It still requires very fast magnet motion very near to the coil for the LED to flash briefly.

Try this variant. It has much improved sensitivity, will detect fast magnet motion from several inches away and slow magnet motion from an inch or so by turning the LED on for as long as it detects the magnet is moving.

I don't  know if it will work the same way with the LM339 (using the correct pin numbers for that op-amp of course), I don't have one on hand to test. It doesn't work very well with the LM358n, it probably needs the high-impedance inputs provided by the TL082.
« Last Edit: December 27, 2015, 05:35:16 pm by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline Seekonk

  • Super Contributor
  • ***
  • Posts: 1938
  • Country: us
Re: Circuit with op amp lm339
« Reply #15 on: December 27, 2015, 04:58:17 pm »
YIPES!
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #16 on: December 27, 2015, 05:36:51 pm »
YIPES!

Change the feedback resistor R2 to 47k for even greater sensitivity. 

(I've made this change on the circuit diagram and reposted it above.)

A 0.1 uF cap in parallel with the feedback resistor may be needed if the circuit oscillates.
« Last Edit: December 27, 2015, 05:44:11 pm by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline Seekonk

  • Super Contributor
  • ***
  • Posts: 1938
  • Country: us
Re: Circuit with op amp lm339
« Reply #17 on: December 27, 2015, 05:50:11 pm »
Capacitors.  Let's add some capacitors.

I don't need to build one of these.  I have a GHOST METER that I picked up.  Photo is unretouched, you can find these on ebay.  It flashes and beeps.  This won't do anything around my equipment or TV but there is a place in the middle of the living room that it goes crazy, oooooooooh scary.  GHOST METER, Don't stay home without it!
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Circuit with op amp lm339
« Reply #18 on: December 27, 2015, 05:54:16 pm »
Capacitors.  Let's add some capacitors.

I don't need to build one of these.  I have a GHOST METER that I picked up.  Photo is unretouched, you can find these on ebay.  It flashes and beeps.  This won't do anything around my equipment or TV but there is a place in the middle of the living room that it goes crazy, oooooooooh scary.  GHOST METER, Don't stay home without it!
Lol, how about doing a teardown?
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #19 on: December 27, 2015, 05:59:47 pm »
The scale should read "milliGHOSTS"  instead of milliGauss.....      :-DD
The easiest person to fool is yourself. -- Richard Feynman
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #20 on: December 27, 2015, 06:41:59 pm »
Capacitors.  Let's add some capacitors.

(snip)


OK.... how about this then.  Eliminate the feedback resistor altogether and replace it with a 200 nF monolithic ceramic cap (I used 2 ea. 100nF in parallel).   Now the circuit has _crazy_ sensitivity. It will detect the motion of a weak magnet moving slowly, several inches away, and a strong magnet at six inches or more.
The easiest person to fool is yourself. -- Richard Feynman
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #21 on: December 27, 2015, 09:43:43 pm »




Some one asked a few days ago about simple circuits for scoping. This is one such. The circuit has a tendency to self-oscillate, which makes the LED look like it's "ON" continuously, but really it is turning on and off very rapidly. (This is why the OP's LED appeared to be continuously ON, probably: the op-amp was probably oscillating and making the LED look like it was continually lit. Maybe.) This effect can be seen with the scope, which can tell you whether the LED is in fact solidly ON, or is oscillating rapidly, and so helps you to find the right place to install capacitors to kill the oscillations.
« Last Edit: December 27, 2015, 09:50:17 pm by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline edavid

  • Super Contributor
  • ***
  • Posts: 3383
  • Country: us
Re: Circuit with op amp lm339
« Reply #22 on: December 27, 2015, 09:54:37 pm »
Yes, the op-amp is being used as a comparator in this circuit.

If it's an LM339, it's actually a comparator being used as a comparator :)
 

Offline Seekonk

  • Super Contributor
  • ***
  • Posts: 1938
  • Country: us
Re: Circuit with op amp lm339
« Reply #23 on: December 27, 2015, 10:55:09 pm »
When I was a kid I made the amplifier section of a radio cluck like a chicken.  I probably
couldn't do that now if I tried.  So there is something to be said about experimenting and
connecting parts up randomly.

The following circuit provides about 3 mv (matching that of the maximum offset of the 339)
of bias assuming a 50 ohm coil. This should guarantee a solid off or on state of the LED.
Input connections depend it you want it off or on. This should prevent oscillations.  An
added advantage is that it offsets the inputs at half the supply voltage.  That should
provide sufficient protection for input spikes.

Biasing the input will make it stable.  However, you never know which way the offest of
the op amp input is.  That could require up to 6 mv of signal before the comparator trips.
Placing the coil in a resistor H configuration with a 10K pot in the upper or lower feed
ia an option.  Then it could be adjusted to the edge of tripping with just 1 mv of offset.
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #24 on: December 28, 2015, 11:37:39 am »
That's strange, there are two different explanations of how the circuit works. And it's a simple circuit.
No, only one explanation for how the circuit works has been given. I only provided a possible reason for the circuit not working.

It is a hobby circuit designed to teach you not to trust what you see on the internet.  The 339 has up to 3mv of offset on the input.  Shorting the inputs to common the output is undefined.  You should always have  several mv  designed into the circuit to define the output to a certain state.  The input is not protected.  Spec says not to let input drop below -.3V.  Get near a good magnetic field and the chip may self destruct.  Good luck.
Yes, unless the resistance of the coil is very high, the input offset voltage will dominate the bias current.

The circuit should work with the LM339, with a couple of modifications. Connect a 470k resistor between the non-inverting input to raise the input voltage a few mV above 0V. The bias current will develop a voltage across the resistor which should be greater than the offset voltage, thus ensuring the non-inverting input high enough above the inverting input to cause the output to go high and the LED turn off. Adding diode in reverse parallel with the coil will provide some protection against negative voltages.


How did you calculate the resistor value? So it has to be 470k?
 

Offline Seekonk

  • Super Contributor
  • ***
  • Posts: 1938
  • Country: us
Re: Circuit with op amp lm339
« Reply #25 on: December 28, 2015, 02:40:30 pm »
25nA  input current X 470,000 to get at least 3mv, though it appears to be three times the resistance needed unless I missed a decimal place.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Circuit with op amp lm339
« Reply #26 on: December 28, 2015, 02:51:24 pm »
25nA  input current X 470,000 to get at least 3mv, though it appears to be three times the resistance needed unless I missed a decimal place.
Yes and choosing thee times the resistance needed was deliberate, as the bias current could be much lower than specified on the datasheet, which just gives the typical and highest values, not the lowest.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Circuit with op amp lm339
« Reply #27 on: December 28, 2015, 05:21:13 pm »
That's strange, there are two different explanations of how the circuit works. And it's a simple circuit.

My theory is this:

The output of the op amp (someone called it a comparator) ..

Sorry to bother you again, that is not "someone called it", LM339 actually is a comparator, cannot be used as a general purpose opamp! You cannot interchange the two. Not the same!

Another piece you should know (and was mentioned in the beginning) is that some type of input circuitry (usualy with PNP stages) allows operation below ground level. Usually up to some hundred mV. Typical OPAMPies and COMPies like that are LM358, LM324, LM393, LM339, ... In the datasheet search for a term of "input commonmode voltage range" and that shout "include ground" if operation like that is required.

 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #28 on: December 28, 2015, 07:06:28 pm »
OK... so I went out to my local supplier and bought an LM339. For a dollar ... what a ripoff, could have ordered 10 for $3.50, free shipping from Colorado, but I didn't want to wait 3 or 4 days for them to get here.    :rant:

I breadboarded Hero999's version and it works fine ... but it does have a tendency to oscillate, which keeps the LED "on" (really, it's flashing on and off so fast it looks continuously on.) I cured this self-oscillation by putting 0.1 uF ceramic caps from pins 6 and 7 to Ground. Now the LED stays nicely off until I move a magnet past the coil.

The circuit is more sensitive than I expected (using the same ~50 ohm miniature relay coil) but nowhere nearly as sensitive as the TL082 version that I posted and demonstrated in the video above.

The easiest person to fool is yourself. -- Richard Feynman
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Circuit with op amp lm339
« Reply #29 on: December 28, 2015, 07:30:26 pm »
That's strange, there are two different explanations of how the circuit works. And it's a simple circuit.

My theory is this:

The output of the op amp (someone called it a comparator) ..

Sorry to bother you again, that is not "someone called it", LM339 actually is a comparator, cannot be used as a general purpose opamp! You cannot interchange the two. Not the same!

Another piece you should know (and was mentioned in the beginning) is that some type of input circuitry (usualy with PNP stages) allows operation below ground level. Usually up to some hundred mV. Typical OPAMPies and COMPies like that are LM358, LM324, LM393, LM339, ... In the datasheet search for a term of "input commonmode voltage range" and that shout "include ground" if operation like that is required.


Yes, it's important to be aware of the internal workings of the op-amp/comparator when dealing with a circuit like this. Looking at the input stage it's clear the bias current is positive, i.e. the inputs source current.



It's also interesting you mention the distinction between op-amps and comparators. It's possible to get an LM339 to work as an op-amp but it's not ideal. The datasheet even shows an example of a VCO which uses one of the comparators as an op-amp to form an integrator.


http://www.ti.com/lit/ds/symlink/lm339-n.pdf

OK... so I went out to my local supplier and bought an LM339. For a dollar ... what a ripoff, could have ordered 10 for $3.50, free shipping from Colorado, but I didn't want to wait 3 or 4 days for them to get here.    :rant:

I breadboarded Hero999's version and it works fine ... but it does have a tendency to oscillate, which keeps the LED "on" (really, it's flashing on and off so fast it looks continuously on.) I cured this self-oscillation by putting 0.1 uF ceramic caps from pins 6 and 7 to Ground. Now the LED stays nicely off until I move a magnet past the coil.

The circuit is more sensitive than I expected (using the same ~50 ohm miniature relay coil) but nowhere nearly as sensitive as the TL082 version that I posted and demonstrated in the video above.


Wow that's expensive!

You could've easily used the LM393 which will probably be cheaper as it only contains two comparators.

 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #30 on: December 28, 2015, 07:51:07 pm »
25nA  input current X 470,000 to get at least 3mv, though it appears to be three times the resistance needed unless I missed a decimal place.

This is maybe a beginners question, but: From where does this input bias current come from? There is no negative loop, no positive loop and no current or voltage source. Only the coil.
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #31 on: December 28, 2015, 07:59:48 pm »
@Hero999:

Looking through my parts stash, I found a LM393 in there, a used pull! So I'll give it a try next.

But what's worse.... I found 2 brand new LM339s that I didn't know I had, not on the inventory list. SO I didn't need to go out and spend any money, either way.   :palm:
The easiest person to fool is yourself. -- Richard Feynman
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Circuit with op amp lm339
« Reply #32 on: December 28, 2015, 08:49:57 pm »
25nA  input current X 470,000 to get at least 3mv, though it appears to be three times the resistance needed unless I missed a decimal place.

This is maybe a beginners question, but: From where does this input bias current come from? There is no negative loop, no positive loop and no current or voltage source. Only the coil.
It comes from the base of Q1 & Q4, shown in the schematic attached to my previous post.
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #33 on: December 28, 2015, 09:15:33 pm »
So if I understand correctly, the input bias current runs from non-inverting and inverting input out. So away from the inputs, not in  the comparator.
 

Offline SeanB

  • Super Contributor
  • ***
  • Posts: 16284
  • Country: za
Re: Circuit with op amp lm339
« Reply #34 on: December 29, 2015, 07:23:30 am »
PNP transistors source a current to ground, NPN transistors sink a current to ground. Input of comparator internally uses PNP transistors in the first differential pair.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Circuit with op amp lm339
« Reply #35 on: December 29, 2015, 10:27:46 am »
So if I understand correctly, the input bias current runs from non-inverting and inverting input out. So away from the inputs, not in  the comparator.
Yes, it's because, in order to switch on a PNP transistor, a current needs to flow out of the base.

In op-amps/comparators with an NPN stage, such as the uA741 and NE5532, the bias currents will flow into the inputs.

741 schematic

http://www.sentex.ca/~mec1995/gadgets/741/741.html

Note that this isn't always the case. In some op-amps, such as the OP07 and OP37, an NPN input stage is used and bias compensation circuitry is added to try to reduce the bias current to zero but it isn't perfect so the inputs may either source or sink a tiny current.
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #36 on: December 29, 2015, 05:03:19 pm »
And then of course there are op-amps that use FET input stages, like the TL08x series ....

 
The easiest person to fool is yourself. -- Richard Feynman
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Circuit with op amp lm339
« Reply #37 on: December 29, 2015, 08:54:25 pm »
And then of course there are op-amps that use FET input stages, like the TL08x series ....
Which have  tiny bias current, until the input voltages is taken too near the negative rail, then the gates on the input transistors become forward biased, phase reversal occurs and a the bias current shoots up.
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #38 on: December 29, 2015, 10:48:11 pm »
OK... so I went out to my local supplier and bought an LM339. For a dollar ... what a ripoff, could have ordered 10 for $3.50, free shipping from Colorado, but I didn't want to wait 3 or 4 days for them to get here.    :rant:

I breadboarded Hero999's version and it works fine ... but it does have a tendency to oscillate, which keeps the LED "on" (really, it's flashing on and off so fast it looks continuously on.) I cured this self-oscillation by putting 0.1 uF ceramic caps from pins 6 and 7 to Ground. Now the LED stays nicely off until I move a magnet past the coil.

The circuit is more sensitive than I expected (using the same ~50 ohm miniature relay coil) but nowhere nearly as sensitive as the TL082 version that I posted and demonstrated in the video above.

Can you attach a schematic of this final circuit that you build. How are capacitors helping with oscillation problem?

Thank you.
 

Offline Seekonk

  • Super Contributor
  • ***
  • Posts: 1938
  • Country: us
Re: Circuit with op amp lm339
« Reply #39 on: December 29, 2015, 11:14:35 pm »
YOUR RESULTS MAY VARY

Operation of this circuit are based solely on the operation of a comparator.  The trip point of the comparator is totally uncontrolled due to variations in input current and offset voltage.  No effort has been made to adjust for variations from chip to chip.  Build five and you could easily get five different results.  I haven't seen anything which constituted a design.
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #40 on: December 30, 2015, 12:20:13 am »
OK... so I went out to my local supplier and bought an LM339. For a dollar ... what a ripoff, could have ordered 10 for $3.50, free shipping from Colorado, but I didn't want to wait 3 or 4 days for them to get here.    :rant:

I breadboarded Hero999's version and it works fine ... but it does have a tendency to oscillate, which keeps the LED "on" (really, it's flashing on and off so fast it looks continuously on.) I cured this self-oscillation by putting 0.1 uF ceramic caps from pins 6 and 7 to Ground. Now the LED stays nicely off until I move a magnet past the coil.

The circuit is more sensitive than I expected (using the same ~50 ohm miniature relay coil) but nowhere nearly as sensitive as the TL082 version that I posted and demonstrated in the video above.

Can you attach a schematic of this final circuit that you build. How are capacitors helping with oscillation problem?

Thank you.
Which "final circuit"? The LM339 and LM393 versions are Hero999's circuit shown in Reply #13 which is a modification of the original circuit you linked in the original post. I added 100nF capacitors from Pins 6 and 7 to ground, which stopped the oscillations for me.  "MY" extremely sensitive version using the TL082 is shown at the end of the demonstration video I posted, and on the previous page (Reply # 20).
The capacitors in the 339/393 versions work to kill the oscillations by bypassing AC noise/oscillation to ground so it doesn't affect the inputs. In my TL082 version the 200 nF capacitor is feeding back oscillations from the output to the inverting input in a negative feedback loop which tends to cancel them out. I think.


@Seekonk:  There may not be "anything which constitutes a design"... but I've built, and demonstrated, examples that work quite well nevertheless. I also determined the likely reason the OP's LED was staying on: the circuit was oscillating. I did this by applying my _practical knowledge_ and using an oscilloscope to confirm my educated guess, and I also applied this knowledge to fix that problem.  Designs are nice, but they are only designs, until someone puts them into practice and shakes out the bugs.
« Last Edit: December 30, 2015, 12:23:44 am by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #41 on: December 30, 2015, 11:17:54 am »
The final circuit with LM339.

So, the capacitors help reduce  AC oscillations. Can you describe more detailed?
 

Offline Seekonk

  • Super Contributor
  • ***
  • Posts: 1938
  • Country: us
Re: Circuit with op amp lm339
« Reply #42 on: December 30, 2015, 02:24:33 pm »
The following schematic is one of many possible solutions.  It reduces some of the problems
of input offset and bias current variations between chips.  The first stage provides a small
gain for AC signals and no gain for the offset voltage.  This reduces the effect of offset
uncertainty.  Raising the input voltage to half of supply reduces the chance of IV damage
due to spikes and solves the problem of op amps that inputs are not rail to rail.

The second stage has two comparators and detects positive and negative signals.  Adjusting
the 1K pot changes the trip plus minus points from about  7 to 50 mv. High frequency roll off
can be achieved by placing a small cap across RG.  A pair of diodes can be used to OR the
outputs if an op amp is used instead of a 339.  Inputs are not designated.  If it doesn't
jump out right away it is time to view one of Dave's op amp videos.  You should learn something
by building.
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #43 on: December 30, 2015, 10:48:07 pm »
@alsetalokin4017

Can you attach the latest schematic of lm339 circuit with capacitors. I would like to know how does capacitors reduce AC oscillations.
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #44 on: December 31, 2015, 05:40:03 am »
@Seekonk:

Can't you add a bit more complexity so that all 4 comparators in the 339 are used for something?    ::)



@nForce:

Here you go.
The easiest person to fool is yourself. -- Richard Feynman
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #45 on: December 31, 2015, 11:55:47 am »
@alsetalokin4017

Why did you choose 1n4148 diode? Isn't this diode for high power electronics? 1 A of a current.

Can I replace that with some other diode for smaller current?
 

Offline Audioguru

  • Super Contributor
  • ***
  • Posts: 1507
  • Country: ca
Re: Circuit with op amp lm339
« Reply #46 on: December 31, 2015, 03:03:21 pm »
Why did you choose 1n4148 diode? Isn't this diode for high power electronics? 1 A of a current.

Can I replace that with some other diode for smaller current?
You should read the datasheet for a 1N4148 low current silicon diode:
1) Its maximum continuous DC current is 300mA.
2) Its max peak current for 1 second is 1A.
3) Its max peak surge current for 1 micro-second is 4A.
5) Its datasheet shows a graph of its typical forward voltage at currents as low as 1uA.
6) its reverse leakage current is very low. 
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #47 on: December 31, 2015, 05:54:52 pm »
Oh, sorry my local supplier has a wrong picture. It's a small signal diode.

@alsetalokin4017, Hero999

Which program are you using for modifying and adding components on the schematics? These modified schematics look original.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Circuit with op amp lm339
« Reply #48 on: December 31, 2015, 07:41:38 pm »
I just use MS Paint and cut and paste the original symbols.
 

Offline Seekonk

  • Super Contributor
  • ***
  • Posts: 1938
  • Country: us
Re: Circuit with op amp lm339
« Reply #49 on: December 31, 2015, 09:18:20 pm »
I like that look, like it is copied out of an old manual.
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #50 on: December 31, 2015, 11:28:07 pm »
I just use MS Paint and cut and paste the original symbols.

Ditto, but I use mtPaint on Linux. Same difference.

The 1n4148 or 1n914 type diode is very cheap, and is very common in small signal applications where you don't need the very low Vf of a Schottky diode. I get them for 15 cents each, and that's pretty expensive. If you want to wait for delivery, you can get them for a penny apiece in lots of 100 from China. Free shipping too.

But you could probably use many other diodes in this application.
« Last Edit: December 31, 2015, 11:36:15 pm by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #51 on: January 04, 2016, 05:36:52 pm »
Ok, now I am confused.

I have made the @Hero999 version of the "magnetic field detector". (I don't need smoothing capacitors).

Now the LED is always on (like before), but when I get closer with the magnet, the LED turns off. Ok then.

But here is another thing, when I don't move the magnet (so it get's stuck on the coil)  the magnet is present, but not moving the LED is off.

How is that? I thought it would be a sensor for sensing CHANGE in a magnetic field. Now it works for just the presence of a magnetic field.


Can someone please explain to me how does this work?
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #52 on: January 04, 2016, 06:17:48 pm »
OK, now it works for changing the magnetic field. But still is off when the magnet is stuck on the coil.

And the LED is always on, but the brightness is much dimmer as it would be if I just connect to the positive. Why is that? Because there is always a small current? Because the comparator is not perfect?
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #53 on: January 04, 2016, 08:19:54 pm »
From your description it sounds to me like your circuit is still oscillating somewhat. Look at my modification of Hero999's modification of your schematic and put the capacitors in. If it still oscillates try increasing the value of the capacitors from 100 nF to 200 nF. See the quote from the Data Sheet below.

The circuit does not work for the _presence_ of a magnetic field. The mere presence of a constant magnetic field does not induce any voltage in a coil. The field must be _changing_ for a voltage to be induced. See Faraday's Law of Induction. The circuit responds to induced voltage in the coil, so if the field is not changing there is nothing to respond to. If the LED is on fully or dimly, then there is either enough changing magnetic field to induce voltage in the coil, or the circuit is oscillating, or both. When the magnet is stuck to the coil, it is possible that this changes the tendency of the circuit to oscillate, so the LED goes out.

One solution to oscillation is to add capacitors. You should have a local decoupling capacitor of 100 nF or so as near as possible to the chip, across the chip's Vcc and Vss (supply and ground) pins 3 and 12, and also have capacitors from the input pins 6 and 7 to ground. (See the quote from the Data Sheet below.)
Wiring should be direct and short and your breadboard should be in good condition.

Also, if you are still using the LM339 quad comparator, the 3 unused comparators in the chip can cause oscillations if they are left floating (no input or output). The Data Sheet for the TI LM339 says
Quote
The LM139 series are high gain, wide bandwidth devices which, like most comparators, can easily oscillate if the
output lead is inadvertently allowed to capacitively couple to the inputs via stray capacitance. This shows up only
during the output voltage transition intervals as the comparator changes states. Power supply bypassing is not
required to solve this problem. Standard PC board layout is helpful as it reduces stray input-output coupling.
Reducing this input resistors to < 10 k? reduces the feedback signal levels and finally, adding even a small
amount (1 to 10 mV) of positive feedback (hysteresis) causes such a rapid transition that oscillations due to stray
feedback are not possible. Simply socketing the IC and attaching resistors to the pins will cause input-output
oscillations during the small transition intervals unless hysteresis is used. If the input signal is a pulse waveform,
with relatively fast rise and fall times, hysteresis is not required.

All pins of any unused comparators should be tied to the negative supply.


If you have an oscilloscope you should be able to see if oscillations are keeping your LED glowing.


ETA: I just tested the circuit with LM339. It oscillated, keeping the LED on as you describe.  Without using any capacitors, simply tying all remaining pins of the 3 unused comparators (2, 4, 5, 8, 9, 10, 11, 13, 14) to Ground killed all my oscillations and now the circuit works as you probably expect it to.
« Last Edit: January 04, 2016, 08:52:03 pm by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #54 on: January 05, 2016, 06:15:40 pm »
Thank you.

I have one question, can I make the same circuit with an op amp let's say lm741? Instead of using a comparator.

Because the original author of the circuit choosed the comparator.
 

Offline Seekonk

  • Super Contributor
  • ***
  • Posts: 1938
  • Country: us
Re: Circuit with op amp lm339
« Reply #55 on: January 05, 2016, 06:25:27 pm »
Yes but likely the inputs must be raised above ground.  Use one resistor to common aqnd another to power as I indicated in a previous example.
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #56 on: January 05, 2016, 06:55:32 pm »
Is there any particular reason why the author choosed the comparator? Do you maybe know?
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Circuit with op amp lm339
« Reply #57 on: January 05, 2016, 07:15:15 pm »
Thank you.

I have one question, can I make the same circuit with an op amp let's say lm741? Instead of using a comparator.

Because the original author of the circuit choosed the comparator.

Didn't you see my version with TL082? And the video demonstration I did of it? It is a lot more sensitive than the comparator version.
The easiest person to fool is yourself. -- Richard Feynman
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #58 on: January 05, 2016, 08:00:15 pm »
oh sorry, I thought it was a comparator.

So op amps can be used as a comparator or amplifier but, it isn't true the other way around.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Circuit with op amp lm339
« Reply #59 on: January 08, 2016, 08:52:53 pm »
The circuit I posted was designed for the LM339 which has PNP input transistors which sources bias current. The LM741 has NPN input transistors so sinks bias current. The inputs on the LM741 also do not work down to the negative rail.

oh sorry, I thought it was a comparator.

So op amps can be used as a comparator or amplifier but, it isn't true the other way around.
No quite. Generally op-amps shouldn't be used as comparators. Some can behave unpredictably when the difference between their inputs exceeds a certain threshold or the output saturates.

Using an op-amp as a comparator is a bodge and should only be done caution and when there's a spare op-amp in a package to save space and cost. If you have a choice, don't do it!

It's also not true that comparators can't be used as op-amps. In reality, many comparator ICs (not all though) can be used as op-amps but care needs to be taken to prevent oscillation and filter out any such oscillation from the output. The LM339 even has an example of one of the comparators being used as an op-amp integrator on the datasheet.

http://www.ti.com/lit/ds/symlink/lm339-n.pdf

The comparators which should not and cannot be used as op-amps are those with built-in hysteresis (these will oscillate with no chance of becoming stable) and the ones with a CMOS output which will draw excessive current when both the transistors in the output stage are turned on.
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #60 on: January 11, 2016, 08:48:22 pm »
@Hero999

When you calculated the resistor value for increasing voltage on the pin of the comparator, you have used Ohm's law.

But how can I imagine with intuition, why the voltage has been increased. Does the electrons slow down and start accumulating at the pin. So that's why voltage has been increased?
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Circuit with op amp lm339
« Reply #61 on: January 11, 2016, 11:15:41 pm »
The electric current flows out of the input pin (conventional flow) through the 470k resistor which causes a voltage to be developed across it.
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #62 on: January 12, 2016, 09:57:00 am »
Yes, i know. But what happens from electrons perspective? They slow down, and start bumping each other? So that the voltage increases.

Here it's one resistor and the voltages increases, if we use two resistors in series it's a voltage divider. In this case it decreases.
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #63 on: January 13, 2016, 10:56:35 am »
So no one knows, what happens with electrons in a wire?
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
 

Offline nForceTopic starter

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: ee
Re: Circuit with op amp lm339
« Reply #65 on: January 13, 2016, 04:40:34 pm »
So, my explaination is correct. Electrons slow down, and because of that we have an increase of voltage.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf