Question about PBASIC instructions
Archiver
Posts: 46,084
In a message dated 6/24/2004 4:26:38 PM Eastern Daylight Time,
jwilliams@p... writes:
> The BASIC Stamp is a single-threaded beast. In many applications you
> can use a task-switching strategy that looks something like this
> (pseudocode):
>
Also, where you have pauses of 10 or 20ms, this pause can be used to check
the status of something, serout instructions to a slave, set a pin high, the
list goes on and on. Pauses are dead, wasted time. Use them as much as yu can.
Sid
[noparse][[/noparse]Non-text portions of this message have been removed]
jwilliams@p... writes:
> The BASIC Stamp is a single-threaded beast. In many applications you
> can use a task-switching strategy that looks something like this
> (pseudocode):
>
Also, where you have pauses of 10 or 20ms, this pause can be used to check
the status of something, serout instructions to a slave, set a pin high, the
list goes on and on. Pauses are dead, wasted time. Use them as much as yu can.
Sid
[noparse][[/noparse]Non-text portions of this message have been removed]
Comments
I was wondering if someone can give me a hand about
some problem. I just got a croton-8 robot programmable
via PBASIC. The thing is that the design we are carrying out
considers a serie of "parallel" (ie. threads) routines/modules.
The reason for this is that I can not run the routines
sequentially. By looking at the instruction set, it does not
appear nothing like that, does anyone know how to do it?
I mean, for example, two routines X and Y
I want to be able to perform things like:
"RUN X in parallel"
"RUN Y in parallel" ... (X could be detect light,
Y could be detect obstacle, etc)
Thanks a lot in advance
John
take a pin high for 300us. You could write
high 0
pulsout 15, 0, 150
low 0
The pulsout command takes 300us - sort of like a built-in microsecond timer .
You can really do all sorts of things with PBasic - just use your
imagination.
Sid
[noparse][[/noparse]Non-text portions of this message have been removed]
randyjones@w... writes:
> did provide a nice 300 uS pulse on pin 0, but the pulsout instruction also
> has some overhead. With the above code, the duration of the high signal on
> pin 1 is now about 670 uS. Changing it to:
>
> main:
> HIGH 1
> PULSOUT 0, 1
> LOW 1
> GOTO main
>
> Gives a pin 1 high duration of about 360 uS.
>
> -Randy
> www.glitchbuster.com
>
>
>
You get an "A" for today, Randy. I was wondering if someone would catch
that. Sitting around with not much to do, so I thought I just put that out there
to see what happened. Incidentally, the specs for the BS2 say 250us per
instruction, but I've found that the BS2 seems to run a bit faster than that.
Maybe the larger the program the more time it takes.
OK - that's that. I think now I will invent something [noparse]:)[/noparse]))
Sid
[noparse][[/noparse]Non-text portions of this message have been removed]
PBasic and not 'Proton' Basic) is a single
tasking language for a single tasking platform.
The BS2 does NOT do 'tasks'. You can simulate
them, on a 50 mSec cycle-time basis, with an
external 'sMT' 'Tick' generator.
However, the BS2 is a single tasking beast
(as I keep saying). It does one thing at a time.
It does NOT support the 'parallel thread' approach
you are asking for.
This leaves the question: If you bought the
robot, and the robot uses PBasic, what made you
think you could have two tasks? Perhaps you
are in the wrong forum, and you aren't using
Parallax PBasic?
--- In basicstamps@yahoogroups.com, "atkinson_edinburgh"
<atkinson@d...> wrote:
> Hi Folks,
>
> I was wondering if someone can give me a hand about
> some problem. I just got a croton-8 robot programmable
> via PBASIC. The thing is that the design we are carrying out
> considers a serie of "parallel" (ie. threads) routines/modules.
> The reason for this is that I can not run the routines
> sequentially. By looking at the instruction set, it does not
> appear nothing like that, does anyone know how to do it?
>
> I mean, for example, two routines X and Y
> I want to be able to perform things like:
> "RUN X in parallel"
> "RUN Y in parallel" ... (X could be detect light,
> Y could be detect obstacle, etc)
>
>
> Thanks a lot in advance
>
>
> John
can use a task-switching strategy that looks something like this
(pseudocode):
Main:
DO
GOSUB Do_Something_Really_Important
ON task GOSUB Task0, Task1, Task2, Task3, ...
LOOP
Task0:
' task code here
IF (No_Problems) THEN
task = 1
ELSE
task = Problem_Solver
ENDIF
RETURN
...
By keeping all of your tasks small and in subroutines, they can be
called from the main task switcher or from another point in the program
if needed.
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: atkinson_edinburgh [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=i61by-VO_uUbFQP6fcCj7O6AIvs1WlGKuYOUv9yeBwuCrudzSL6SxXfiNOg7KsHnkAYF_LpQ7EFOB6Ykh2ZW]atkinson@d...[/url
Sent: Thursday, June 24, 2004 11:37 AM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] Question about PBASIC instructions
Hi Folks,
I was wondering if someone can give me a hand about
some problem. I just got a croton-8 robot programmable
via PBASIC. The thing is that the design we are carrying out considers
a serie of "parallel" (ie. threads) routines/modules. The reason for
this is that I can not run the routines sequentially. By looking at the
instruction set, it does not appear nothing like that, does anyone know
how to do it?
I mean, for example, two routines X and Y
I want to be able to perform things like:
"RUN X in parallel"
"RUN Y in parallel" ... (X could be detect light,
Y could be detect obstacle, etc)
Thanks a lot in advance
John
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Yahoo! Groups Links
This message has been scanned by WebShield. Please report SPAM to
abuse@p....
The 'Croton-08' is a 4-legged robot, around $450 US,
with an on-bot BS2 (OEM, it looks like, the pictures
don't give quite enough detail). It certainly is
programmed in PBasic, of course.
It controls 8 Servo-based motors to move the legs.
The nice thing about servo controlled motors is that
you can control them with a 'PULSOUT' of 1 to 2 mSec,
repeated every 20 to 50 mSecs. This lets you
control 8 motors with a single-tasking BS2.
If you need to control all 8 motors, that's 16 mSec.
you now have 4 to 34 mSec to do other stuff, before
you must 'refresh' the servos.
The BS2 is STILL single-tasking, so your single
thread will have to update the servo's, then read
a sensor and decide what to do with it, then
update the servo's again. You MUST run the
routines sequentially -- but you can implement
a state-machine that makes it 'look' like two
threads.
You are on the correct Yahoo group, by the way.
On the other hand, I've never seen the Croton-8
before -- so our help may be limited. It looks
like a really cool robot.
--- In basicstamps@yahoogroups.com, "atkinson_edinburgh"
<atkinson@d...> wrote:
> Hi Folks,
>
> I was wondering if someone can give me a hand about
> some problem. I just got a croton-8 robot programmable
> via PBASIC. The thing is that the design we are carrying out
> considers a serie of "parallel" (ie. threads) routines/modules.
> The reason for this is that I can not run the routines
> sequentially. By looking at the instruction set, it does not
> appear nothing like that, does anyone know how to do it?
>
> I mean, for example, two routines X and Y
> I want to be able to perform things like:
> "RUN X in parallel"
> "RUN Y in parallel" ... (X could be detect light,
> Y could be detect obstacle, etc)
>
>
> Thanks a lot in advance
>
>
> John
Cheers
John
--- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...> wrote:
> The BASIC Stamp is a single-threaded beast. In many applications you
> can use a task-switching strategy that looks something like this
> (pseudocode):
>
> Main:
> DO
> GOSUB Do_Something_Really_Important
> ON task GOSUB Task0, Task1, Task2, Task3, ...
> LOOP
>
> Task0:
> ' task code here
> IF (No_Problems) THEN
> task = 1
> ELSE
> task = Problem_Solver
> ENDIF
> RETURN
>
> ...
>
>
> By keeping all of your tasks small and in subroutines, they can be
> called from the main task switcher or from another point in the program
> if needed.
>
> -- Jon Williams
> -- Applications Engineer, Parallax
> -- Dallas Office
>
>
>
>
>
Original Message
> From: atkinson_edinburgh [noparse][[/noparse]mailto:atkinson@d...]
> Sent: Thursday, June 24, 2004 11:37 AM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] Question about PBASIC instructions
>
>
> Hi Folks,
>
> I was wondering if someone can give me a hand about
> some problem. I just got a croton-8 robot programmable
> via PBASIC. The thing is that the design we are carrying out considers
> a serie of "parallel" (ie. threads) routines/modules. The reason for
> this is that I can not run the routines sequentially. By looking at the
> instruction set, it does not appear nothing like that, does anyone know
> how to do it?
>
> I mean, for example, two routines X and Y
> I want to be able to perform things like:
> "RUN X in parallel"
> "RUN Y in parallel" ... (X could be detect light,
> Y could be detect obstacle, etc)
>
>
> Thanks a lot in advance
>
>
> John
>
>
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject
> and Body of the message will be ignored.
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
> This message has been scanned by WebShield. Please report SPAM to
> abuse@p...
timer .
Good idea, but don't forget the overhead of the instructions... I just
watched the output on a scope from a BS2 running:
main:
HIGH 1
LOW 1
GOTO main
...and pin 1 was high for about 150 uS. Total time through the loop looks
like about 570 uS. Adding the Pulsout instruction like this:
main:
HIGH 1
PULSOUT 0, 150
LOW 1
GOTO main
did provide a nice 300 uS pulse on pin 0, but the pulsout instruction also
has some overhead. With the above code, the duration of the high signal on
pin 1 is now about 670 uS. Changing it to:
main:
HIGH 1
PULSOUT 0, 1
LOW 1
GOTO main
Gives a pin 1 high duration of about 360 uS.
-Randy
www.glitchbuster.com
> One other thing - the shortest pause Stamp has is 1ms. Suppose you wanted
to
> take a pin high for 300us. You could write
>
> high 0
> pulsout 15, 0, 150
> low 0
>
> The pulsout command takes 300us - sort of like a built-in microsecond
timer .
>
> You can really do all sorts of things with PBasic - just use your
> imagination.
>
> Sid
will vary based on the instruction and the complexity of any parameters
provided. Tracy Allen has done the most thorough research (that I'm
aware of) on BASIC Stamp instruction timing.
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: Newzed@a... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=4DhE-Pi02RALquLBVKwWYYxT1iOuXWFX-FZUhFHVFGx_6kO7PQ-n71fP2xVrR5k-cVELgA]Newzed@a...[/url
Sent: Thursday, June 24, 2004 4:48 PM
To: basicstamps@yahoogroups.com
Subject: Re: [noparse][[/noparse]basicstamps] Question about PBASIC instructions
In a message dated 6/24/2004 5:30:36 PM Eastern Daylight Time,
randyjones@w... writes:
> did provide a nice 300 uS pulse on pin 0, but the pulsout instruction
> also has some overhead. With the above code, the duration of the high
> signal on pin 1 is now about 670 uS. Changing it to:
>
> main:
> HIGH 1
> PULSOUT 0, 1
> LOW 1
> GOTO main
>
> Gives a pin 1 high duration of about 360 uS.
>
> -Randy
> www.glitchbuster.com
>
>
>
You get an "A" for today, Randy. I was wondering if someone would catch
that. Sitting around with not much to do, so I thought I just put that
out there
to see what happened. Incidentally, the specs for the BS2 say 250us per
instruction, but I've found that the BS2 seems to run a bit faster than
that.
Maybe the larger the program the more time it takes.
OK - that's that. I think now I will invent something [noparse]:)[/noparse]))
Sid
[noparse][[/noparse]Non-text portions of this message have been removed]
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Yahoo! Groups Links
This message has been scanned by WebShield. Please report SPAM to
abuse@p....