# Need output voltages of 0V or 5V based on analog range

I need to produce an output voltage of 0 volt for inputs < 2.24V or 5 volt for inputs above > 2.70 V.

(For instance, 1.50 V input should produce 0 V output, while 3.75 V input should produce 5 V output.)

Is there any device or electronic component that can do this?

-
@Kortuk: You translated gibberish into english, but unfortunately removed the minimum low and maximum high thresholds the OP originally mentioned. As the question stands now, hystersis would not meet the spec. –  Olin Lathrop Aug 2 '11 at 16:00
@Olin - Don't you mean maximum low and minimum high? –  stevenvh Aug 2 '11 at 16:02
@Steven: Oops, yes. In any case, I fixed it by putting the original min/max levels back into the question. –  Olin Lathrop Aug 2 '11 at 16:04
@OlinLathrop, he gave example values, they looked spaced around 2.5V. I took a shot at what the OP needs but we need feedback almost as much as a good opamp. –  Kortuk Aug 2 '11 at 20:15
@Chris: Sorry, I disagree. The original question was very poorly worded in broken english and also showed that the problem hadn't been thought thru. For example, it listed several voltages to result in a low output, although only the highest mattered of course. I was sortof considering voting to close on account of "it is difficult to tell what is being asked here", but took a stab at trying to answer it anyway. Apparently I guessed right. –  Olin Lathrop Aug 2 '11 at 22:55
show 1 more comment

A comparator will do this. Set the power supply to 5V, and connect the inverting input to 2.5V. The variable voltage goes to the non-inverting input. The output will be high if the non-inverting input is higher than the inverting, and low otherwise.

The TLV7211 (just a random one of many) is a comparator which can work at 5V, and has a push-pull output, which means that it can force the output to 0V or 5V (the comparator's supply voltage). Note that there are many comparators which have an open collector output instead, they need a pull-up resistor to get the 5V.
Also note that the 0V and 5V outputs are not always met. You need a RRIO (Rail-to-Rail I/O) device, and even then the output may be a few tens of millivolts short of the theoretical value.

edit: Comparator tutorial

An analog comparator is a device with 2 inputs, +, called the non-inverting, and -, called the inverting, and one output. It continuously compares the input voltages on the + and - inputs. If the + input has a higher voltage the output will go to the positive power supply voltage (in our case +5V). If the voltage on the - input is higher the output will go to the negative power supply voltage (in out case 0V).
So you put the - input to 2.5V by means of a resistor divider.
If the + input is 3V it's higher than the - input and the output will go to +5V. If the + input is 2V it's lower than the - input and the output will go to 0V. This should be easy to remember: the input with the highest voltage wins, and the output goes to that level. So if the + input is the highest, the output goes to the + power supply level.

Hysteresis (a bit more complex)
Olin mentions hysteresis, and it may be important, but it's a bit more complicated. You probably won't need it if the input voltage will never be around the threshold voltage (the voltage where it switches from + to - and vice versa). If the input voltage can be close to the 2.5V reference it may cause unwanted effects. Noise on the input voltage may cause it to go above and below the 2.5V all the time, and therefore cause the output to switch fast between 0V and 5V.

Engineers have invented hysteresis to prevent this. It means adding a small portion of the output to the input, so that the voltage comparison will be different depending on the output level too. Instead of a single threshold at 2.5V we'll have two threshold levels, for instance 2.4V and 2.6V. If your input starts from 0V and slowly goes up, the output will toggle when the upper threshold of 2.6V is reached. But when going down again the other threshold is valid, and the voltage has to go below 2.4V to toggle again.

This means that continuous toggling of the output won't happen anymore, unless your noise will be larger than the 200mV hysteresis (very unlikely).

Adding Extra Hysteresis to Comparators (Maxim Application Note)

-
thank you so much for answering....i am from programming side i don't know anything about Comparator could you please elaborate what is comparator is?? –  Aryan SuryaWansi Aug 2 '11 at 14:09
@Aryan - I've tried to explain the comparator (added to my answer), and also hysteresis. Hysteresis isn't easy to understand first-off, and you might not need it, so try to get a hold of the comparator function first. –  stevenvh Aug 2 '11 at 15:47

Your question is unclear due to being poorly worded, so I'll define what I'm answering.

You have a input signal that can vary from 0V to 4.5V, and you want a 0 or 5V logic signal out depending on the voltage of the input signal. For inputs of 2.24V or below, you want logic low output, and for inputs of 2.70V or higher you want logic high output.

This is easy, and is called a "comparator". There is actually little difference between a comparator and a opamp. Comparators tend to have open collector/drain outputs more often, but that is not inherent to being a comparator.

In your case, you can use 2.5V as the threshold. So put 2.5V into the negative input and your external signal into the positive input. The result will be high when above 2.5V and low below. This is all you need if you know for sure your input signal won't spend much time near the 2.5V switching threshold.

If the input signal might stay for a while near 2.5V, then you want to add something called "hysteresis". This is a little positive feedback such that the threshold level changes depending on what state the output is in. For example, when the output is low, the input must be above 2.6V to make the output go high. When the output is high, the input must go below 2.4V for the output to go low. Now the input can change slowly thru the transition region but you still get a single clear digital edge out. In this example, the input can have up to 200mV peak-peak noise on it and still guarantee to cause only a single output edge as it transitions from high to low.

Here is such a circuit with a switching threshold of 2.5V and about 100mV hysteresis. It should do what you want if I understand the question correctly.

## Circuit Description:

R3 and R4 divide the 5V supply to make a 2.5V reference. C1 adds some filtering so that noise on the 5V supply won't get onto the 2.5V reference. This 2.5V result is fed into the negative input of the comparator (actually a opamp used in comparator role in this case). Since this value is fixed, the output will go high when the positive input is above 2.5V and low when below 2.5V.

C2 is the power supply decoupling capacitor for the opamp. It should be there, but can be ignored for the purpose of understanding how the comparator is used and how the hysteresis works.

Before jumping into hystersis, consider how the circuit would work if R2 weren't present. Since the opamp inputs are very high impedance, R1 basically does nothing in that case. The input voltage will be presented directly to the positive opamp input. So if the input is above 2.5V, the output will go high. If the input is below 2.5V, the output will go low. This is a straight forward comparator function.

Now consider the effect of adding R2. It adds a little bit of the 0 or 5 volt output to the input. You can think of R2 and R1 forming a voltage divider so that changes of the output show up attenuated at the positive input. The voltage divider ratio is R1 / (R1 + R2) = 0.021. The output always changes in 5V steps, so those steps will be 5V * .021 = 104mV at the opamp positive input. That means the input signal as the opamp sees it will have about 50mV added to it when the output is high, and 50mV subtracted from it when the output is low. This 100mV difference is the size of the hystersis band.

-
My turn - very nicely done :-). +1 –  Russell McMahon Aug 2 '11 at 14:35
@Olin or anybody else: could you explain how that circuit achieves the hysteresis quality? –  NickHalden Aug 2 '11 at 15:01
@JGord: Circuit description added. –  Olin Lathrop Aug 2 '11 at 15:36
@Olin Thanks, I'll work through your last paragraph after work... –  NickHalden Aug 2 '11 at 19:27