Comparator doesn't swing entirely to 5v and 0v?

Thread Starter

icydash

Joined Jan 14, 2009
148
Hey guys. I'm desigining a circuit that compares the output of an op amp stage to 300 mV DC. When the output of the op amp stage exceeds 300 mV (AC), the comparitor should output 5 V, and when it's below 300 mV the comparitor should output 0 V. For some reason my circuit is outputting 3.488 V and 91.808 mV though. Also, in Multisim, it seems like there's some AC voltage at the output too, which I don't understand / want? Thanks for your help!

The schematic can be found at:
http://tech-area.com/h/techarea/comparitor.bmp
 

SgtWookie

Joined Jul 17, 2007
22,230
The comparator's output is open-collector. When the output is in saturation, it won't get quite down to the negative rail, but with a light load (under 6mA) it'll get down under 100mV. When the output is turned off, the 1.5k resistor should pull the output to 5v, unless you have your simulated instruments set to a low impedance.

Tie pins 5&6 to pin 8 (5v). That should increase input slew rate from around 7v/uS to around 18v/uS.

Your 500mVRMS signal will swing to about +353/-353mV. When it dips below around -300mV, the comparator will enter phase inversion aka "latchup", and you'll notice the output start to rise. That's the AC you're seeing on your output. If you don't want to see that, keep your inputs between the rails (0v and 5v) by adding a 707mVDC offset voltage.
 

Thread Starter

icydash

Joined Jan 14, 2009
148
I made those changes and the new circuit is located at:
http://tech-area.com/h/techarea/comparitor2.bmp

I made all the changes you suggested and now it works great. I added a 1.8Vdc offset to the AC source and that seemed to help bring the output up to 5V. I had totally forgot that everything was in RMS not Peak-Peak, too, which made a lot of the problems occur. Also, with the AC +/- swing, adding the DC offset really helps...I hadn't thought about that. Now the output is ~91mV off and 5V on, which is pretty good. Also all the AC is gone at the output (it's like 9mV when on and pretty much 0 off).

What exactly is slew rate and why does increasing it help? I made the changes you suggested, I just wanted to understand it better. Thanks so much for your time!
 

eblc1388

Joined Nov 28, 2008
1,542
Also, with the AC +/- swing, adding the DC offset really helps...I hadn't thought about that.
It is easy in simulation just to "designate" a DC offset value to the input signal which is grounded.

In real life, how can you make that happens with a grounded source?

Have you thought about coupling your signal to the comparator using capacitor?
 

Thread Starter

icydash

Joined Jan 14, 2009
148
Thanks for the info on slew rates!

eblc: I actually had thought about that but thanks for bringing it up, because it brings me to another problem in my circuit. The comparitor stage is actually the second stage of the circuit, after an op amp stage. I connect the positive voltage of the op amp to +5v, and the minus to ground, and input a 2.5 Vdc offset (using a voltage divider) to the + terminal and my ac source to the minus terminal. I was hoping to use the DC offset i create from the resulting op amp stage output in the comparitor stage. For some reason though, my multisim crashes when I try to run my op amp stage with the 2.5 V voltage divider. Maybe you guys can help me figure this out? Am I doing something wrong? Also, the final stage of the circuit is a flip flop, which I'm pretty sure I've connected correctly and seems to simulate right. Note that the "out" of the comparitor stage would go to the CLK on the flip flop stage and the switch would be removed...that was just for simulation purposes.

All three stages can be found here:
http://tech-area.com/h/techarea/fullCircuit.bmp

The purpose of the circuit is: I will actually be using an ultrasonic receiver at the beginning of the circuit (the AC source). I want to make it so when i hit the circuit with ultrasonic (40kHz) signal, it turns on the circuit and keeps it on. Then later on, if I hit it again, it'll turn off the circuit. Sort of a remote control power switch. I already know from about 10 feet away I can get about 10mVp-p of power AC from the ultrasonic receiver so that's why I chose that number for the AC source.
 

Thread Starter

icydash

