parallel tasks

curtis_1966

New Member
I would like to thank everyone for your help on my last problem that I had, some great minds here. So here's my latest problem.
I have 3 tasks running(start0,start1,start3), start0 and start3 are in a loop routine now how do I stop start1 from falling into the other lines of code.

Thanks Curtis
 

westaust55

Moderator
Not sure that I fully understand your program structure from the description.

Please post your code so folks are clear on what you are doing.
The multiple tasks with M2 parts are I believe intended to be functionally separate.
Any reason why there is no Start2: label ?

From PICAXE manual 1 page 64:
sub-procedures can be shared between different tasks if required, however this is not generally recommended.
 
Last edited:

curtis_1966

New Member
oh sorry for that, my fault there. Was at work an in a rush to get out an no copy of code on me.
So start0: falls into a testit: loop and start1: just ends would fall into start2: and stop didn't seem to work it also stopped start0:. Any help would be gratefully appreciated.

(code)
start0:
for b15=1 to 60 ;Delay for PIR
pause 1000
next b15

serout TENDA,4800,($EF) ;STOP MP3
pause 500
serout TENDA,4800,($E7) ;Set MP3 Volume
pause 500

testit:
Do : loop until PIR_IN=1
Do
PIR_COUNT = PIR_COUNT + 1 * PIR_IN
loop until PIR_COUNT = 10
PIR_COUNT = 0

goto turn1


Start1:
pause 500
MovementType = 0 ;reset movement type index to first data block
LastCommand=$ff ;show no last command

Random_Word=RandomSeed ;start random number off with random seed

ReadPointer=MovementType+HeadTurnData+HeadCenter
Read ReadPointer,Temp_LSB ;get default position for servo
servo HeadTurnServo,Temp_LSB ;and setup servo with it
TurnPos=Temp_LSB ;and the software too

ReadPointer=MovementType+HeadNodData+HeadCenter
Read ReadPointer,Temp_LSB ;get default position for servo
servo HeadNodServo,Temp_LSB ;and setup servo with it
NodPos_MSB=Temp_LSB ;and the software too
NodPos_LSB=128 ;make it x.5 for round off

ReadPointer=MovementType+HeadTiltData+HeadCenter
read ReadPointer,Temp_LSB ;get default position for servo
servo HeadTiltServo,Temp_LSB ;and setup servo with it
TiltPos_MSB=Temp_LSB ;and the software too
TiltPos_LSB=128 ;make it x.5 for round off
stop

start2:
pause 2000
MovementType=0 ;yes, set the index to start of table
high EyesOutput ;and set Eyes output
Temp_LSB=7 ;and do all 7 movement types
goto main
turn1:
suspend 2
pause 500
serout TENDA,4800, (01) 'Play MP3
pause 500
servo B.2,210 'turn head
servopos B.2,210
for b16=1 to 5 'delay for mp3
pause 1000
next b16
servopos B.2,130 'turn head
pause 500
resume 2

for time = 1 to 150
pause 2000
next time

goto testit

main:
Random Random_Word ;get next random number

Temp_LSB=Random_MSB * Temp_LSB /256; ;get a random from 0 to 4 or 0 to 6
if LastCommand = Temp_LSB then start2 ;get another command if repeating the last one.

On Temp_LSB gosub LookHome,LookFarLeft,LookNearLeft,LookFarRight,LookNearRight,LookAt,NodNo

Goto start2
 

curtis_1966

New Member
okay gonna try a do:loop until PIR_IN=3 at the end of start:1. Since it will never reach 3, if any better ideas let me know please


curtis


Update: seems to work fine in the windows simulator.
 
Last edited:

westaust55

Moderator
It is unclear exactly what the program flow is that YOU want, as opposed to what the program is doing.
I do not know whether the label testit: is supposed to be part of task Start0 or not. Your words suggest maybe not.

When positing code, please use the [code] and [/code] tags to retain any indentation.

If your code does not already have indentation please consider to add in future to make the code earlier for those helping to read and see the flow.
By way of example here is your code with some formatting and moving two blocks around so I could better see what might be the program flow for each task.
Can you see how much easier it is to see the labels and what lines are loops (For...Next or Do Loop structures, etc)

Code:
start0:
   for b15=1 to 60 			;Delay for PIR
      pause 1000
   next b15

   serout TENDA,4800,($EF)	 	;STOP MP3
   pause 500
   serout TENDA,4800,($E7) 		;Set MP3 Volume
   pause 500 

testit:
   Do : loop until PIR_IN=1
   Do
      PIR_COUNT = PIR_COUNT + 1 * PIR_IN
   loop until PIR_COUNT = 10
   PIR_COUNT = 0

goto turn1 
turn1:
    suspend 2
    pause 500 
    serout TENDA,4800, (01) 'Play MP3
    pause 500 
    servo B.2,210 		'turn head
    servopos B.2,210
    for b16=1 to 5 		'delay for mp3
        pause 1000
    next b16 
    servopos B.2,130 		'turn head
    pause 500
    resume 2

    for time = 1 to 150
        pause 2000
    next time

    goto testit 

; = = = = = = = = = = = = = = = = = = = = = =

Start1:
    pause 500
    MovementType = 0			 ;reset movement type index to first data block
    LastCommand=$ff			 ;show no last command

    Random_Word=RandomSeed	 ;start random number off with random seed

    ReadPointer=MovementType+HeadTurnData+HeadCenter
    Read ReadPointer,Temp_LSB 	;get default position for servo
    servo HeadTurnServo,Temp_LSB	 ;and setup servo with it
    TurnPos=Temp_LSB 		;and the software too

    ReadPointer=MovementType+HeadNodData+HeadCenter
    Read ReadPointer,Temp_LSB 	;get default position for servo
    servo HeadNodServo,Temp_LSB	 ;and setup servo with it
    NodPos_MSB=Temp_LSB 	;and the software too
    NodPos_LSB=128 			;make it x.5 for round off

    ReadPointer=MovementType+HeadTiltData+HeadCenter
    read ReadPointer,Temp_LSB 	;get default position for servo
    servo HeadTiltServo,Temp_LSB 	;and setup servo with it
    TiltPos_MSB=Temp_LSB 		;and the software too
    TiltPos_LSB=128 			;make it x.5 for round off
    stop

; = = = = = = = = = = = = = = = = = = = = = =

start2:
    pause 2000
    MovementType=0 			;yes, set the index to start of table
    high EyesOutput			;and set Eyes output
    Temp_LSB=7 			;and do all 7 movement types
    goto main 
main:
    Random Random_Word ;get next random number

    Temp_LSB=Random_MSB * Temp_LSB /256	; ;get a random from 0 to 4 or 0 to 6
    if LastCommand = Temp_LSB then start2		 ;get another command if repeating the last one.

    On Temp_LSB gosub LookHome,LookFarLeft,LookNearLeft,LookFarRight,LookNearRight,LookAt,NodNo

    Goto start2
; = = = = = = = = = = = = = = = = = = = = = =
 
Top