Shop OBEX P1 Docs P2 Docs Learn Events
Flash an LED while Polling — Parallax Forums

Flash an LED while Polling

Bob@RCHBob@RCH Posts: 5
edited 2008-10-07 03:32 in BASIC Stamp
Hello All,

I'm looking for some assistance in trying to accomplish what may be quite simple but has me perplexed.· I'm polling·some Input pins on a BS2P40 and·turning a motor on or off and changing direction depending on their status.· When 2 of the pins are active, I need to flash an LED (among other things) at 1 second intervals until the condition is no longer true.· However, I need to know exactly when the condition is true or not true·so·I can not use the PAUSE command to hold the LED on or off due to·program execution stopping·during PAUSE.· I think I'll figure it out eventually but I could use a few pointers.

BTW, we're a manufacturer of Semiconductor processing tools.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-07 00:54
    You can still use a short PAUSE. Use a word counter to count the number of PAUSE 20 statements that are executed in a loop. Each time through the loop, check your two input pins to see if both are active. If not, exit the loop and GOTO the part of your code that decides what to do if only one input is on or if no inputs are on. If both are active, continue in the loop and increment the count in the word variable. When the count reaches 50, approximately one second has elapsed and you can toggle the state of the LED (and reset the count to zero).

    This allows you to check the status of the inputs, yet still keep approximate time. The time required to execute the input test and the other stuff in the loop will be a fraction of the 20ms and the 20ms (which is fairly accurate) will swamp the other statement's execution time.

    Check out the "app-note" link at www.emesystems.com for a discussion of the execution time of various Basic statements.
  • Bob@RCHBob@RCH Posts: 5
    edited 2008-10-07 00:58
    Thanks for the quick reply.· That's exactly where I was going next.· IS there any reason why you chose 20ms rather than 1 or 2? Just curious if there's a minimum time value for Pause/

    Thanks again!
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-07 01:15
    1 or 2ms is almost the same order of magnitude of time as many of the simpler PBasic statements on a BS2. If 10ms or 20ms works for you, it would really swamp any effect of the execution time of the statements surrounding the PAUSE statement.
  • Bob@RCHBob@RCH Posts: 5
    edited 2008-10-07 01:18
    Gotcha.· Thanks.· I think I'll go with 10ms.· Can you give me a hint of what issues might come up if 10 is too small a value.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2008-10-07 01:29
    I think Mike chose 20 ms because it is relatively long with respect to the execution time of BASIC Stamp instructions. A program polling loop on the Stamp is likely to take on the order of one millisecond. It is possible to write program code so that every path through the code takes the same amount of time, but that is harder to do when adding up pieces of code with lots of branches. It is easier to pace it with relatively long PAUSEs. But if your polling loop is quite simple, it would certainly be possible to shorten it and measure the execution time empirically.

    Another approach to this problem is to attach an parallel RC circuit between a free pin and Vss, and make the RC value around 1 second. Add that pin to your polling loop. PULSOUT the pin briefly high and then make it an input. When it goes low (C having discharged through R), toggle the state of the LED, and pulse the RC pin high again to charge the capacitor for the next round. It is like RCTIME, but DIY.

    Are you using the BS2p's POLLing commands, or simply a polling loop?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Bob@RCHBob@RCH Posts: 5
    edited 2008-10-07 02:26
    And one more time, thank you for the quick reply.· I know you guys are busy helping people wih much bigger problems than mine but I do have one more question;· When I eliminate the Pause command all together and just test the loop to see if "X" has reached a value of 300 for on, and 300 for off, while doing my tests in between, the LED seems to blink just fine.· Do either of you·see any problem with this?

    Thanks,· Bob

    ·
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2008-10-07 02:59
    Good deal. No problem with that at all Bob. The only problem would come if you change the program loop substantially, and then you only have to readjust the timing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Bob@RCHBob@RCH Posts: 5
    edited 2008-10-07 03:32
    Great! Thanks for everything.

    Bob

    FYI - You may not be interested but I'm attching the schematic and PCB layout we're using just so you know we're using the Stamp in a professional manner.··This board is an interface between a PLC and a·Cool Muscle Smart Motor (www.coolmuscle.com).
Sign In or Register to comment.