Shop OBEX P1 Docs P2 Docs Learn Events
i''m new, need help with command — Parallax Forums

i''m new, need help with command

ArchiverArchiver Posts: 46,084
edited 2004-02-10 07:36 in General Discussion
>Here's a basic description of my circuit: A user can press one of 4
>momentary switches, labeld A, B, C, and D. Pressing the A buttons
>will cause the program to go into the A subroutine, pressing the B
>button goes into the B subroutine, and so forth.
>
>I just can't figure out how to make the program look for these
>triggers. I want the stamp to be continuously looking for one of the
>4 inputs. I originally thought POLLIN would work, but I can't find a
>way for it to distinquish which button was pressed. And since it's
>just a momentary pulse coming from the switch, I can't think of what
>else to use.
>
>Does anyone have any suggestions? By the way, it's a BS2p40, because
>I have 20 I/O elements for this program.
>
>Thanks for any help you might be able to offer.

Hi Andy,

I'm glad you asked. It gets to one of those hidden capabilities of
the BS2p and BS2pe that Chuck Gracey kindly stuck in there, yet one I
think not many Stampers know exist.

Take a look at POLLMODE 10, and scratchpad locations 128 to 131.
Those scratchpad locations are read-only, updated by the system. The
32 bits there correspond to the 32 input pins on the BS2p40 (or the
BS2pe40), and each bit goes to one when its corresponding POLLIN pin
goes to its target state. In POLLMODE 10 (and certain other
POLLMODEs >8), those bits are latched. That means that a brief pulse
on a POLLIN pin, so long as it spans two PBASIC instructions, will
cause its corresponding trigger bit to be latched. The program can
take its sweet time to look for which one occurred. Note that you
can have several POLLIN pins active on both MAINIO or AUXIO at once,
and the POLLMODE applies to all of them.

If you want an easy way to test whether at least one trigger event
has occurred, here it is. You don't have to scan the scratchpad
locations. This is similar to the idea presented in the Stamp v2
manual at the end of the description of the POLLOUT command. Define
at least one POLLOUT pin (You don't even have to use the pin for real
output). Then define your POLLIN pins, as many as you want. If any
one or more of those goes active, then the output bit will change and
latch, and you can test that...

ON out0 GOSUB ...

and branch off to a routine that scans the scratchpad locations to
see which event(s) occurred.

The latches are all reset to the untriggered state when you next
issue the POLLMODE command. There is always some chance that you
will miss an event during your service routine, but hey.

I have several example routines posted at the following URL, along
with more text.

http://www.emesystems.com/BS2pe.htm#spram_specials

It is a little bit complicated, and I was trying to explain it to
myself. There are a lot of combinations I have not tried yet.

-- regards,
Tracy Allen
electronically monitored ecosystems
mailto:tracy@e...
http://www.emesystems.com
Sign In or Register to comment.