why does one work but the other dosnt

i have 2 peices of code for a remote and servo The only difference i can see is the labels and variables used, but only the first one works.

Code:
init:  

servo b.3, 80 ;set the initial servo position @  position 80

arm:

irin b.2,b0
debug
if b0=16 then arm_up
if b0=17 then arm_down
goto arm

arm_up:

servopos b.3,180 ;change the servos position without reseting the timer
pause 500
goto arm

arm_down:
servopos b.3,80
pause 500
goto arm

Code:
start3:

servo b.3, 80 ;set the initial servo position @  position 80

arm1:

irin b.2,b4
debug
if b4>=16 then up
if b4<17 then down
goto arm1

up:
servopos b.3, 180 ;change the servos position without reseting the timer
pause 500
goto arm1

down:
servopos b.3,80
pause 500
goto arm1
 

inglewoodpete

Senior Member
Yes, look at your code closely to determine what will happen when B4 = 16. Compare that result with what is actually happening and what you want to happen.
 

hippy

Ex-Staff (retired)
On a PICAXE-M2 chip "StartN" labels indicate the start of separate tasks. So a program with "StartN" labels will be multi-tasking while those without will not be.
 
code #2 was an a subsystem extract from another code
thanks Pete and Allan for pointing out the if b4 difference
and thank you hippy, after replacing start3 with main, code #2 now works on it's own.
 
but when i replace main with start3 and put it back into the main code, it doesn't work
Code:
#Terminal 4800

Symbol spacesLeft  = b0
Symbol spacesShown = b1

Symbol entryBeam   = b2
Symbol exitBeam    = b3

Symbol ENTRY_ADC   = B.4
Symbol EXIT_ADC    = C.4

Symbol BROKEN      = 10

; Display routine

Start0:
  serout B.1,N2400,(254,1)
    pause 30
  
  
  spacesLeft = 4
  Pause 500
  SerTxd( CR, LF )
  SerTxd( "Starting...", CR, LF )
  Do
    spacesShown = spacesLeft
    If spacesShown = 0 Then
      SerTxd( "Full - No spaces left", CR, LF )
    Else
      SerTxd( "Spaces Left = ", #spacesShown, CR, LF )
      serout B.1,N2400,(254,128)   ; move to start of first line
   serout B.1,N2400,("places availible")  ; output text
   
   serout b.1, n2400, ( 254, 192 ) 'second line
  serout b.1, N2400, (#spacesshown)
    
    
    End If
    Do : Loop Until spacesShown <> spacesLeft
  Loop

; Handle the entry beam

Start1:
  Do
    Do : ReadAdc ENTRY_ADC, entryBeam : Loop Until entryBeam <= BROKEN
    Do : ReadAdc ENTRY_ADC, entryBeam : Loop While entryBeam <= BROKEN
    spacesLeft = spacesLeft - 1 
  
  if spacesleft = 0 then 
  serout B.1,N2400,(254,1)
  serout b.1, n2400, ( 254, 128 ) 'second line
  serout b.1, n2400, ( "park is full " )
  elseif spacesleft > 0 then goto Start1
  
  
 End If
    'Do : Loop Until spacesShown <> spacesLeft
  
  Loop

; Handle the exit beam

Start2:
  Do
    Do : ReadAdc EXIT_ADC, exitBeam : Loop Until exitBeam <= BROKEN
    Do : ReadAdc EXIT_ADC, exitBeam : Loop While exitBeam <= BROKEN
       
    spacesLeft = spacesLeft + 1 Max 4
  
  Loop






start3:  

servo b.3, 80 ;set the initial servo position @  position 80

arm1:

irin b.2,b4
debug
if b4=16 then goto up
if b4=17 then down
goto arm1

up:

servopos b.3,180 ;change the servos position without reseting the timer
pause 500
goto arm1

down:
servopos b.3,80
pause 500
goto arm1
 

hippy

Ex-Staff (retired)
IRIN is a blocking command so it is hard to tell exactly what is happening which makes it work in one case but not in another. What happens if you use the code in a multi-tasking program but only handling IRIN and the servo ...

Code:
start0:
do
loop

start3:  

servo b.3, 80 ;set the initial servo position @  position 80

arm1:

irin b.2,b4
debug
if b4=16 then goto up
if b4=17 then down
goto arm1

up:

servopos b.3,180 ;change the servos position without reseting the timer
pause 500
goto arm1

down:
servopos b.3,80
pause 500
goto arm1
 
IRIN is a blocking command so it is hard to tell exactly what is happening which makes it work in one case but not in another. What happens if you use the code in a multi-tasking program but only handling IRIN and the servo ...

16 makes it move about 20 degrees clockwise before returning. 17 makes it move about 180 degrees clockwise before returning
 

hippy

Ex-Staff (retired)
There should be no "returning"; the code in post #7 should simply move from one position to another depending on which of the two keys are pressed. I would guess the IRIN is affecting things.

You could try the following, which might improve things; replace the IRIN with ...

Code:
WaitForIr:
  Pause 40
  If pinB.2 = 0 Then
    IrIn [100,WaitForIr], B.2, b4
  End If
 
i don't think i did i right...
Code:
start0:
do
loop

start3:  

servo b.3, 80 ;set the initial servo position @  position 80

arm1:

WaitForIr:
  Pause 40
  If pinB.2 = 0 Then
    IrIn [100,WaitForIr], B.2, b4
    debug
  End If
if b4=16 then goto up
if b4=17 then down
goto arm1

up:

servopos b.3,180 ;change the servos position without reseting the timer
pause 500
goto arm1

down:
servopos b.3,80
pause 500
goto arm1
 
Top