Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp Multi-tasking — Parallax Forums

Basic Stamp Multi-tasking

Michael GarkieMichael Garkie Posts: 3
edited 2004-11-08 18:05 in BASIC Stamp
Hi,

I am new to the forum, and have been playing around with Stamps for a week or so. I have a question:

If my stamp is listening for an RS232 command with SERIN, how do I do other things, like blink LED's while it's waiting?

Is there any way to make a button command command or anything else interrupt the SERIN waiting for an incoming string?

Thanks

Mike Garkie
Garkie Digital

Comments

  • NewzedNewzed Posts: 2,503
    edited 2004-11-07 19:34
    You probably wrote something like:

    serin pin, baud, [noparse][[/noparse]data]

    Try this:

    Start:
    serin pin, baud, 1000, blink,[noparse][[/noparse]data]

    'if you get serin then do what you want

    blink:
    high led
    pause 200
    low led
    goto start

    if no serin within 1 second, program jumps to blink:, blinks led once, then goes back to serin.· The jump to blink will cost you about 200ms.· If that is too long you can shorten the blink time to 100.




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    New Combo LCD Backpack

    http://hometown.aol.com/newzed/index.html


    Post Edited (Newzed) : 11/7/2004 7:36:49 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-07 20:48
    Sid's point is that the BASIC Stamp is a single-tasking device, and SERIN will block all other activity. Thankfully -- and as Sid pointed out in his post -- the SERIN function has a timeout timer that will let you escape the SERIN if nothing arrives withing a given window.

    Beyond that, there are programming schemes that can make the BASIC Stamp (or any single-tasking controller) "appear" to be doing many things at once. The key is to setup a task-manager that handles important things through every program loop iteration, then divide the other task on each successive loop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Fast MiconFast Micon Posts: 16
    edited 2004-11-08 04:31
    Jon, would you post snippets for the task manager you mentioned?· I am currently thinking about something similar for a Stamp that has many things to take care of concurrently.

    Thanks.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-08 14:33
    The framework looks something like this:

    Main:
      '
      ' do "important" task here
      '
     
      ON state GOSUB Task_0, Task_1, Task_2 ...
      GOTO Main
     
     
    Task_0:
      '
      ' task code
      '
      IF (emergency) THEN
        GOSUB Emergency_Task
      ENDIF
      state = state + 1 // MaxStates
      RETURN
    


    As you can see, you put your important task in the top part of the main loop.· After it's done, the program will call on a task based on the value of 'state.'· Within each task subroutine, the task code is handle, then the next task is pointed to -- unless there is some problem that needs to be dealt with first.· By breaking the program into small subroutine tasks, you can make things quite flexible and efficient.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Michael GarkieMichael Garkie Posts: 3
    edited 2004-11-08 15:29
    Thanks everyone for your timely replies!

    I'll try these routines today. Also, I read a thread in the archives about character buffer chips for the stamps. The MAX3100 and a PIC with code by S. Parkis were mentioned. If I used a chip like this ahead of the stamp, could it hold incoming characters and then signal the stamp when there was someting to read by SERIN?

    Thanks,

    Mike Garkie
    Garkie Digital
  • AlWilliamsAWCAlWilliamsAWC Posts: 135
    edited 2004-11-08 15:35
    Have a look at:
    http://www.wd5gnr.com/suart.htm·-- past project of the month.

    Al Williams
    AWC
    http://www.awce.com
    ·
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2004-11-08 18:05
    Yes, the MAX3100 has a pin that indicates that their is data in but buffer. Also, if you don't want to dedicate a Stamp pin to reading that status, a quick shiftin can read the status from the data line.

    Note that the Stamp SERIN command also has a hardware flow control option. If the device that your Stamp is talking to can also do hardware flow control, the wait and response can be very tight.

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