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.
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
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).
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.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Post Edited (Chris Savage (Parallax)) : 2/14/2007 9:35:14 PM GMT
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
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
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)
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