How can i add hysteresis in a comparator when input voltage varies ?

I want to use a comparator like LM339, to check the current of a circuit.
When it consumes more than 1 amper the output of the comparator will trigger a pin change interrupt.
The problem i am facing is that i don't know the way to add hysteresis ( i think that is the word ) to the circuit because the input voltage varies between +10V to + 24V.

In the schematic R5 = 0.1R When it passes 1A it will give me 0.1V. The comparator will trigger even when the consumption will be a little more than 0A.
How can i make it to trigger only when it passes 1A?
Keep in mind that the input voltage varies.

Any ideas?

Usually a high value resistor from output back to non inverting input (+) will provide some hysteresis, start with 10M and work down, you may have to reduce R1 & R2 (keep them equal though).

It is not giving me the same results when the input voltage changes.

To add hysteresis to any OP-AMP like circuit, add positive feedback in conjunction with an input resistance. What this accomplishes, is it moves the reference voltage on the non inverting pin slightly , in favor of the switched state. Look at this diagram (which I've attached, but I hope shows up because I can't see it in the preview :frowning: ). Considering the output must be approximately +Vcc or -Vcc, it becomes a simple matter to calculate the voltage at the non inverting input after a transition. Do this for both possible states, and you have the total hysteresis.

Unfortunately to make this work in your circuit, you'll have to make some changes. Attaching an OP AMP (or comparator) input directly to the same rail its powered from makes this kind of hysterisis impossible. Once the comparator flips its output to high, it is not possible for the resistors in the circuit I described to do their job (because nothing can force the non inverting reference input above VCC.

So one solutions is that if your circuit load can stand to lose a volt or two, you can add 2 or three diodes to everything using VCC, EXCEPT the LM339 itself. Then, once you connect the feedback resistor, the circuit will be free to "pull" the reference voltage at the non inverting pin both lower and higher than the reference point, at least up to a volt or so depending on how many diodes you add. And you can always use a trim pot for the feedback (R2 in my diagram) and fine tune the amount of hysteresis you want. Finally, remember to add a capacitor across the power inputs to your LM339, just to ensure that sudden transitions don't cause circuit instability.

hyst.jpg

Ignore the unhelpful suggestions here. Neither of them even come close to addressing the fact that you aren't even using the comparator correctly to begin with.

You need to connect the shunt to a current sense amplifier. Then you connect the amplifier output to one of the comparator inputs, and connect a reference voltage equivalent to 1A of output to the other comparator input. Adding hysteresis circuitry after that is easy.

Maybe have a look here to see if something on the page might work for you.

Hi,

I think what Jiggy-Ninja is saying is.... you are asking a lot from the comparator. I think will be unhappy with the result, especially if the currents are low and there is some noise on the 20V supply.

While there are more complex solutions, if this is a home project (which are less cost sensitive) you should consider a "..high side current sense amplifier..." Maxim makes some and I'm sure there are others.

These devices are designed to reject the noise on the high side line and amplify small voltages usually associated with a current sense resistor.

However if you want to try the hysteresis suggested above, you should at least reduce the 1 Meg series resistors. The comparator (+) input is connected to the supply so it is not sensitive to loading.

The (-) input resistor only needs to be say greater than 1000 x the shut resistor, so perhaps a 10k would be better. However they both should be the same.

Good luck

draw.

How fast do you need a response?

The LM339 responds in a few uS, but is no good as it's input common mode range does not include it's +ve supply. Hence your circuit cannot work.

There are ways.........

regards

Allan

Firstly it will be much easier if the shunt is low-side, then you can compare its output against
a voltage reference above ground since these comparators do work all the way to 0V and a little bit beyond.

If the voltage across the shunt is very small you should amplify it first with an opamp in differentialamplifier configuration before driving the comparator. The opamp will need to be a precision one with low offset voltage.

R5 ensures that the voltage across the inputs always has the +Ve input greater than the -Ve input, therefore the comparator can never change state no matter what current is flowing through R5.

Grumpy_Mike,

Of course your are correct.... Its amazing how someone can look at something and see something else.

Is it correct?
I think that is the only way to check the consumption, when the input voltage varies.

That way will work, if you don't mind the current shunt being on the low side. If any other part of your circuit needs common ground with the load, the voltage drop across the shunt might cause problems.