Joined Jan 14, 2009
148
Although now in thinking about using the 2.5Vdc offset from the op-amp stage for a while...Will that always be there regardless of if i have an AC signal or not and thus mess up the comparitor stage? if so, is there a better way to add in that offset to the comparitor stage then using the offset from the op amp stage?
 

SgtWookie

Joined Jul 17, 2007
22,230
Refer to your input opamp circuit.
On the noninverting input, you have a voltage divider circuit; it's output will be 2.5v.
However, on the inverting input, you have divided feedback; R1=5k and R2=300k.
The gain of the opamp will be: gain = (R2/R1) + 1 = 61
See this E-book chapter: http://www.allaboutcircuits.com/vol_3/chpt_8/5.html

You have 2.5v on the noninverting input, so 2.5 * 61 = 152.5v! This won't work very well at all.
 

Thread Starter

icydash

Joined Jan 14, 2009
148
Ok, as it turns out I should have made the stage that creates Vcc/2 a buffer stage as shown http://instruct1.cit.cornell.edu/courses/bionb440/datasheets/SingleSupply.pdf (on page 4) and then did the inverting amplification stage separately, as shown on page 6. I guess I tried to combine the two and that's no good? I don't entirely get the purpose of the buffering op-amp. If I do it in two separate stages (the buffer then the AC gain combining what's on pages 4 and 6) I should get the desired results of 60 gain on the AC riding on 2.5Vdc I think....right?

I suppose I could leave the circuit as i have it, too, and instead of putting like 2.5V on the noninverting input, only put like 40mV dc in so i'd get around 2.5 Vdc after the 61 gain.
 
Last edited:

KL7AJ

Joined Nov 4, 2008
2,229
I made those changes and the new circuit is located at:
http://tech-area.com/h/techarea/comparitor2.bmp

I made all the changes you suggested and now it works great. I added a 1.8Vdc offset to the AC source and that seemed to help bring the output up to 5V. I had totally forgot that everything was in RMS not Peak-Peak, too, which made a lot of the problems occur. Also, with the AC +/- swing, adding the DC offset really helps...I hadn't thought about that. Now the output is ~91mV off and 5V on, which is pretty good. Also all the AC is gone at the output (it's like 9mV when on and pretty much 0 off).

What exactly is slew rate and why does increasing it help? I made the changes you suggested, I just wanted to understand it better. Thanks so much for your time!

Send cash, not applause. :D
 

SgtWookie

Joined Jul 17, 2007
22,230
I suppose I could leave the circuit as i have it, too, and instead of putting like 2.5V on the noninverting input, only put like 40mV dc in so i'd get around 2.5 Vdc after the 61 gain.
There you go ;)

With a gain of 61, for (roughly) each 16.4mV of offset you introduce on the noninverting input will give a 1v increase in the output.

However, there is also the input offset voltage to consider. This is typically 3mV to 5mV, but it could be as high as 15mV; this is also multiplied by the gain. So, you'll need a pot in order to be able to compensate for the offset voltage.
 

Thread Starter

icydash

Joined Jan 14, 2009
148
input offset voltage? you mean on the - line of the op amp coming from the source? where is an offset coming from?

If you mean there will be some AC input offset from the ultrasonic receiver shown as an AC source here, can i just put like a 100nF capacitor between it and the first inverting resistor to block any dc?
 

SgtWookie

Joined Jul 17, 2007
22,230
input offset voltage? you mean on the - line of the op amp coming from the source? where is an offset coming from?
Input offset voltage is the equivalent voltage at the input of an operational amplifier. If an amplifier has a voltage gain of ten and an input offset voltage of 10 microvolts, a level of 100 microvolts will appear at the output with no input (input shorted to ground). Manufacturers try to design an op amp so the input offset voltage is as small as possible to minimize this error voltage at the output of the amplifier, especially for applications where small voltages are being amplified.

If you look at the datasheet for your TL082, you will see typical and maximum specifications for input offset voltage.

Virtually all opamps have some input offset voltage. Expensive precision opamps' input offsets may be as low as a few microvolts.
 

Thread Starter

icydash

