OP amp as comparator.

Thread Starter

engrokstate

Joined Jul 1, 2018
9
I simulated this circuit in Tina and it seems to be fine but I was wanting to ask if there is anything fundamentally wrong with it. The output is doing exactly what I want it to do but if there is a simpler or better approach I would appreciate the feedback. I tried to model it with a single supply, +24 VDC would be ideal, but I couldn't get the off state was a little over 1V. I would like to do this with the minimum number of components.
1599514616306.png
 

AlbertHall

Joined Jun 4, 2014
10,417
As you have no hysteresis, in the real world and with a slowly changing input you will get multiple transistions on the output at each state change. This may or may not matter depending on the application. It would be a problem if feeding a counter as the extra edges will give multiple counts for each transistion.
 

Thread Starter

engrokstate

Joined Jul 1, 2018
9
An opamp makes for a slow comparator and it's a shame to use an LM318 as one.

An LM393 would be better suited. It's input range includes ground while operating from a single supply.
I will look into that. The signal I am measuring is always around 550 hz and will never get above 1khz.
 

Thread Starter

engrokstate

Joined Jul 1, 2018
9
As you have no hysteresis, in the real world and with a slowly changing input you will get multiple transistions on the output at each state change. This may or may not matter depending on the application. It would be a problem if feeding a counter as the extra edges will give multiple counts for each transistion.
As I am going into a counter jitter would be a problem if it lasted longer than 2usec. Suggestions for hysteresis?
 

Papabravo

Joined Feb 24, 2006
14,459
A comparator is essentially an analog input device with a digital output. Back at the dawn of time, a set of standard logic levels was a pipe dream, and the analog folks solved that problem by making the output open collector (drain). Having an analog output on a comparator has some major disadvantages, especially when using legacy devices such as you are. I don't know what the counters input requirements are but I'll bet it would be happier with signal that was more "digital" and less "analog". I don't know that for sure, I'm just guessing.

BTW - jitter is where the transitions are moving back and forth in TIME. What you have is multiple up and down excursions near the transition point. This causes rail to rail jumps in the output. You do not want that. You can add hysteresis to any opamp or comparator with feedback. Here is an online design tool you may find helpful. I like these guys, They make good online STUFF.

http://sim.okawa-denshi.jp/en/compkeisan.htm
 

Thread Starter

engrokstate

Joined Jul 1, 2018
9
A comparator is essentially an analog input device with a digital output. Back at the dawn of time, a set of standard logic levels was a pipe dream, and the analog folks solved that problem by making the output open collector (drain). Having an analog output on a comparator has some major disadvantages, especially when using legacy devices such as you are. I don't know what the counters input requirements are but I'll bet it would be happier with signal that was more "digital" and less "analog". I don't know that for sure, I'm just guessing.

BTW - jitter is where the transitions are moving back and forth in TIME. What you have is multiple up and down excursions near the transition point. This causes rail to rail jumps in the output. You do not want that. You can add hysteresis to any opamp or comparator with feedback. Here is an online design tool you may find helpful. I like these guys, They make good online STUFF.

http://sim.okawa-denshi.jp/en/compkeisan.htm
You are correct, the high speed input is designed for encoders and the like. It would be better if I drove an opto-coupler or something more "digital". It accepts up to 24V but turns on around 4 and off around 2. Would the comparator mentioned above be less susceptible to extraneous transitions?
 

Thread Starter

engrokstate

Joined Jul 1, 2018
9
You are correct, the high speed input is designed for encoders and the like. It would be better if I drove an opto-coupler or something more "digital". It accepts up to 24V but turns on around 4 and off around 2. Would the comparator mentioned above be less susceptible to extraneous transitions?
 

Thread Starter

engrokstate

Joined Jul 1, 2018
9
A comparator is essentially an analog input device with a digital output. Back at the dawn of time, a set of standard logic levels was a pipe dream, and the analog folks solved that problem by making the output open collector (drain). Having an analog output on a comparator has some major disadvantages, especially when using legacy devices such as you are. I don't know what the counters input requirements are but I'll bet it would be happier with signal that was more "digital" and less "analog". I don't know that for sure, I'm just guessing.

BTW - jitter is where the transitions are moving back and forth in TIME. What you have is multiple up and down excursions near the transition point. This causes rail to rail jumps in the output. You do not want that. You can add hysteresis to any opamp or comparator with feedback. Here is an online design tool you may find helpful. I like these guys, They make good online STUFF.

http://sim.okawa-denshi.jp/en/compkeisan.htm

If the LED were an opto isolator.
1599548029527.png
 

Papabravo

Joined Feb 24, 2006
14,459
The diode in an opto-isolator is more of a digital device than an analog device. It has two meaningful states: current and no current. The amount of current is completely beside the point.
 

Papabravo

