PDA

View Full Version : question about pollwait in latched state



basicstampede
01-25-2007, 03:48 AM
Below are two programs.· First goes to slot 0, and second goes to slot 1.
Question is listed below code.

' {$STAMP BS2p, pollwait2slot1}
' {$PBASIC 2.5}
sw0 PIN 0
led1 PIN 1
sw_reset PIN 2
idx VAR Byte
setup:
POLLIN 0, 0
POLLOUT 1, 1
POLLRUN 1
POLLMODE 12 'latched, pollout, pollwait, pollrun allowed
main:
·DEBUG "Slot 0:· ", CR ', DEC5 idx, CR
·POLLWAIT 7
GOTO main


' {$STAMP BS2p}
' {$PBASIC 2.5}
'This is program pollwait2slot1 which is in slot 1 of program above
DEBUG "Slot 1:· ", CR
DO WHILE IN2=1
LOOP
TOGGLE 1
POLLMODE 12
RUN 0
END

When I run the program above, it kind of works.· The problem is that since I've set POLLWAIT 7, BS2p wakes up every 2.3 seconds and checks the input switch.

If I press the pollin switch while BS2p is napping, it misses the "interrupt".· i.e. I must press and hold the pollin switch (pin 0) for at least 2.3 seconds to reliably have the Stamp respond.

Is there a way for Stamp to "latch" the switch input so that even if the switch was pressed while Stamp was napping, when it finally wakes up, it will see that the switch was pressed, and take program to slot 1 (in this case).·

Reason:· I want to maximize the napping time to save battery, but I don't want to miss the external trigger either.

Actually, I thought by putting it on POLLMODE 12, I was expecting the input switch to be latched, thus not miss this signal.· I guess Stamp really goes to sleep.

Any insights from anyone?

Thanks in advance.

Tracy Allen
01-25-2007, 05:04 AM
Your best bet in that situation may be to install a capacitor in parallel with the switch. Provided there is not an external leakage path, a capacitor of even 0.01uf will "latch" the event for many seconds. To refresh the latch, recharge the capacitor with a pulsout before the pollwait.

An aside: If you were using the BS2pe instead of the 'p, you could go to a much shorter POLLWAIT interval to catch the event without much penalty in current drain.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com (http://www.emesystems.com)

basicstampede
01-25-2007, 08:37 PM
Thanks Tracy. I thought I could get around by reading memory location 128 using GET 128, but it still did not catch the short
input. I guess I have to put that capacitor. pe is also a good suggestion. Thanks.