Having trouble with comparator with hysterisis

Discussion in 'General Electronics Chat' started by Alvin, Jan 25, 2008.

  1. Alvin

    Thread Starter Member

    Jan 22, 2008
    22
    0
    I'm trying to build this circuit with a LM339 and I'm not having much luck.. I don't think I'm on the right track with the resistor combination and was wnodering if one of you guys might be able to help.



    R1 RL = 3.9K ohm
    R2 and RH i have as 100 ohm.

    My goal was to have somehting come on at around 3 volts with around a .2 volt historisis. I would honestly like to adjust the on point with a pot but have a fixed hysterisis.




    [​IMG]
     
  2. Alvin

    Thread Starter Member

    Jan 22, 2008
    22
    0
    I should mention that this is DC and will be driving a relay via a small power transistor. The problem is my input is a good bit jumpy and I don't want it to burn up the relay.
     
  3. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    What is your V+?

    Your RH needs to be MUCH higher than it is now. If you change R1 and R2 to 10K, an RH of 270K will give about 0.2V hysteresis with V+ being 12v.

    The comparator won't have much current output. Better to use either a FET/MOSFET or a Darlington driver.

    Why is your R2 so low?

    I guess a better question to ask is, at what voltage do you want the output of the comparator to go high?
     
  4. Alvin

    Thread Starter Member

    Jan 22, 2008
    22
    0
    Hey thanks for the response.

    I'm on 12v and I would like the output to go to 11-12v when in the input goes above 3v and stays on until voltage drops below 2.8v Honestly i would like a trim pot to adjust my input trigger between 3-7 volts but keep the .2 volt hysterisis (approximate, the hysterisis doesn't need to stay exactly .2 v)
     
  5. Alvin

    Thread Starter Member

    Jan 22, 2008
    22
    0
    Just for clarification I picked the R values with a excel worksheet I made with the forumlas above in the picture.
     
  6. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Ok, the attached circuit is pretty close to what you're shooting for.

    R1 adjusts the threshold level. R4 and R5 ensures that the threshold level only varies between around 2.7v and 7.2v. Note that the "80%" next to R1 means that the upper leg of the pot is 20% of 50K, and the lower leg is 80% of 50K.

    R3 needs to stay at around 1K.

    Since the sum of that R4-R1-R5 network is nearly 110K Ohms, it was necessary to scale RH up porportionately. With the original 20K divider, a value of around 270K Ohms for RH gave around 220mV hysterisis; now about 1.3M Ohms are needed. The advantage of using larger values of resistors is that current consumption will be reduced. A disadvantage may be that the circuit will be less stable; but you'll have to determine that via experimentation.

    I chose an IRF510 N-channel MOSFET for the output driver, because these are pretty inexpensive and commonly available. R6 represents the coil to your relay. You should have a diode wired across the coil with the cathode towards V+ to absorb the voltage spike when the current is cut off.

    (Note: the + and - inputs to the comparator are reversed)
     
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Here's another version. Note that I replaced the MOSFET's load resistor with a motor and diode, and that the entire hysterisis network has been scaled down in resistance. The current in the network will still be very low (on the order of a milliamp or so) but will likely be more stable than the previous circuit I posted.

    The hysterisis is about 180mV at 2.3v, and around 230mV @ 2.3v You can decrease the resistance of R2 a bit to increase hysterisis. 220K will give you about 280mV at 7v.

    The first image shows R1 at 80%, the 2nd shows R1 at 15%. Note that in the 2nd image a small cap has been added across D1; this helps to surpress transients.
     
  8. pebe

    AAC Fanatic!

    Oct 11, 2004
    628
    3
    You need positive feedback from the output to input to get hysteresis, so the circuit is basically correct but the values are way out. Try these values on it.

    R1 = 36K3 (33K + 3K3 in series)
    R2 = 12K

    The +ve input will then sit at 2.98V and its source impedance from the supply will be 9K.

    Make RH = 532K (470K + series resistors to suit). That will give you about 0.2V hysteresis.

    RL will not affect things much. You can use that as the base feed to a transistor to switch your relay. The IC has an open collector output so you will need to drive a PNP driver for the relay.
     
  9. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    Sarge, both of those circuits have negative feedback, which generally results in oscillation when applied to a comparator.
    EDIT: I suppose the small amount of feedback avoids oscillation, but you certainly won't get hysteresis.
     
  10. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Thanks for the catch, Ron_H - had a lot of background activity going on when drawing it and I missed that. :rolleyes: Don't know how really, it's rather glaringly obvious now that you pointed it out.
     
  11. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    SgtWookie, I apologize for the somewhat harsh response. I should have realized that you had simply accidentally swapped the inputs on the comparator, and responded accordingly.
     
  12. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Your response was harsh? Nah, not even close ;) No apology necessary.
     
  13. Alvin

    Thread Starter Member

    Jan 22, 2008
    22
    0
    Hey Guys,

    Still having a bit of trouble with this. I used the Second set of schematics you posted but needed to replace the 470 ohm resistor with a 1k just to keep the relay off. (I'm using a TIP 3055 to drive an automotive relay.) because of this I only got around .05v hystoresis with the 270k resistor so I increased it to to a 1meg resitor and I'm getting approximately 100mv of hystoresis.

    What shoudl I do to get my hystorsis back up to 200mv?
     
  14. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    Are you wanting to turn the relay on when the input when the input goes above the threshold, or below? Are you using +12V for your Schmitt trigger supply voltage?
     
  15. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    OK, having to increase the resistor from 470 Ohms to 1K is my fault.

    The maximum sink current for the lm339 is 20mA, which means that at 14V it needs at least 700 Ohms between the LM339 output and V+ to limit the current! (R = E / I, so R = 14 / .02 = 700) The simulation I was using should've blown up at that point, but it didn't. Changing it to 1K Ohms will give some "headroom" to the LM339 so it's not running wide open all the time (sinking max current). The other change would be to drop the feedback from 270K to 220K, and then you'll have about 200-220mV of hysteresis.

    Right now your problem is the selection of the TIP3055! The circuit I put together used an IRF510, which for all practical purposes has infinite resistance on it's gate. In contrast, the TIP3055 can pull up to 7 AMPERES (!) through it's base! It's not surprising at all that your hysterisis has gone kaput. If you're going to keep using that TIP3055 instead of the recommended MOSFET, you're going to have to add a driver stage for it with another transistor (PNP), and limit the current to THAT transistor's base using a resistor. Otherwise, the LM339 can't sink enough current to turn the thing on and off. If you tried using a limiting resistor between the output of the LM339 and the base of your existing TIP3055 transistor, the transistor won't fully cut off or turn on, and it will foul up the hysterisis. Meanwhile, the transistor being in a partially-conducting state will cause it to become mighty warm, mighty quick.

    So, what would you like to do now?

    [edited to add]
    Attached is yet another modification to the circuit to enable you to use your TIP3055. The TIP3055 has a gain (hFE) of 70, and the 2n3906 is around 300; in this configuration the gains are multiplied which is what you need. Note that the base current of the 2n3906 is limited by R6. R7 may not be absolutely necessary, but it's there in case Q1 fails.

    Since you're now using a transistor instead of a MOSFET, the voltage to the output is automatically reduced by at least 0.6 (the voltage drop across the emitter-base junction), and the transistor will get warm since it's dropping voltage across itself. Don't forget to heat sink it, or it will fail.
     
  16. Alvin

    Thread Starter Member

    Jan 22, 2008
    22
    0
    Humm.. ok. I was using the 3055 just because thats all I've ever used.. I've not had any formal electronics training..

    Will that mosfet drive an automotive relay with no real issues?
     
  17. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Sure it'll drive an automotive relay.

    The big issues with MOSFET devices is that they are vulnerable to static electricity and over voltage. This is why you need to have the diode across the relay (or other inductive load) to absorb the reverse EMF when the current flow is cut off. The capacitor absorbs the start of the EMF pulse during the time it takes for the diode to turn on.

    Power MOSFETs don't like to be in "partially conducting" state very much; it's either ON or OFF. To turn an IRF510 fully ON, you need to hav the gate 10v higher than the source. To turn it off, you need to put the gate at the same or lower potential as the source. The circuit I put up does that.

    Power MOSFETs have much lower ON resistance than transistors do, and they don't have that fixed 0.6V drop across the emitter. That's why they can handle much more power than a comparably sized transistor.
     
  18. Alvin

    Thread Starter Member

    Jan 22, 2008
    22
    0
    I really appreciate your help in this matter.


    I think thats my problem.. or rather I'm not sure what the heck is going on!!


    The problem I'm having a the moment is that as the input voltage climbs (slowly like .5v/second which) the output pin of the comparator goes from 0-2-4-6-8v Thats exactly whatI wasn't trying to get.. I wanted something that would watch this input signal.. which climbs slowly but bounces about 100mv at a freq of approximately 1hz and have a descrete output... IE when input voltage climbs above Xvolts the output of the comparator switches fast from 0v to 12v.

    I have absoulutely why I'm getting these.. I always thought comparators have a descrete output 0 or 1 thats it.. was I wrong?
     
  19. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Well, the output of the comparator should "snap" on and off - but it won't if you have the base of the TIP3055 connected up.

    I'm going to fiddle with the model to more accurately simulate your input.
     
  20. Alvin

    Thread Starter Member

    Jan 22, 2008
    22
    0
    I didn't know that.. What makes it do that?

    I just took the hysterisis resisitor out of the circuit (RH?) and the output definately snapped on and off.. the only problem is when it snapped off it would flicker a bit which is what I'm really trying to advoid.
     
Loading...