Shop OBEX P1 Docs P2 Docs Learn Events
Listen to BUTTON and SERIN at same time? — Parallax Forums

Listen to BUTTON and SERIN at same time?

J.WeJ.We Posts: 15
edited 2005-08-03 14:13 in BASIC Stamp
I'm trying to get my BSsx to listen to a BUTTON and Serial command SERIN·at the same time?·They are off course on·different·I/Os and they work fine separate. My coding experience is·limited and this is the first time I use BS, please, is there anyone who can give me some advice on how to code this?
·
I can send serial commands from pc via BS to control a step motor and I want to get my BS to listen to the BUTTON at the same time! I'm trying to get around this problem but the commands SERIN and BUTTON seems to get stuck "in their own listening" until something happens only on their pin! What can I do to make the BS to listen to both of them? Can I maybe set some priority on them?
·
Thanks in advance!
//jw

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-02 14:28
    The BASIC Stamp does not have a background serial buffer so you can't do two things at once. What you could do is add a timeout to your SERIN so that if nothing comes along you can go check your button.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-08-02 14:30
    Hello,

    ·· The BASIC Stamp is a single-thread device...You can only do one thing at a time.· You could, however, monitor the serial port for a short time using a time-out, then monitor the button by reading the state of the input pin within a loop.· This might work, depending on baud rate, how often the button needs to be check, etc.· It would work better if you use a pulse-stretcher, such as a 555 timer on the button input too.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • J.WeJ.We Posts: 15
    edited 2005-08-03 09:07
    Thank you·Chris and·Jon·for fast replies!
    Ok, I think the time-out will solve some of my problems.. But there isn’t any time-out on the BUTTON. So, one way to solve this is to have an extern buffer? Do you know any projects who have tried this? Any recommendations or other advises?
    ·
    Chris, can you explain more what you mean: "It would work better if you use a pulse-stretcher, such as a 555 timer on the button input too. "·


    Many thanks!
    Regards//jw
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-03 09:12
    You don't have to sit in a BUTTON command, you can simply scan an input (create a subroutine that will monitor for a specific amount of time before leaving) and then go back go checking your serial input.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-08-03 14:13
    J.We said...(trimmed)
    Thank you·Chris and·Jon·for fast replies!
    Chris, can you explain more what you mean: "It would work better if you use a pulse-stretcher, such as a 555 timer on the button input too. "·
    Hello,

    ·· What I meant was, watch the input(s) using the IN0, IN1 or for multiple inputs INA, etc.· Then within the loop also do your SERIN routine with a timeout.· Depending on how much time you spend watching the serial port, you may need to stretch your input pulse, but the easier solution is to just cut the time you spend waiting for SERIN, although I wasn't sure how fast/often you have data coming in.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.