Sign in

username:

password:



Not a member?

Search basicx



Search tips

Subscribe to basicx



basicx by Keywords

Accelerometer | ADC | ADXL | Adxl20 | AVR | BasicStamp | BX-35 | BX28 | BX35 | COM3 | Compiler | Downloader | EEPROM | Electromagnet | GetADC | GP2D1 | GPS | I2C | IDE | Keypad | LCD | LCD+ | MIDI | Motors | Multitasking | Netmedia | Networking | PCB | PID | PlaySound | PWM | Relays | RTC | Servo | ShiftOut | SitePlayer | SPI | Stack | Timer | USB

Ads

Discussion Groups

Discussion Groups | BasicX | multitasking question

Discussion forum for the BasicX family of microcontroller chips.

multitasking question - Author Unknown - Mar 20 21:47:00 2001

I am a little new to the BX-24 chip and had a question about
multitasking. I am building an autonomous sumo robot for a
competition and need the sensors being read very quickly. I was
wondering if I have the tasks that I want to run simotaniously in sub
main in a do loop (as shown in the code below) is this the proper way
to use multitasking and if it would work.
Also if i call a sub program from a task will this halt multitasking?

dim stacksonar(1 to 40) as byte
dim stacklightsensors(1 to 40) as byte
dim stackbumpers(1 to 40) as byte
dim stackwhereto(1 to 40) as byte

sub main()
do
calltask "lightsensorstask", stacklightsensors
calltask "sonarstack", stacksonar
calltask "bumperstask", stackbumpers
calltask "wheretotask", stackwhereto
loop
end sub

sub sonarintask()
do
call sleep (0.0)

"statements"

loop
end sub

sub lightsensorstask()
do
call sleep (0.0)

"statements"

loop
end sub

and so on.....






(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )


Re: multitasking question - Tony Brenke - Mar 21 1:17:00 2001

do this.
calling a sub will not hals multitaskin.
Many tasks will slow thing down though.

too many and you run out of stack space.

just with the stacks here you are using 160 bytes of your 512.
can the sonor, lightsensor and bumpers run in one "sensor" task?

the code in a bx should be fast enough for that easly. dim stacksonar(1 to 40) as byte
dim stacklightsensors(1 to 40) as byte
dim stackbumpers(1 to 40) as byte
dim stackwhereto(1 to 40) as byte

sub main()
calltask "lightsensorstask", stacklightsensors
calltask "sonarstack", stacksonar
calltask "bumperstask", stackbumpers
calltask "wheretotask", stackwhereto
' you only need to call the tasks once
' the do/loop in the task will keep it going
' the main task runs also
do
call sleep (0.0)

"statements"
loop
end sub

sub sonarintask()
do
call sleep (0.0)

"statements"

loop
end sub

sub lightsensorstask()
do
call sleep (0.0)

"statements"

loop
end sub =====
Tony Brenke
North Tacoma, WA

__________________________________________________






(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: multitasking question - Author Unknown - Mar 21 22:30:00 2001

In my original code I had all the sensors being read in one big sub
program and one big do loop. This wasnt fast enough. Each sensor
will call a sub forward, back, right, or left (which control the
motors) if they detect something Will putting them into one big task
and splitting them into small subs within the task (like in the reply
message) make it fater than using one big sub program?





(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Re: multitasking question - Tony Brenke - Mar 22 0:52:00 2001

>Will putting them into one big task and splitting them into
> small subs within the task (like in the reply
> message) make it fater than using one big sub program?

no.
all tasks run on only one prossesor.
put the sensors in a tight loop for reading there value and storing it
in a varable.

then read the varable in the main program and make the choises from
there.

that way the sensors are close to real time.

there is a ballance you will have to work out.

--- wrote:
> In my original code I had all the sensors being read in one big sub
> program and one big do loop. This wasnt fast enough. Each sensor
> will call a sub forward, back, right, or left (which control the
> motors) if they detect something Will putting them into one big task
>
> and splitting them into small subs within the task (like in the reply
>
> message) make it fater than using one big sub program? > ------------------------ Yahoo! Groups Sponsor >
>

=====
Tony Brenke
North Tacoma, WA

__________________________________________________





(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: multitasking question - Author Unknown - Mar 22 7:07:00 2001

--- In basicx@y..., nick4562002@y... wrote:
> In my original code I had all the sensors being read in one big sub
> program and one big do loop. This wasnt fast enough. Each sensor
> will call a sub forward, back, right, or left (which control the
> motors) if they detect something Will putting them into one big
task
> and splitting them into small subs within the task (like in the
reply
> message) make it fater than using one big sub program?

There whould be a definitive solution. Hooking all the sensor (maybe
grouping some of them) to a sort of interrupt chip controller. This
way the processor only analizes the change instead of pulling
continuos them. This whould be a nice project for those already
skilled whid the basic-x chip.

Bye
Kai




(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )