Shop OBEX P1 Docs P2 Docs Learn Events
Reading Voltages — Parallax Forums

Reading Voltages

SN96SN96 Posts: 318
edited 2009-05-18 02:26 in BASIC Stamp
I have the BS2px and I was wondering if the CONFIG command would allow me to· trigger a·program routine when the voltage changes from 1.6v to 2.5v? I do not need to measure the voltage, just cause my program to react to the change. I built a sound sensor that has an output wire that normally puts out ~1.6v but when a sound is detected, the wire puts out ~2.2v. TTL logic threshold is logic low @ 1.4v and logic high @ above 1.4v my circuit is normally outputing 1.6v.

Whats the best way to react to voltage changes?





▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike



·

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-05-15 15:41
    You could use the COMPARE comand (BS2px only), with fixed 2 volts on pin p1 and your sound trigger voltage on p2. Then you can read the result of the compare in a variable.

    It depends a lot on what else the program has to be doing, while waiting for the sound trigger. It could sit and watch the result of the comparison, or it could do other stuff and come around occasionally.

    Also look at the POLLIN command. This provides another way to detect the sound trigger, but you would have to shift the 1.6 to 2.5 volt signal down by about 0.6 volts, so that it would span the 1.4 volt trigger point of any Stamp input. The POLLing commands can be configured to latch an input event (hold on to a brief event even while the program is off doing something else), and it can be configured to trigger while the Stamp is in a low power SLEEP mode or to trigger very rapidly to the event.

    I'm not sure exactly how the COMPARE interacts with the POLLing, but I believe that if you enable the p0 output from a compare, that can be used as an input to POLLing.

    There is ordinary polling too, available on any Stamp on any pin. Just look at the input to be above or below the threshold, but the program has to be there to catch it or have some external means to stretch external events.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • SN96SN96 Posts: 318
    edited 2009-05-15 16:38
    Thanks,

    I will try the compare command by feeding one pin 5v and the other pin the sensor output and use the difference as the trigger.

    I will also look in to the POLL command and see if that will work for me also.

    I got this to work using a Basic Atom Pro, which has a built in AD converter but I think I fried the AD converter some how. The AD pin is rated for 5v and my circuit only puts out 2.5v so I don't know what happened. Below is a video using the Atom MCU but I also have the BS2px I can try.

    http://www.youtube.com/watch?v=23s_LwDYKiQ&fmt=6

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike



    ·
  • SN96SN96 Posts: 318
    edited 2009-05-16 13:13
    I got this to work with the BS2px. I used the normal input pins and set the input to high (2.27v) and the program looks for a momentary low to trigger that a sound has been detected. It works well.

    Here is the simple code:

    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}

    DO

    IF IN3 < 1 THEN
    DEBUG "it works" '<
    Can be replaced with any set of instructions
    PAUSE 1200 '<---- Allow time for the pin to return to a high state
    ENDIF

    LOOP

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike



    ·
  • UghaUgha Posts: 543
    edited 2009-05-17 01:16
    Couldn't you have used a simple resistor to lower the normal 1.6v output to something below the 1.4v threshold? This would allow it to only register a HIGH when a sound is detected.
  • SN96SN96 Posts: 318
    edited 2009-05-17 20:56
    Yes I could but I don't have any resistors on hand with the right value.·I don't want to use 5 resistors in series·to drop the voltage. Using the output of the op amp works well. But yes, using a single resistor to drop the voltage below 1.4v is certainly a great solution.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike



    ·
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2009-05-18 02:26
    I would be tempted to try a diode in series with the I/O pin. The PN junction of the diode on average will drop the voltage about 0.6V which might also be a solution to using Tracy Allen's suggestion.

    Note: Because the voltage drop across the PN junction is proportional to the current across the PN junction, you might need two diodes in series to get an adequate drop. Just about any generic Si diode should work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
Sign In or Register to comment.