Shop OBEX P1 Docs P2 Docs Learn Events
PAUSE and POLLIN — Parallax Forums

PAUSE and POLLIN

SunztSunzt Posts: 9
edited 2007-03-27 16:07 in BASIC Stamp
It seems that POLLIN does not work when a PAUSE command is executed. Is there a way to keep detecting a pin for POLLIN while a PAUSE command is running?

Here's some example code:

' {$STAMP BS2px, receivekill.bpx}
' {$PBASIC 2.5}

POLLInitialize:
POLLIN 6, 0 ' Pin 6 is set to low if receiving data
POLLRUN 1 ' Runs killswitch program
POLLMODE 3

Main:
DO
DEBUG "PAUSE", CR
PAUSE 5000
LOOP


The above program wont switch program slots during the pause. If I don't put a PAUSE then the program switches kinda erratically without the POLLIN pin actually changing, but that might be a different issue.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-27 14:17
    Hello,

    Bear in mind that the POLL commands check between instructions, not while an instruction is executing, so during the PAUSE you should expect not to be able to detect anything. On the other hand if you use a passive counter the program can still pause but it will still be executing instructions. This can be done by executing a loop with a small PAUSE value of say, 1 mS and then looping approximately 5000 times (minus overhead). Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-03-27 16:07
    Another option might be POLLWAIT:

    POLLInitialize:
    POLLIN 6, 0 ' Pin 6 is set to low if receiving data
    POLLMODE 3
    
    main:
      POLLWAIT 8   ' run 1 instantly when xtion detected, no sleeping
     ' ...
    



    The problem with that, depending on what else the program has to do, it that it waits forever until p6 activates. If the program has to do other things, it might be necessary to break out of the POLLWAIT at intervals. The way I do that sort of thing is with a heartbeat output from a real time clock chip, or you could even use an RC timer on another pin. Set that pin also as a POLLIN, so that either your Kill pin or the timeout can end the wait state. The pollmode has to be changed and the program has to check which event triggered the wakeup before taking action.

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