Using LM339 as XOR gate

Discussion in 'The Projects Forum' started by jbord39, Apr 1, 2010.

  1. jbord39

    Thread Starter Member

    Mar 31, 2010
    41
    0
    Hey all,

    I am working on a digital-ish ammeter for my power supply. I am using about 6 reference voltages (from series resistors) to compare this to a known resistor voltage and in turn find the current (in piecewise ranges).

    The 339's are working as far as distinguishing if the voltage is above or below the threshold. Here is an example truth table for my data:

    Input Comp1 Comp2 Comp3 Comp4
    0 0 0 0 0
    1 1 0 0 0
    2 1 1 0 0
    3 1 1 1 0
    4 1 1 1 1

    I was using another row of comparators to now compare these values (1 and 2, 2 and 3, 3 and 4) to find the range of the input. The problem is that for some reason the comparators are working sort of funny (not just around the reference voltage either). Is it possible to use the comparators in this way (like a XOR) gate?

    The final truth table should be like this:
    Input Out(1-2) Out(2-3) Out(3-4)
    0 0 0 0
    1.5 1 0 0
    2.5 0 1 0
    3.5 0 0 1

    Thanks. I am not worried about the output changing erratically at the threshold voltages.

    John
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I quoted your reply to help with the table formatting.
    Tabular data format doesn't work well unless you use the CODE blocks around the text. Compose the table using Notepad or other fixed-width font text editor.
     
  3. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Have you looked at using an LM3914 IC?
    They have 10 comparators and a voltage divider built in, along with a voltage regulator and a current limiter for driving LEDs.

    They're pretty easy to use.
    http://www.national.com/mpf/LM/LM3914.html
     
  4. jbord39

    Thread Starter Member

    Mar 31, 2010
    41
    0
    I have looked into it and am planning on ordering it in the future.

    I am trying to construct it using only comparators and discrete components. Could a comparator be used as an XOR gate?

    Thanks
     
  5. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
  6. jbord39

    Thread Starter Member

    Mar 31, 2010
    41
    0
    Do you know if a comparator can function as an XOR gate?

    Thanks.
     
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Sort of. But instead of being called "XOR gates" they are called "window comparators".

    If you want a real XOR gate, use a CD4070B.
     
  8. jbord39

    Thread Starter Member

    Mar 31, 2010
    41
    0
    Maybe I'm confused but it seems like that doesn't really answer my question. Window comparators provide a high logic when the input voltage is between a range voltages. XOR gates provide a high logic when there is a difference in input logics.

    My question is if a single comparator can be used as an XOR gate.

    Example: a comparator has inputs V- and V+. (outputs high when V+ is greater than V-). So if the two inputs are not analog waveforms but rather digital type signals, would the comparator function as an XOR gate?
    When both signals are high, there would be no difference in input voltages, so it would output a 0; if both signals are low, the same thing.

    Do you know if this could work?

    Thanks,

    John
     
  9. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    No, a single comparator that just has a single inverting input, a single noninverting input, and a single output cannot be used as an XOR gate.
     
Loading...