Compiler Error

Pat13

Senior Member
Am trying to use multitasking on 18M2 but keep getting compiler error "start label must be at start of program".
i have seen other examples of multitasking code that does not have start0 at the beginning. I have moved the SYMBOL part of code into the START sections, but it does not run START0 and START1 simultaneously. In fact, start1 doesn't run.

Code:
#Picaxe 18M2
'Witch Prop

symbol PIR= B.7      `PIR sensor
symbol TENDA=B.3 `Tenda RXD  `
symbol Debounce=b8
symbol BAUD=T4800
symbol Wait_If_Busy=pinB.1 `Tenda Busy Line
let dirsc=%11000001
let pinsc=%00000000
let w0 = time
symbol sequence =w0
random w1
pause w2

Init:                'Staring point to setup all inputs, outputs and set variables
 
            serout TENDA,BAUD, ($EF);       'STOP MP3 module 
            pause 5000
            serout TENDA,BAUD, ($E8)        `set Tenda Volume
            pause 60000
            
                                ;

 Start0:           
            Do
            serout TENDA, Baud, ($F2,01)     `play Track 1, Folder 2
		pause 1000       
		readadc PIR,debounce 
		if debounce>50 then Open_Chant 'if triggered go to opening chant
		gosub Test_Busy_Line          'check busy line before doing anything else
		loop while debounce < 50        'if not triggered sit in this loop
	
Test_Busy_Line:
            Do
            if Wait_If_Busy = 1 then exit
            Loop
            return
	
		
Open_chant:
		Gosub Clear_Debounce		'clear Trigger
		 Pause 1000
		 serout TENDA,BAUD,($F2,02)		'play cackle,Track 2, folder 2
		 do
		 if Wait_If_Busy=1 then gosub Spellcast 'wait unti track ends  
		 loop
		 
Spellcast:										
            serout TENDA,BAUD,($00) 'random selection of verses
		pause 1000
            do
            if Wait_If_Busy=1 then goto start0'watch for spellcast to end and return to start0
            loop
            
		
Clear_Debounce:
		Debounce=0
		return
	                              
		
Start1:


		do
		random sequence
		let pinsc =sequence
		random w1
		w2=w1//1000 + 4000
		pause w2
		random sequence
		let pinsc =sequence
		random w1
		w2=w1//1000 + 4000
		pause w2
		pinsc=0
		pause 500
		loop
 

westaust55

Moderator
When using the M2 parts for multitasking, all of your program code must be within the 4 (for 08M2 and 18M2) or 8 (others) program tasks/blocks.
As such by default, the label Start0: when not defined will be before the first line of program code.
As your code is currently written the initialization section starting at Init: and several other lines before the init: label are not within any of the valid program tasks/blocks.

try this code:
Code:
#Picaxe 18M2
'Witch Prop

symbol PIR= B.7      `PIR sensor
symbol TENDA=B.3 `Tenda RXD  `
symbol Debounce=b8
symbol BAUD=T4800
symbol Wait_If_Busy=pinB.1 `Tenda Busy Line


Start0:


	let dirsc=%11000001
	let pinsc=%00000000
	let w0 = time
	symbol sequence =w0
	random w1
	pause w2

Init0:                'Staring point to setup all inputs, outputs and set variables
 
            serout TENDA,BAUD, ($EF);       'STOP MP3 module 
            pause 5000
            serout TENDA,BAUD, ($E8)        `set Tenda Volume
            pause 60000
            
                                ;
Main0:
           
            Do
                serout TENDA, Baud, ($F2,01)     `play Track 1, Folder 2
		pause 1000       
		readadc PIR,debounce 
		if debounce>50 then Open_Chant 'if triggered go to opening chant
		gosub Test_Busy_Line          'check busy line before doing anything else
            loop while debounce < 50        'if not triggered sit in this loop
	
Test_Busy_Line:
            Do
              if Wait_If_Busy = 1 then exit
            Loop
            return
	
		
Open_chant:
            Gosub Clear_Debounce		'clear Trigger
            Pause 1000
            serout TENDA,BAUD,($F2,02)		'play cackle,Track 2, folder 2
            do
               if Wait_If_Busy=1 then gosub Spellcast 'wait unti track ends  
            loop
		 
Spellcast:										
            serout TENDA,BAUD,($00) 'random selection of verses
            pause 1000
            do
                if Wait_If_Busy=1 then goto start0'watch for spellcast to end and return to start0
            loop
            
		
Clear_Debounce:
            Debounce=0
            return
	                              
		
Start1:


            do
                random sequence
                let pinsc =sequence
                random w1
                w2=w1//1000 + 4000
                pause w2
                random sequence
                let pinsc =sequence
                random w1
                w2=w1//1000 + 4000
		pause w2
		pinsc=0
		pause 500
            loop
 
Last edited:

westaust55

Moderator
You may also find it useful to read PICAXE manual 1 page 61 onwards and in particular page 63
under the sub heading: Multi task mode labels

The start (“top”) of the program is always task 0. This is the first task that is
started when the chip is reset. If desired an optional ‘start0:’ label may be used,
but this is also implied by default if not used. If used, ‘start0:’ must always be on
the very first line of program code.
 
Last edited:
Top