Discussion forum for the BasicX family of microcontroller chips.
|
Think of a task as a subroutine that you never want to exit. Tasks are scheduled by the amount of time you allow the to sleep. The longer you allow a Task sleep the less it runs, when compared to tasks with shorter sleep times. Dim Stack1(1 to 30) as Byte 'Set aside some RAM for our Tasks to run with Dim Stack2(1 to 30) as Byte Dim Stack3(1 to 30) as Byte Sub Main() 'PlaySub is now a task and will continue to run until your code in 'PlaySub allows it to exit or power is removed from the chip. CallTask"PlaySub",Stack1 'EatSub is now a task that will only run once. CallTask"EatSub",Stack2 'WorkSub is now a task and will continue to run until your code in 'WorkSub allows it to exit or power is removed from the chip. CallTask"WorkSub",Stack3 Do Call Sleep(1) Loop End Sub Sub PlaySub() Do Call PutPin(26,0) Call Sleep(100) Call PutPin(26,1) Call Sleep(100) Loop End Sub Sub EatSub() Call PutPin(12,0) Call Sleep(100) Call PutPin(12,1) Call Sleep(100) End Sub Sub WorkSub() Do Call PutPin(25,0) Call Sleep(100) Call PutPin(25,1) Call Sleep(100) Loop End Sub Have fun, Chris Harriman Here I will yet again display my almost limitless ignorance. How ,exactly, would one go about multitasking? Is there code that schedules the tasks, or do you just write them as a series of Do-Loops with sleep commands? Suppose you had three subroutines that you wanted run multi-tasked: PlaySub, EatSub, and WorkSub. Do you simply write it as: Main() Do Playsub code sleep() Loop Do EatSub code sleep() Loop Do WorkSub code Sleep() Loop End Or, do you have some sort of scheduler code that decides when and how long to run each task: Main() Mysterious task scheduler code PlaySub EatSub WorkSub End Thanks for the help. Peter [Attachments have been removed from this message] --------------------------- ONElist Sponsor ---------------------------- Independent contractors: Find your next project gig through JobSwarm! You can even make $$$ by referring friends. <a href=" http://clickme.onelist.com/ad/jobswarm2 ">Click Here</a ------------------------------------------------------------------------ |
|
Look at the example in the operating system reference manual. Essentially you write the task as a procedure with no parameters. To start it you use CallTask rather than Call. The task needs a stack of its own so the syntax is CallTask task(), stack where the stack is an array of sufficient size. Use a Dim statement to create it in the calling task. The size of the stack depends. Start with maybe 50 bytes. Try decreasing it if it doesn't crash or increasing it if it does. With the limited ram storage on the BX24 you are not going to be able to have more than a few tasks. The BX01 allows a lot more tasks. You need a Sleep or Delay or one of several other conditions like accessing a queue to switch tasks. I'm under the impression that all tasks have equal priority. mwf -----Original Message----- From: Dr. Peter Charles [SMTP:] Sent: Tuesday, November 23, 1999 3:14 PM To: Subject: [BasicX] Multitasking Question Here I will yet again display my almost limitless ignorance. How ,exactly, would one go about multitasking? Is there code that schedules the tasks, or do you just write them as a series of Do-Loops with sleep commands? Suppose you had three subroutines that you wanted run multi-tasked: PlaySub, EatSub, and WorkSub. Do you simply write it as: Main() Do Playsub code sleep() Loop Do EatSub code sleep() Loop Do WorkSub code Sleep() Loop End Or, do you have some sort of scheduler code that decides when and how long to run each task: Main() Mysterious task scheduler code PlaySub EatSub WorkSub End Thanks for the help. Peter [Attachments have been removed from this message] --------------------------- ONElist Sponsor ---------------------------- Independent contractors: Find your next project gig through JobSwarm! You can even make $$$ by referring friends. <a href=" http://clickme.onelist.com/ad/jobswarm2 ">Click Here</a ------------------------------------------------------------------------ |
|
The stack size would need to be bigger if any variables are declared. Also, EatSub doesn't need the sleep at the end. mwf -----Original Message----- From: Chris Harriman [SMTP:] Sent: Tuesday, November 23, 1999 12:50 PM To: ' Subject: RE: [BasicX] Multitasking Question From: Chris Harriman < Think of a task as a subroutine that you never want to exit. Tasks are scheduled by the amount of time you allow the to sleep. The longer you allow a Task sleep the less it runs, when compared to tasks with shorter sleep times. Dim Stack1(1 to 30) as Byte 'Set aside some RAM for our Tasks to run with Dim Stack2(1 to 30) as Byte Dim Stack3(1 to 30) as Byte Sub Main() 'PlaySub is now a task and will continue to run until your code in 'PlaySub allows it to exit or power is removed from the chip. CallTask"PlaySub",Stack1 'EatSub is now a task that will only run once. CallTask"EatSub",Stack2 'WorkSub is now a task and will continue to run until your code in 'WorkSub allows it to exit or power is removed from the chip. CallTask"WorkSub",Stack3 Do Call Sleep(1) Loop End Sub Sub PlaySub() Do Call PutPin(26,0) Call Sleep(100) Call PutPin(26,1) Call Sleep(100) Loop End Sub Sub EatSub() Call PutPin(12,0) Call Sleep(100) Call PutPin(12,1) Call Sleep(100) End Sub Sub WorkSub() Do Call PutPin(25,0) Call Sleep(100) Call PutPin(25,1) Call Sleep(100) Loop End Sub Have fun, Chris Harriman Here I will yet again display my almost limitless ignorance. How ,exactly, would one go about multitasking? Is there code that schedules the tasks, or do you just write them as a series of Do-Loops with sleep commands? Suppose you had three subroutines that you wanted run multi-tasked: PlaySub, EatSub, and WorkSub. Do you simply write it as: Main() Do Playsub code sleep() Loop Do EatSub code sleep() Loop Do WorkSub code Sleep() Loop End Or, do you have some sort of scheduler code that decides when and how long to run each task: Main() Mysterious task scheduler code PlaySub EatSub WorkSub End Thanks for the help. Peter [Attachments have been removed from this message] --------------------------- ONElist Sponsor ---------------------------- Independent contractors: Find your next project gig through JobSwarm! You can even make $$$ by referring friends. <a href=" http://clickme.onelist.com/ad/jobswarm2 ">Click Here</a ------------------------------------------------------------------------ --------------------------- ONElist Sponsor ---------------------------- Independent contractors: Find your next project gig through JobSwarm! You can even make $$$ by referring friends. <a href=" http://clickme.onelist.com/ad/jobswarm2 ">Click Here</a ------------------------------------------------------------------------ |
|
> From: Mike Fellinger <> > > The stack size would need to be bigger if any variables > are declared. [...] This is generally true for local variables. Module-level variables, on the other hand, don't take up stack space per se, although of course they reduce the RAM available for task stacks. (Module-level variables appear outside any subprogram, and are the equivalent of "static" variables in C.) -- Frank Manning -- NetMedia, Inc. |
|
That's what I meant to say. mwf -----Original Message----- From: Frank Manning [SMTP:] Sent: Tuesday, November 23, 1999 1:01 PM To: Subject: Re: [BasicX] Multitasking Question From: "Frank Manning" <> > From: Mike Fellinger <> > > The stack size would need to be bigger if any variables > are declared. [...] This is generally true for local variables. Module-level variables, on the other hand, don't take up stack space per se, although of course they reduce the RAM available for task stacks. (Module-level variables appear outside any subprogram, and are the equivalent of "static" variables in C.) -- Frank Manning -- NetMedia, Inc. --------------------------- ONElist Sponsor ---------------------------- Thinking about putting your business on the Web? MindSpring Biz has helped over 100,000 businesses get their .com. Join MindSpring Biz and save $50! <a href=" http://clickme.onelist.com/ad/mindspring4 ">Click Here</a ------------------------------------------------------------------------ |
|
Here I will yet again display my almost limitless ignorance. How ,exactly, would one go about multitasking? Is there code that schedules the tasks, or do you just write them as a series of Do-Loops with sleep commands? Suppose you had three subroutines that you wanted run multi-tasked: PlaySub, EatSub, and WorkSub. Do you simply write it as: Main() Do Playsub code sleep() Loop Do EatSub code sleep() Loop Do WorkSub code Sleep() Loop End Or, do you have some sort of scheduler code that decides when and how long to run each task: Main() Mysterious task scheduler code PlaySub EatSub WorkSub End Thanks for the help. Peter |
|
|
|
Hi Guys, Ok, quick little question. What I want to know is say I have a several tasks running at the same time, and then I want to move a servo, so I use pulseout. now, when I do that all multitasking will halt while the pulseout command is running, correct? After the pulseout command is done running, will multitasking resume automatically, or will I have to call each task again? Is there another way to run a servo, one that allows for multitasking? Thanks Cameron |
|
|
|
>Hi Guys, > >Ok, quick little question. What I want to know is say I have a >several tasks running at the same time, and then I want to move a >servo, so I use pulseout. now, when I do that all multitasking will >halt while the pulseout command is running, correct? After the >pulseout command is done running, will multitasking resume >automatically, or will I have to call each task again? > >Is there another way to run a servo, one that allows for multitasking? You basically described it there. Set up a task that does the pulseout, give it an 18-20 ms sleep at the end of the task. The BX will run the task every 18-20 ms, pulse the servo to the correct location, and do other tasks in the meantime. -- -- Tom Igoe |