I am guessing that you are copying you source program from another language.
You have incorrect syntax for the use of GOSUB. The Gosub command is used to jump to a label as a subroutine, in a similar way to Goto. The difference is that Return can then be used to return to the line of code after the Goto. Gosub should NOT be used if it can be avoided.
You need to change the sub NAME to NAME: which is a label.
However, use proper subroutines The name of the sub subroutine and end sub. So, in your code.
'Reads sensor values Sub readSensors DigitalFlame = ReadAD(AN2) DigitalWallFront = ((6787/(ReadAD(AN1)-3))-4)/5 DigitalWallLeft = ((6787/(ReadAD(AN0)-3))-4)/5End Sub
Note... changed in the return to end sub, then you need to remove the gosub from the calling lines.
The difference? Using GoSub cannot be optimised by the compiler. You prevent any optimisation of the generated hex file. So, use Sub - End Sub.
Also, you ADC calc.... ((6787/(ReadAD(AN1)-3))-4)/5this is horrid.
You will get the microcontroller overflows - this is where the microcontroller cannot cope with the maths and during the intermediate maths you will get incorrect results.
Case where the ADC value is 0x00. Your calc will return 1356...
Case where the ADC > 0 and ADC < 30. Your calc will overflow with values that are greater than 255 ( a byte value ).
And, the calc is very slow.
Consider using SCALE(). DigitalWallFront = Scale( ReadAD( AN1 ), 0, 255, 225, 4 ) // I am guessing the value of 225.....
You should model this range in EXCEL. Remember to use INT() to simulate the integer nature of the microcontroller. You will see the overflows and the division by zero, negative numbers... So, using Scale() will control the returned range.
Enjoy,
Evan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Attached is the. GCB file.
The Error code comes from Ln 55, Col 1
Hello Chase/Nathan
I am guessing that you are copying you source program from another language.
You have incorrect syntax for the use of GOSUB. The Gosub command is used to jump to a label as a subroutine, in a similar way to Goto. The difference is that Return can then be used to return to the line of code after the Goto. Gosub should NOT be used if it can be avoided.
So, in your code.
You need to change the
sub NAME
toNAME:
which is a label.However, use proper subroutines The name of the
sub subroutine
andend sub
. So, in your code.Note... changed in the
return
toend sub
, then you need to remove thegosub
from the calling lines.The difference? Using GoSub cannot be optimised by the compiler. You prevent any optimisation of the generated hex file. So, use Sub - End Sub.
Also, you ADC calc....
((6787/(ReadAD(AN1)-3))-4)/5
this is horrid.You will get the microcontroller overflows - this is where the microcontroller cannot cope with the maths and during the intermediate maths you will get incorrect results.
Case where the ADC value is 0x00. Your calc will return 1356...
Case where the ADC > 0 and ADC < 30. Your calc will overflow with values that are greater than 255 ( a byte value ).
And, the calc is very slow.
Consider using
SCALE()
.DigitalWallFront = Scale( ReadAD( AN1 ), 0, 255, 225, 4 ) // I am guessing the value of 225.....
You should model this range in EXCEL. Remember to use INT() to simulate the integer nature of the microcontroller. You will see the overflows and the division by zero, negative numbers... So, using
Scale()
will control the returned range.Enjoy,
Evan
and, figure this out
DigitalWallFront =[byte]Scale( ReadAD(AN1), 0, 255, 200, 4)
The line of code adapts
scale()
. Try to understand why this adaption works, and, it will be slightly faster.