Shop OBEX P1 Docs P2 Docs Learn Events
Latching an Input — Parallax Forums

Latching an Input

civstercivster Posts: 17
edited 2005-07-18 05:37 in BASIC Stamp
I'm trying to figure out the best way to latch an input in case my application is performing a PAUSE instruction.

Here is an example:

Slot0
StartBtn  PIN  15 ' pin 15 is active low

POLLIN StartBtn, 0
POLLRUN 1 
POLLMODE 3

Main:
DO
  ' Perform tasks here
  PAUSE 50
LOOP
END




My current dilemma is that pin 15 will be connected to a relay output of an external device that will only close the contacts for a few milliseconds. In my example above, if pin 15 is pulled low when the PAUSE instruction just begun and its' only pulled low for 40ms then the program in slot1 will not be executed.

I'm wondering if there is something that will pull pin 15 low until a program in slot1 resets it.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-06 17:28
    Sounds like a job for a flip-flop.· Some have a reset pin on them.· They can be configured as a one-shot until reset.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • civstercivster Posts: 17
    edited 2005-07-06 17:36
    I don't have any experience with a flip-flop and I've only read about using the 555 as a flip-flop.

    Any resources around that can enlighten me on using a flip-flop for my current application?

    Thanks!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-06 17:42
    You can also configure a 555 as a one-shot with an output pulse that is longer than your longest "away" time. A second pin can be used to reset it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2005-07-06 20:56
    Here is a SET/RESET latch using two transistors arranged in a standard SCR configuration.

    The SENSE pin is an input·(read your signal here)

    The Set/Reset pin is an output and supplies power to the SCR.· To "set" the latch make this
    pin LOW.· To "reset" the latch make this pin HIGH for about 1mS, and then LOW again.



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

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 7/6/2005 9:01:26 PM GMT
    1365 x 981 - 231K
  • stamptrolstamptrol Posts: 1,731
    edited 2005-07-07 00:32
    The other way to think about it is to put your PAUSE in a subroutine and reduce it to say, 1 or 2. In the main part of your program you put a call to the subroutine. Now, keep track of how many times you go to the subroutine. In this case, if you count up to 10 or 15, you know you've paused for about 50, but your program is never stopped longer than the time it takes to do one excursion to the subroutine.

    Don't forget to check the status of StartBtn each time you come back from the subroutine.

    Cheers,

    Tom Sisk
  • civstercivster Posts: 17
    edited 2005-07-07 17:59
    Beau,

    Thanks for the SCR diagram and after studying it, I'm guessing that the BS2p pin that is connected to SENSE will now be active high. Also, the TRIGGER will be connected to my external device's N.O. relay and back to +5VDC? Without these transistors in hand, I couldn't test these theories on the bench.

    Just as Tom suggested, I've already set my PAUSE to 5ms increment in a FOR...NEXT loop, however, I would also like to have the input latched for redundancy.
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2005-07-07 20:16
    Do you need the SENSE to be active low? I just find it easier to work and reference things to GND, so I usually design that way. If you have a long distance between the SCR and the
    N.O. relay contacts, you might find this circuit a little sensitive. You can counter this by decreasing the value of the 10K resistor, likewise if you need more sensitivity you can increase
    this value. Leave the parallel 1K and .022uF the way it is (errr don't change R... C could vary from .1uF to .01uF), this prevents false triggering during power-up, by creating a virtual
    short across the B-E junction of the PNP transistor.

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

    IC Layout Engineer
    Parallax, Inc.
  • civstercivster Posts: 17
    edited 2005-07-18 03:53
    Beau,

    I really appreciate your help with the SCR diagram. I finally got some transistors and decided to build the SCR circuit.

    I did noticed an oddity; when I connected an LED to the SENSE pin of the circuit, the LED will be on after the TRIGGER goes high but it will not turn off when the RESET pin goes high. When I connected the circuit to my Stamp, it worked as expected.

    Below, is the code I used to check the circuit:

    ' buttons are setup as active high
    startbtn    PIN    0
    resetbtn    PIN    1
    
    pressed    CON    1    'active high
    
    initialize:
    LOW resetbtn
    DEBUG CLS
    
    main:
    IF startbtn = pressed THEN
      DEBUG CLS, "button pressed"
      PAUSE 5000
      PULSOUT resetbtn , 8000 ' each period is 0.8us
      DEBUG CLS
    ENDIF
    GOTO main
    END
    
    



    While studying your diagram, I believed it's possible to use the same pin in Basic Stamp to be the SENSE and the RESET?

    Again, thanks.
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2005-07-18 04:40
    civster,

    SCR's are funny when you are trying to turn them off.... they basically don't want to. Connecting a LED to the SENSE pin probably allowed enough of a path to VSS that the
    SCR was not able to turn completely off. If you want an LED indicator, put it in series with the SET/RESET pin.

    As far as using the same stamp pin for the SENSE and RESET.... This would not work since the SENSE pin needs to be an INPUT to the stamp, and the SET/RESET is actually
    supplying VSS to the SCR. By making the SET/RESET pin HIGH you are supplying +5V to the SCR's ground, this effectively turns off the SCR - "RESET" ...Making this pin LOW
    again, the SCR is "SET" and ready for a trigger.

    Now, you could interchange these two pins, but one needs to be an OUTPUT supplying power/ground to the SCR, while the other needs to be an INPUT.

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

    IC Layout Engineer
    Parallax, Inc.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-07-18 05:37
    One KISS way to latch a short signal is with a capacitor. Connect the capacitor (0.1 uf, say) across the relay contacts, with a small resistor (~220 ohms) in series to limit the current and sparking. The contacts and capacitor are connected to Stamp pin p15. Note: _No_ pullup or pulldown resistor. The Stamp charges the capacitor to +5 volts with a quick PULSOUT 15,200 or quick HIGH 15:LOW 15 sequence. The capacitor will stay charged for a long time. However, when the relay closes, it will discharge the capacitor and that is the memory of the event. The Stamp can takes its time to get around to looking at pin p15. Assuming there are no leakage paths, the capacitor can hold its state, high or low even for 10s of seconds. Every so often, and after the relay cycles, the program (slot 1) will have to refresh the charge on the capacitor. This is the principle of dynamic memory. If you do use a pullup resistor on the pin, make it a high enough resistance so that the time constant to recharge the capacitor will stretch out longer than your longest PAUSE. That circuit would be self-resetting and would work fine with POLLRUN.

    With POLLRUN, the program will break out of slot 0 and into slot 1 immediately, between two Stamp instructions, when the event occurs. Sometimes, some programs, the interruption might occur at a bad time in the middle of other tasks. Maybe that isn't a problem here.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.