Joined Feb 24, 2006
14,459
You are correct, the high speed input is designed for encoders and the like. It would be better if I drove an opto-coupler or something more "digital". It accepts up to 24V but turns on around 4 and off around 2. Would the comparator mentioned above be less susceptible to extraneous transitions?
Yes, especially if you implement some hysteresis, which we can help you specify.
If you are running the comparator from +5VDC, the midpoint is 2.5VDC. As a first experiment I would try a lower theshehold point (LTP) of 2.4VDC and an upper threshold point (UTP) of 2.6VDC. If that works for you great. If you need more you add 50mVDC to the UTP and subtract 50mVDC from the LTP.

Just to be clear, a rising edge will cause the comparator to change states at the UTP, but a falling edge must drop to the LTP to return the comparator to the original state. Hysteresis just means you have different thresholds depending on where the input signal started and ended up.

One more thing. Anything you do open loop in the analog world is going to have "problems". Everything you do that involves feedback, solves many of those problems.
 

DarthVolta

Joined Jan 27, 2015
509
What's the difference between an LM393 and an LM358 ? I've been digging deeper in H-parameter's lately, and I've not applied all that stuff to op-amp's yet. I'm just trying it on diff-pairs again.

And latley when I wanted to find out something or other about LM393 vs regular op-amp, I never found the anwser or the even the question, on google. And I guess looking at the LM393 datasheet, I can't see the finer details yet, of what I was looking for. On the basic side, isn't it just an op-amp, with a tighter linear region, that will swing it from Vlo to Vhi ?
 

Papabravo

Joined Feb 24, 2006
14,459
Here is the deal
  • LM358 is an opamp, with differential inputs and you can make a unity gain inverter with it because it has an analog output, that probably doesn't make it to either supply rail because it is such an ancient part. It is characterized for single supply operation.
  • LM339, LM393 are identical internally. They the quad and dual packages for that particular comparator circuit. Like an opamp they have differential inputs and high open loop gain, BUT they have an open collector output which REQUIRES an external pullup resistor to whatever Vcc value is used by the chip looking at the output of the comparator. In the dawn of time there was no such thing as a "standard" ligivc level. This was the compromise that allowed it to work with literally any logic family. They are not normally used with negative power supplies because very few digital logic families use negative supplies anymore.
 

Thread Starter

engrokstate

Joined Jul 1, 2018
9
The diode in an opto-isolator is more of a digital device than an analog device. It has two meaningful states: current and no current. The amount of current is completely beside the point.
I understand what a diode is. I was modifying the design based on your previous comment "I don't know what the counters input requirements are but I'll bet it would be happier with signal that was more "digital" and less "analog". Tina doesn't have an opto-isolator so I modeled it with a diode. I used an LTV-847S I had laying around. I have built this updated circuit and tested it and it works great and is exactly what I need. I tried it without feedback and I saw oscillations at the transition point. After adding the feedback resistors and some hysteresis all is better. Thanks all for the feedback.
1599674235362.png
 

AnalogKid

Joined Aug 1, 2013
8,608
What is the part number of the counter the circuit is driving? If it is a logic device (IC) rather than a piece of test equipment, what is its power supply voltage? Depending on the answers, you might be able to eliminate VS2 and LED1. Also, there is no reason for the feedback resistors to be so low. Consider R2 = 10K and R3 = 47 K.

ak
 

Ian0

Joined Aug 7, 2020
521
The diode in an opto-isolator is more of a digital device than an analog device. It has two meaningful states: current and no current. The amount of current is completely beside the point.
Really? So how can optoisolators be used as feedback in switched mode supplies? The optoisolator is most certainly analogue. Over a large range output current is proportional to input current, and the output can be at voltages between 0V and Vcc simply by varying the LED current, unless you use a schmitt trigger isolator such as IS609/H11L1. But if there's nothing to isolate, just use a comparator with hysteresis. There are also plenty of comparators out there with push-pull outputs: Microchip has a good range:
https://www.microchip.com/design-centers/amplifiers-linear/comparators
If the signal is 1kHz, don't choose a comparator that is really fast, it will give you worse jitter. It may even give you multiple edges which you can't see on your scope, but your counter can see!

If you do use an op-amp as a comparator, then the slow slew-rate can prevent jitter. If the logic gate has schmitt trigger inputs (many do, but it's not universal) then you have no need for hysteresis. However, if there is no schmitt trigger on the input of the logic gate then it can cause jitter.
 

Papabravo

Joined Feb 24, 2006
14,459
An opto-isolator is characterized by a parameter called CTR (Current Transfer Ratio). On a typical device this parameter is neither very precise or well controlled. To use it in an analog context would require some means of calibration. Furthermore this parameter degrades (gets worse) over time, so the calibration would need to be regular. You tell me how it can be used in a switched mode power supply.
 

AlbertHall

Joined Jun 4, 2014
10,417
You tell me how it can be used in a switched mode power supply.
They are very commonly used as feedback from the secondary side to the primary side. Again commonly, a TL431 monitors the output voltage and drives the LED in an opto-isolator thus any variation in CTR between devices or over time is compensated for by the TL431. This feedback is an analog signal.
 
Top