LM339 and trimpots. Threshold inaccurate. Normal? - Page 1
Forum section: electronics / beginners

author: jbs
author_rank: Contributor
timestamp: May 25, 2020, 10:07:33 pm
content: So I have this peculiar problem.When I hook up a LM339 comparator with two 10K trimpots (A & B), I find that the Output switch from HIGH/LOW doesn't happen at the threshold I set with trimpot A. R5 is the pullup resistor (4K7 Ohm).I understand why this happens (Thanks to Zero999's help).Here's a simplified schematic. Trimpot A is represented by resistors R1 & R2 (e.g. R1=10K-R2) and trimpot B is represented by resistors R3 & R4 (R4=10K-R3).Let's assume the comparator Output is HIGH, then R5 is in parallel with R3 and the two together with R4 are defining a voltage divider (R3//R5 at the top and R4 at the bottom).When I set a threshold voltage at the LM339 Positive input with trimpot A (R1 & R2), then I can solve for R3 in the equation given by the voltage divider (R3//R5 and R4).threshold voltage = 5 * R4 / (R4 + (R3*R5/(R3+R5))), where R4=10K-R3 and R5 =4K7.I guess what I find interesting is that once the switch in Output happens, the voltages across both trimpots don't match. I always thought, that it would suffice to check the voltages across both trimpots at the LM339 pins (pos. input and neg. input), and that they had to be the same.Hopefully I've made myself clear. Can someone please confirm if I got this right?Also, is there a way around this, e.g. I would like both trimpots to have the same voltages when the switch occurs. (reading the result directly at the pins).Thanks,Joël

author: gbaddeley
author_rank: Regular Contributor
timestamp: May 25, 2020, 10:16:40 pm
content: Why do you think R5 has any influence on the threshold??

author: RoGeorge
author_rank: Super Contributor
timestamp: May 25, 2020, 10:21:17 pm
content: R5 has nothing to do with R1,2,3,4, no matter if the output is high or low. Only R1,2 and R3,4 dividers are the ones who set the two voltages that will be compared by the 339.If V pin 1/339 > V pin 2/339, the output V pin 4/339 will be +5V.If V pin 1/339 < V pin 2/339, the output V pin 4/339 will be 0V.LTspice can help simulating the circuit and playing with the R1,2,3,4 values to study how it works.

author: jbs
author_rank: Contributor
timestamp: May 25, 2020, 10:38:55 pm
content: Quote from: RoGeorge on May 25, 2020, 10:21:17 pmThanks. Although, this is not what happened when I took the measurements. I'm not sure what I did wrong.When I measured the voltages at the pins, the positive input was higher than the negative input and yet, the output was staying LOW. Only when I had a delta of .33 V (with 3.3 source voltage) did the switch happen.It's late now, I will try tomorrow and write more. Thanks again for all your help.

author: jbs
author_rank: Contributor
timestamp: May 26, 2020, 12:39:32 pm
content: So I have tried again. I'm feeding 5V from an arduino to the circuit.I measure 2.5V at the Positive Input (Pin 10) and 2.503V at the Negative Input (Pin 9).The Output (Pin 16) reads HIGH, but it should read LOW, since 2.5<2.503Only at 2.508 is the switch happening, and the Ouput isn't a steady LOW but it's fluctuating, I guess because of noise. At 2.509 V it is steadily LOW.Is this behavior normal for a LM339 ? Meaning, is there always a delta?Edit: I measure the voltage with a Fluke 87V Multimeter, if that matters (can the instrument be to blame)?

author: RoGeorge
author_rank: Super Contributor
timestamp: May 26, 2020, 01:07:10 pm
content: Quote from: jbs on May 26, 2020, 12:39:32 pmYes, it is normal behavior, the small difference you see is caused by the internal "input offset voltage" of the 339 comparator. Look in the datasheet of the 339 comparatorhttp://www.ti.com/lit/ds/symlink/lm339.pdfin the table called "7.7 Electrical Characteristicsfor LMx39and LMx39A". Note that there is also an "input offsetcurrent", too, not only "input offsetvoltage". And apart fromoffseterrors, there is "inputbiascurrent".- input offset voltage- input offset current- input bias currentmust all be taken into account as unknown values (but they are all less than the max guaranteed value written in the datasheet, i.e. max 4mV input offset voltage guaranteed, but can be as well only 1 mV, or maybe -4mV).Of course, the measuring instrument has some internal resistance, too, and that can contribute to small measurement errors when you measure the divider voltage, but in your case this is negligible.For your circuit the most errors are caused by the input offset voltage. Input offset current and bias current start to produce errors only when you use very high value resistors for the dividers, for example in the megaohms range (guess why offset and bias current doesn't matter much for dividers made out of low value resistors - if it's not clear why, ask, this is an important step to understand).Note that the same circuit, i.e. 339, might have different max offset and bias depending on what company made the circuit, depending of the ambient temperature, or the supply voltage, etc.

author: jbs
author_rank: Contributor
timestamp: May 26, 2020, 05:45:19 pm
content: That's very informative post. Thank you very much. The LM339 datasheet mentions a max input offset voltage of 5mV, however, my delta is more like 9-10mV.

author: RoGeorge
author_rank: Super Contributor
timestamp: May 26, 2020, 06:12:11 pm
content: Connect the DMM between pin 1 and 2 of the 339 and use a LED or some other indicator to read the state of the 339 output. Leave the DMM connected while you are operating the voltage dividers.- at what voltage (between pin 1 and 2 of the 339) does the comparator starts to shift it's output state? Make a table with a few measurements and post the results here.- what value does those trimmers, or R1,2,3,4 have (with approximation)?

author: Benta
author_rank: Super Contributor
timestamp: May 26, 2020, 06:46:06 pm
content: Quote from: jbs on May 26, 2020, 12:39:32 pmCongrats, you've just learned why hysteresis is almost always built into comparator circuits. Try adding a 1M resistor between output and non-inverting input, You'll be astounded at the difference in stability. However, the switch voltages will shift of course, and will be different at "off" and "on".

author: Doctorandus_P
author_rank: Super Contributor
timestamp: May 28, 2020, 03:42:06 am
content: It's not only noise.When the output of the LM339 switches, the bias currents through the input pins change, and these bias currents create an additional offset voltage that can lead to oscillations. If the resistances on the inputs of the LM339 gets bigger the offset gets worse.