Shop OBEX P1 Docs P2 Docs Learn Events
Best way to capture HI and LOW triggers? — Parallax Forums

Best way to capture HI and LOW triggers?

BigMikeBigMike Posts: 34
edited 2008-03-02 09:10 in BASIC Stamp
Board: BOE
Stamp: BS2px24

What I've got are two triggers I need to monitor.

One trigger occurs when a certain circuit receives 12 VDC and the other trigger occurs when a certain circuit is grounded.

Please note I am using resistors to drop the 12 volt source down to 5 volts!

What I have right now is the following (and I'm sure this is extremely crude but it works):
INPUT 0 ' Pin 0 is connected to a circuit that gets +12 VDC via a switch -- and it is dropped to 5 volts before the Pin.
INPUT 1 ' Pin 1 is connected to a circuit that gets grounded by a switch

IF IN0=1 THEN ' This means a switch is closed and 5 volts goes to Pin 0.

......do some stuff in here in this case...

ELSEIF IN0<1 THEN ' This means a switch is opened and no voltage goes to Pin 0.

......do some stuff in here in this case...

ENDIF

IF IN1=0 THEN ' This means a switch is closed and Pin 1 is grounded.

......do some stuff in here in this case...

ELSEIF IN1>0 THEN ' This means a switch is opened and Pin 1 is no longer grounded.

......do some stuff in here in this case...

ENDIF




Ok, like I said above, I know this is extremely crude and that is why I am here seeking help. I understand that the IN statement alternates randomly between "1" and "0" if the circuit is open, so here is the gay part of this: I have some diodes installed onto each pin in an attempt to clamp the randomness and it works by keeping the value either a "1" or "0" when the circuit is open depending on my needs.


I am sure there must be a much better method of monitoring HIGHs and LOWs on pins!

Thank you for your help!! blush.gif

Post Edited (BigMike) : 3/2/2008 5:19:59 AM GMT

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-03-02 05:45
    Hi , the normal way to connect a switch or button to an input is to use a "pull up" or "pull down" resistor depending on whether your are switching with 5v or 0v.

    When an input has nothing connected to it then it is considered "floating" and the input can pick up stray signals that may switch it high or low.

    If the switch applies 5v to the input you would have a 220 ohm resistor in series with the switch to protect the input against over current. In addition you would have a 10K ohm "pull down" resistor connected from the input pin to 0v. The 10k resistor ensures the input is at 0 volt while the switch is open. When the switch closes the voltage at the junction of the 220 ohm resistor and the 10K ohm resistor becomes 5 volts.

    Your code looks fine, there are other ways but if it works stick with it.

    Jeff T.
  • BigMikeBigMike Posts: 34
    edited 2008-03-02 05:52
    Thanks Jeff,

    I have used the BUTTON command in the past but I never enjoyed all the delay and button space stuff. Time to revisit it, thanks!

    I just wanted to check my alternatives [noparse]:)[/noparse]

    Mike
  • BigMikeBigMike Posts: 34
    edited 2008-03-02 09:10
    Ok,

    I have completely redesigned my program and my circuit around the BUTTON command and I must say, once you get used to how it works, it is F-A-R more simple and efficient than what I was doing before. The best part is that I am running a bunch of SEROUT commands on every loop. Now I have configured each SEROUT to be used only when there is a change in state, I could no do this as easily before.

    I am glad I was not shy and brought this simple question up -- it enabled me to improve my circuit greatly.

    Good night,
    BigMike
Sign In or Register to comment.