Shop OBEX P1 Docs P2 Docs Learn Events
Useing Pollxxx commands to react to input faster — Parallax Forums

Useing Pollxxx commands to react to input faster

WT in IndianaWT in Indiana Posts: 5
edited 2005-10-28 17:15 in BASIC Stamp
I need to react to a pin going high very fast and I read that the Poll in command could help me do that but for the life of me I cannot figure it out.


Heres what I have (cliff notes)
**********************************
loop:
BUTTON 0,1,10,400,B2,0,Label1
PULSOUT 10, 650
PULSOUT 1,3750
GOTO loop:

************************

I may have misunderstood that I can use the pollin command to execute a subroutine stored in eeprom.

but I can't figure out how

can I put the pulse out command in Slot 0 and do a loop and wait for the input on port 0 to go high

if so how do I write the pulsout command into memory and trigger the program to execute

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-27 16:01
    You can use POLLRUN to jump to another program slot, but this is not the same as calling a subroutine -- you would be forced to create your own tracking mechanism so that the program could come back to the point of the jump.

    Forget the Cliff Notes ... what, specifically, are you trying to accomplish. The solution may be simpler than you imagine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • WT in IndianaWT in Indiana Posts: 5
    edited 2005-10-27 16:05
    OK I guess that I didn't ask correctly




    I have an input trigger going high for 2 msec

    I need to delay 750uS after the front edge of that trigger and pull the output line low for 3 msec.

    the timing of the delay needs to be programmable and precise

    Ohh yeah, It needs to be done soon with only the parts I have on hand
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-27 16:08
    In my opinion (driven by the word "precise" in your response) you're not going to that with the BASIC Stamp. The problem you're facing is PBASIC instruction load/setup time. Let me suggest that you explore our SX micro and programming in SX/B -- that will give you the performance you're looking for and the ease of BASIC programming.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • WT in IndianaWT in Indiana Posts: 5
    edited 2005-10-27 16:22
    Ohh yeah, It needs to be done soon with only the parts I have on hand


    is there a way to use the pollin in command to trigger a command set ?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-27 16:28
    POLLing functions working in between other language statements, so you're still delayed.· I think you had it pretty close in your first post -- you'll need to use a 'scope to tweak your timing.

    Reset:
    · HIGH OutLine

    Main:
    · DO : LOOP UNTIL (InLine = 1)··· ' wait for input to go high
    · PULSOUT SparePin, 300·········· ' delay·from front end
    · PULSOUT OutLine, 1500·········· ' pull output line low
    · GOTO Main

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-10-27 17:51
    Assuming you have a BS2p, pe, or px? The command you need is POLLWAIT 8. (See the Stamp manual). The "8" selects a mode where the Stamp sits in place and responds instantly (relatively speaking) to a target state at the input.

    delay=650
    POLLIN 0,1 ' target state is 1 on p0
    POLLOUT 10,1 ' you don't really need this, see below
    POLLMODE 2 ' enable polling
    POLLWAIT 8 ' sit here until p0->1
    PULSOUT 10, delay ' program delay
    PULSOUT 1,3750

    The latency is deterministic. There is the delay for the POLLWAIT itself (around 190 microseconds for a BS2pe, or around 130 microseconds for a BS2px), plus the delay to interpret the PULSOUTs. On a BS2px, the minimum delay to the leading edge of your second PULSOUT is about 300 microseconds (That being with delay=0)

    The POLLOUT command is not necessary, but with a 'scope it lets you investigate the latency of the POLLWAIT command.

    WT in Indiana said...
    Ohh yeah, It needs to be done soon with only the parts I have on hand


    is there a way to use the pollin in command to trigger a command set ?
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • WT in IndianaWT in Indiana Posts: 5
    edited 2005-10-27 19:17
    Wow

    Super Duper perfect. This will open up several options

    I use the basic stamp at a major engine manufacture to do small project boxes to aid in R&D.

    I've been programming BS since the BS1 came out and this just goes to prove that you never know anything and there's always someone out there to learn from

    Thanks
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-27 19:36
    And from Tracy we all learn new tricks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-10-28 17:15
    Credit goes to Chuck and Chip and the engineering staff at Parallax for including these more esoteric commands. I use POLLWAIT quite a bit, with the options that put the BS2pe to sleep to save battery power. Then events on the inputs (above all alarms and heartbeats from the real time clock chip) can activate the program flow and synchronize it with the RTC.

    The latched POLLIN states are also useful for capturing events in the background, for later processing. That makes use of scratchpad locations that store the status of the pins. Here are some snippits...
    http://www.emesys.com/BS2pe.htm#spram_specials

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