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 16:57 in General Discussion
Hi again Andy,

Yes, that straight out scan is going to be simpler than the mind set
for the POLLing commands. And yes, 0.5 second is forever in
microcomputer terms. On the Stamp, each one of those instructions
like
> > IF (ButtonA = 1) THEN BtnA_Sub
will take about 1 millisecond to execute, so the entire loop to scan
4 pushbuttons will execute in well under 10 milliseconds.

Note that you also have to allow for the case that someone leans on
one of the buttons. If you don't want the button action to occur over
and over, you will have to write code to do the action once per
event. Take a look at the BUTTON command, which has such debounce.
However, everyone agrees that with several buttons involved it is
more efficient & flexible to write your own code to do that.

The simple scanning will be more of a problem if the Stamp has to do
a lot of other processing at the same time, or if you want it to
catch a quick 0.05 second button press or a similar signal that comes
from an instrument like a tipping bucket rain gage. Or, if the
program has to conserve power while waiting for a button to be
pressed. The POLLIN latched modes work really well with the POLLWAIT
command on the BS2pe/pe, so the chip can nap until an event happens
and then test the scratchpad registers to determine which event(s).

You mentioned an RC input network. That can effectively stretch
events like the 30 millisecond rain gage pulse. Just a 0.1uf
capacitor from the Stamp input to ground, and 270 ohm resistors to
limit the current to the stamp pin and to the switch. The stamp pin
is an output to charge the capacitor. The program returns about once
a second to check the voltage on the pin and to refresh it. If it
finds zero volts, that means the switch has closed in the interim.
The Stamp adds one to the count before refreshing the charge on the
capacitor.

-- Tracy





>Well, by "quick", I mean that the pin will only be high for maybe 0.5
>seconds. Assuming that the only thing going is the loop looking for
>a high on one of the 4 pins, I don't know if that 0.5 sec high is
>long enough. Perhaps I could add some kind of RC circuit to keep the
>pin latched for an extra second or so. The POLLMODE latching stuff
>looks a little more complicated. But if it's that much better, I'll
>try to figure it out.
>
>Thanks,
>Andy
>
>--- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
>wrote:
>> The depends on how you define "quick" and keep in mind that standard
>> Stamp inputs are not latched. As Tracy suggested, however, you can
>use
>> POLLIN instruction with a MODE that will latch polled inputs, but
>note
>> that using POLL instructions work in between other things (the
>Stamp is
>> single threaded). In addition to the manual, and information on
>Tracy's
>> web site, you may find this article helpful:
>>
>> http://www.parallax.com/dl/docs/cols/nv/vol2/col/69.pdf
>>
>> -- Jon Williams
>> -- Applications Engineer, Parallax
>> -- Dallas Office
>>
>>
>>
Original Message
>> From: andy_watson5 [noparse][[/noparse]mailto:andywatson@m...]
>> Sent: Tuesday, February 10, 2004 8:58 AM
>> To: basicstamps@yahoogroups.com
>> Subject: [noparse][[/noparse]basicstamps] Re: i'm new, need help with command
>>
>>
>> Ah, I see. Thanks for the help. That sounds like it might work.
>>
>> So if I have an infinite loop looking at the buttons:
>>
>> Button_Scan:
> > IF (ButtonA = 1) THEN BtnA_Sub
> > IF (ButtonB = 1) THEN BtnB_Sub
>> IF (ButtonC = 1) THEN BtnC_Sub
>> IF (ButtonD = 1) THEN BtnD_Sub
>> GOTO Button_Scan
>> ....
>>
>> Is this loop quick enough to catch a quick pulse on one of the
>> momentary buttons? I just don't know how fast the stamp scans, and
>I
>> don't want the program to be looking at ButtonC when someone
>presses
>> ButtonA, but they release it by the time the program gets back to
>> looking at ButtonA again.
>>
>> Thanks,
>> Andy
>>
>> --- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
>> wrote:
>> > You can do this simply and prioritize your scan through simple IF-
> > THEN
>> >
>> > Button_Scan:
>> > IF (ButtonA = 1) THEN BtnA_Sub
>> > IF (ButtonB = 1) THEN BtnB_Sub
>> > ...
>> >
>> > BtnA_Sub:
>> > ' code for button A
>> > GOTO Button_Scan
>> >
>> > This uses an implicit GOTO in IF-THEN. The sample above assumes
>> that
>> > your inputs are active-high (read a 1 when the button is pressed -
>-
>> > change to 0 for active low). While this code is a bit "grunt" it
>is
>> > simple and allows you to prioritize the buttons in the event that
>> more
>> > than one get pressed.
>> >
>> > If you want to check all the buttons in order and process those
>> that are
>> > pressed, you can change your code like this:
>> >
>> > Button_Scan:
>> > IF (ButtonA = 1) THEN GOSUB BtnA_Sub
>> > IF (ButtonB = 1) THEN GOSUB BtnB_Sub
>> > ...
>> >
>> > BtnA_Sub:
>> > ' code for button A
>> > RETURN
>> >
>> >
>> > -- Jon Williams
>> > -- Applications Engineer, Parallax
>> > -- Dallas Office
>> >
>> >
>> >
>>
>>
>>
>> To UNSUBSCRIBE, just send mail to:
>> basicstamps-unsubscribe@yahoogroups.com
>> from the same email address that you subscribed. Text in the
>Subject
>> and Body of the message will be ignored.
>>
>> Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>>
>> This message has been scanned by WebShield. Please report SPAM to
>> abuse@p...
>
>
>
>To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
>from the same email address that you subscribed. Text in the
>Subject and Body of the message will be ignored.
>
>Yahoo! Groups Links
>
>
>
>
Sign In or Register to comment.