Shop OBEX P1 Docs P2 Docs Learn Events
sx used as a comparator? — Parallax Forums

sx used as a comparator?

infinkcinfinkc Posts: 9
edited 2007-02-15 17:55 in General Discussion
can the sx be used as a comparator(LM339)? any code examples? i have an input that is around 2.5v and want that to compare with +5v and output a low signal.

TIA!

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-02-14 21:24
    The SX has a built-in comparator on Port B which could be used for this function. Unlike the LM339 it only has the one comparator though. You can read about this in the datasheet. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support


    Post Edited (Chris Savage (Parallax)) : 2/14/2007 9:35:14 PM GMT
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2007-02-14 21:55
    To compare an input that is around 2.5V, you would feed this signal into one of the comparator inputs with the other comparator input fed from a reference voltage. If 2.5V is the "critical" voltage, the reference voltage would also need to be 2.5V. If your 5V Vdd supply voltage is stable enough, a voltage-divider network made of two resistors of equal values (say 10 kOhm each) would be fine to generate the reference voltage. For increased precision, you may use a 2.5V Z-Diode-resistor network between Vdd and Vss to generate the reference voltage.

    The RB1 and RB2 port pins can be configured as comparator input pins, and the RB0 port pin can optionally be configured as the comparator putput pin (see the SX data sheets for more details).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • BeanBean Posts: 8,129
    edited 2007-02-14 23:49
    If you are running the SX from 5 volts, then you can trigger an input at 2.5V by setting it to CMOS input levels.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman
  • pjvpjv Posts: 1,903
    edited 2007-02-15 03:34
    Hi All;

    And of course you also could configue an R/C digital to analog onverter on the SX, and let that be one of the comarator inputs. Then with very simple software you can chose the trigger level anywhere from 0 to 5 volts.

    In fact, if you wanted to get cute, you could even use the one comparator input AS the DAC. Done this a number of times.

    Cheers,

    Peter (pjv)
  • infinkcinfinkc Posts: 9
    edited 2007-02-15 17:22
    Bean (Hitt Consulting) said...
    If you are running the SX from 5 volts, then you can trigger an input at 2.5V by setting it to CMOS input levels.

    Bean.

    is there an example how to do this? would it be a problem if the signal rests at +5, the goes to 2.5 when active?
  • BeanBean Posts: 8,129
    edited 2007-02-15 17:55
    If you are using SX/B just do

    MyPin PIN RB.0 INPUT CMOS

    This will set the threshold voltage to 2.5 (if running at 5V), so if the voltage goes from 5 to 2.5 you might or might-not get a change in the input.

    It would be better to run the voltage into a voltage divider (two resistors) to get the levels down.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman
Sign In or Register to comment.