Adding hysteresis to a comparator - Page 1
Forum section: electronics / projects

author: microbug
author_rank: Frequent Contributor
timestamp: June 15, 2014, 10:05:55 am
content: I'm designing a PCB for my boombox project. One of its functions is to detect when the (3s lipo) battery voltage is low and to warn the user (and if it drops too low, cut off the power to the amp). You can see the attached schematic or find it onUpverter.I want to add hysteresis to the comparators, so that they trigger LOW at the same voltage as currently, but trigger HIGH a few hundred millivolts above the LOW voltage. My question is: what equation(s) can I use to calculate the values of R1and R2for hysteresis? I already have the resistors for the resistor dividers: will I have to change their values?I know I will need to add a pull-up resistor to the output of the top comparator, assume it will be 10k going to 5V.

author: dannyf
author_rank: Super Contributor
timestamp: June 15, 2014, 10:09:00 am
content: Quotethat's fairly textbook question. Or you are looking for something different?

author: microbug
author_rank: Frequent Contributor
timestamp: June 15, 2014, 10:12:49 am
content: That's pretty much it, but the textbook I have (practical electronics for inventors) wants me to calculate Vrefafter working out R1and R2. I don't want to change Vref!

author: PE1RKI
author_rank: Regular Contributor
timestamp: June 15, 2014, 10:24:21 am
content: you need 470k or 1meg from the output from the 393 to the minus input and a diode towards the minus.if the load then dissapears and the voltage goes back to 12 volt again, then just use flip flop with reset button.if i understand correctly, you want to turn it into a schmitt trigger

author: dannyf
author_rank: Super Contributor
timestamp: June 15, 2014, 10:25:47 am
content: I can see no way R1/R2 having meaningful impact on hysteresis here.Maybe you can post the work from your book?

author: microbug
author_rank: Frequent Contributor
timestamp: June 15, 2014, 10:28:13 am
content: Sorry; I should have clarified: R1being a currently non-existent resistor between the output of the voltage divider and the non inverting terminal, and R2also being a non-existent resistor between the non inverting terminal and Vout.Oops!EDIT: @PE1RKI Yes I do want to turn it into a schmitt trigger.

author: PE1RKI
author_rank: Regular Contributor
timestamp: June 15, 2014, 10:35:17 am
content: you can also use a regular opamp and then you dont need r1

author: PE1RKI
author_rank: Regular Contributor
timestamp: June 15, 2014, 10:37:58 am
content: you have the opamp inputs the wrong way around ?

author: microbug
author_rank: Frequent Contributor
timestamp: June 15, 2014, 10:39:46 am
content: Do I?It's active low, i.e., the LED turns on when the output of the comparator is LOW.

author: PE1RKI
author_rank: Regular Contributor
timestamp: June 15, 2014, 10:42:54 am
content: ah yes

author: microbug
author_rank: Frequent Contributor
timestamp: June 15, 2014, 10:49:23 am
content: OK, will this do the trick?[See attached]

author: PE1RKI
author_rank: Regular Contributor
timestamp: June 15, 2014, 10:53:10 am
content: invalid picture ?

author: microbug
author_rank: Frequent Contributor
timestamp: June 15, 2014, 10:54:56 am
content: Fixed - see attached.

author: dannyf
author_rank: Super Contributor
timestamp: June 15, 2014, 11:03:15 am
content: QuoteCompare your schematic vs. your book and see how they are different?You need positive feedback, not negative feedback, to establish hysteresis.

author: PE1RKI
author_rank: Regular Contributor
timestamp: June 15, 2014, 11:04:48 am
content: sorry it had to go to the plus input.and a pull up resistor to the 5v.and i think a diode in series with the feedback resistor so that it doesnt affect the turn on voltage point

author: microbug
author_rank: Frequent Contributor
timestamp: June 15, 2014, 11:06:57 am
content: I'll work on it.@PE1RKI, I no longer need a pull up resistor– the new schematic is using a push-pull op-amp.

author: microbug
author_rank: Frequent Contributor
timestamp: June 15, 2014, 11:11:31 am
content: Well, I switched the resistor to the non inverting terminal. I see what PE1KRI means about the diode, but won't that mess up the hysteresis?EDIT: attached schematic.

author: PE1RKI
author_rank: Regular Contributor
timestamp: June 15, 2014, 11:28:03 am
content: it will remain switching on at 9.9 volt but will go of again at a higher voltage.anode of the diode at the plus input.

author: microbug
author_rank: Frequent Contributor
timestamp: June 15, 2014, 11:40:12 am
content: OK then! Final schematic attached.Thank you to dannyf & PE1RKI!

