Shop OBEX P1 Docs P2 Docs Learn Events
BS2 State Machine — Parallax Forums

BS2 State Machine

KatyBriKatyBri Posts: 171
edited 2005-11-12 03:50 in BASIC Stamp
Is it possible to set up the code for a BS2 or BS2p24 to act like a state machine- idle until certain inputs are active. This would be analogous to using interupts at the processor level.

If one uses looping code to simply poll input pins, it is possible to miss an event on a pin, and the processor is running continuously. With code that responds to pins directly (as interupts), an event is less likely to be missed. Is this possible with the BS2 STAMPS- either with code only or with code plus input circuitry?

Comments

  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-11-11 23:32
    On the BS2p, pe and px there are the POLLing commands. In particular POLLWAIT in conjuction with POLLIN and POLLMODE can be set up to monitor inputs and respond quite rapidly to events. Also, some of the polling modes can "latch" the occurance of an event, so that the processor can deal with rather short lived events. It is still not quite like an interrupt, in that the inputs are checked only at intervals that may be milliseconds apart.

    Another workaround uses a little extra hardware, an RC circuit and a diode perhaps, to stretch input pulses so that longer polling intervals are adequate.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • metron9metron9 Posts: 1,100
    edited 2005-11-12 02:30
    "at intervals that may be milliseconds apart"

    or may be microseconds apart as well

    As well as the RC circuit for extending input, a latching buffer circuit could also be used.

    Another idea is to use a 20mHz or faster microcontroller chip like the SX that simply stores event triggers and feeds them to the basic stamp via serial interface as the stamp requests them. I am sure someone here could whip up an sx buffer chip that polls 15 input pins and stores changes of state in a buffer that a bs2 could read at it's own pace.
  • KatyBriKatyBri Posts: 171
    edited 2005-11-12 03:50
    Thanks Tracy - just what I needed. Also, my thanks for the other threads.
Sign In or Register to comment.