Joined Jan 14, 2009
148
It's actually ok if that voltage is there, it just drives up the op amp circuits output by a little bit but that's still fine. The circuit seems to work perfectly as I want it now!

Here's the schematic:
http://tech-area.com/h/techarea/FinalCircuit.bmp

If i replace the piezo electric device with an AC source and switch like in the other schematic diagrams the whole thing simulates beautifully. At the output i plan to have a voltage regulator with built in on/off switch connected to the output of the JK flip flop, and that should be it! I should have an ultrasonically controlled power setup for the rest of my project. Kind of cool.

How does the circuit look to you guys? Can you spot any other errors?

Thanks so much for all the help!
 

SgtWookie

Joined Jul 17, 2007
22,230
That flip-flop is going to be toggling like mad - at an ultrasonic rate. You'll have a 50/50 chance whether the output will be high or low when your circuit stops receiving.

You need a way to ensure that the flip-flop is clocked once, and only once - no matter how long that ultrasonic signal is received.
 

Thread Starter

icydash

Joined Jan 14, 2009
148
I realized in the circuit i posted i can get rid of the 50kOhm resistor in the comparitor stage... I don't know why I had that there.

As for the toggling, I don't see why? In my simulation the flip flop doesn't toggle like mad, it does exactly what its supposed to do. When I close the switch and allow the AC source (40kHz) to sit for a while the flip flop doesn't toggle at all, it just stays in whatever state it was in. I think this is because the comparitor doesn't toggle at all, it just stays high as long as ultrasonic is there and then goes low when it's not...it doesn't seem to be toggling.

Maybe when there is no AC signal from the source there isn't enough gain from the op amp to bring it above the threshold on the comparitor, but when there is signal from the AC source the gain combined with the DC offset keeps it above the threshold level...

for whatever reason it seems to work right though lol
 

Thread Starter

icydash

Joined Jan 14, 2009
148
Yeah it appears that when there is no AC voltage going into the op amp circuit there is only ~65mV of DC and almost 0 V AC at the output of the op amp stage. When I then connect the AC voltage source it has 834mV AC and 3.2V DC at the output. So when there is no piezoelectric stimulation, the output of the op amp stage is below the threshold for the comparitor, and when there is stimulation, it stays above the comparitor threshold. So there is no toggling, it's either high when there is stimulation, or low when there isn't. Then the flip-flop locks it in that state.
 

Thread Starter

icydash

Joined Jan 14, 2009
148
I really wanted to thank everyone so much for their help by the way. You guys were great and I really understand why everything works the way it does now.

One last question haha: I was able to download the .MOD files for the actual circuit components from National Semiconductor I will be using in the real circuit design. I would like to use them in multisim (v10) just to make sure that my circuit still works as is expected. I have the files on the desktop but for the life of me can't figure out how to import them or add them to my library....any ideas?
 

SgtWookie

Joined Jul 17, 2007
22,230
That's really an entirely new topic.

I don't have Multisim, so I won't be of much help.

Start a new topic with a title like "Adding components to Multisim library?" in the General Electronics Chat forum.
 

Thread Starter

icydash

Joined Jan 14, 2009
148
Ok so I realized I may have made a mistake in one large aspect of my circuit design. When I was modeling the piezoelectric ultrasonic receiver in Multsim (they don't have a component for this), I just used an AC source and a switch for when the piezoelectric device was being stimulated and when it was not. Here is a diagram of what I mean:

http://tech-area.com/h/techarea/circuit4.bmp

What I've realized is I've never worked with a piezoelectric device before, but I'm assuming that with all the noise and frequencys flying around a typical room, there is never really 0 volts coming from it, as I modeled by opening the switch in the above circuit. If even the slightest voltage comes out from it (even 1uV), it will cause the op-amp stage of my circuit to amplify and toggle the whole circuit. Is there a way to remove voltages coming from the ultrasonic receiver less then like 10mA or something so this doesn't happen? Like maybe putting a transistor between the op amp and the comparitor stage and having the output of the piezoelectric device (ultrasonic receiver) connect to the gate? is 10mA enough current to turn on the gate of a transistor? Any ideas? Thanks guys.
 
Last edited:
Top