author: dannyf
author_rank: Super Contributor
timestamp: June 15, 2014, 01:18:01 pm
content: The diodes are not ncessary.The math is really simple. Take the lower comarator for example. Its inverting pin sits at 5v*22k/(22k+68k). All you need is to figure out Vcc needed to cross that voltage on the non-inverting pin, assuming a known state for the comparator's output voltage (Vo).The following must be true:(Vcc - V+) / R8 + (Vo - V+) / R21 = V+ / R7, where V+ is the voltage on the non-inverting pin.Or V+ = (Vcc / R8 + Vo / R21) * (R8//R21//R7)ie. the cross-over point is (Vcc / R8 + Vo / R21) * (R8//R21//R7) = 5v * 22k / (22k + 68k).Two scenarios:1) Vcc from low to high, Vo = Vol (minimum output voltage).2) Vcc from high to low, Vo = Voh (maximum output voltage).The difference between Vol and Voh creates the hysteresis.

author: PE1RKI
author_rank: Regular Contributor
timestamp: June 15, 2014, 01:30:32 pm
content: i suggested the diode so that he doesnt have to recalculate the resistors.it is indeed better to do without diodes = less costs.

author: dannyf
author_rank: Super Contributor
timestamp: June 15, 2014, 01:45:47 pm
content: The diode definitely helps simplify the calculation.Once, the comparator's output goes high, the diode and the 1Meg resistor are out of the loop.However, if Vcc continues to increase to a point where the diode starts to conduct, what will happen at that point is probably device specific.

author: microbug
author_rank: Frequent Contributor
timestamp: June 15, 2014, 06:25:36 pm
content: @PE1RKI, recalculating the resistors probably would mean more cost for my setup though.@dannyf, I was aware that V+ was sitting at 1.222(2 recurring) volts, just not of what to do with that info. Anyway, thanks for helping me out!

author: PE1RKI
author_rank: Regular Contributor
timestamp: June 15, 2014, 08:00:08 pm
content: 1M might be way to high.the battery can go up in voltage to, if you remove the load, then you can get oscillation if you allow the amplifier to go on again.

author: dannyf
author_rank: Super Contributor
timestamp: June 15, 2014, 08:06:12 pm
content: QuoteThe difference between Voh and Vol is probably 4 - 5v, assuming 5v rail.The corresponding hysteresis is about 4v * 1/1M / (1/1M + 1/68K + 1/10K) = 35mv.So for 100mv hysteresis, use a 330K resistor instead.

author: microbug
author_rank: Frequent Contributor
timestamp: June 15, 2014, 08:07:12 pm
content: Thanks!

author: PE1RKI
author_rank: Regular Contributor
timestamp: June 15, 2014, 08:17:51 pm
content: dont forget the influence of the diode.if the current is very low, the voltage drop over the diode can be pretty high.if we guess 0.8 volt then the resistor must be 3 times lower then calculated.0.8 is 2/3 of the 1.22 volt reference.

author: dannyf
author_rank: Super Contributor
timestamp: June 15, 2014, 08:23:53 pm
content: QuoteAt this kind of current, the voltage drop over the diode will be pretty LOW.Otherwise, it would raise Vol by 0.7v, or reduce the difference (between Voh and Vol) by 0.7V.

author: PE1RKI
author_rank: Regular Contributor
timestamp: June 15, 2014, 08:39:17 pm
content: oops y other way around, low current low voltage drop.but still it will affect the feedback resistor a great deal.

author: dannyf
author_rank: Super Contributor
timestamp: June 15, 2014, 11:43:41 pm
content: QuoteI simulated the following. Without the diode, the output transitions at V2=9.54v; 9.55v with the diode.The current going through the diode is in na range.

author: PE1RKI
author_rank: Regular Contributor
timestamp: June 16, 2014, 06:46:04 am
content: d1 is not a perfect diode with 0 volt drop ?and what happens with 330k?

author: dannyf
author_rank: Super Contributor
timestamp: June 16, 2014, 10:20:57 am
content: 9.60v vs. 9.54v @ 330k.

author: microbug
author_rank: Frequent Contributor
timestamp: June 16, 2014, 09:19:47 pm
content: So I should drop the diode? I don't need it on the first (top) circuit anyway, only the one controlling the FET.

author: PE1RKI
author_rank: Regular Contributor
timestamp: June 17, 2014, 06:58:54 am
content: yes but it will change moment the led will turn off.also check for oscillation, if the window of the schmitt trigger is to small you can get oscillation.then you need to lower the resistor.

author: dannyf
author_rank: Super Contributor
timestamp: June 17, 2014, 08:17:48 pm
content: The diode makes the calculation a lot easier.If you are simply experimenting and don't need precise transition points, the diode isn't needed.