It's better to post your code as text rather than as a pdf file, which takes several steps to view. Place within the forum editing tags, "[ code]" and "[ /code]" (omitting the spaces I put in to keep the forum from acting on those tags), like this:
Code:
#picaxe 14M2
setfreq m4 ; All M2 parts internal k31,
; k250, k500, m1, m2, m4, m8,m16,m32
symbol speed_control = C.0
symbol val = w0 ; word (16-bit) user variable
symbol pwmPin = B.2
b10 = 255
b12 = 155
b14 = 100
b16 = 50
b18 = 10
b20 = 0
init:
pwmout pwmdiv4, pwmPin, 24, 50
main:
readadc10 speed_control, val ; read 10-bit ADC into variable w0
if val < b10 then let b22 = b10
if val < b14 then let b22 = b12
if val < b15 then let b22 = b14
if val < b18 then let b22 = b20
end if
end if
end if
end if
debug
pwmduty pwmPin, b22 ; set pwm duty
goto main ; loop back to star
Several points. There's nothing invalid in the use of "GOTO main:", especially in a program this small, but as a recent poster said, GOTO is never needed, and often leads to problems. It's more conventional in modern basic to put everything in main: within a DO LOOP construct.
Your variables b10, b12, b14, b16, b18, b20 appear to be constants. Unless you intend for other code to change them, you should define them as such, e.g., "symbol LIMIT1 155" (if you need to define them at all).
Your series of "IF ... ENDIF" statements is confusing. It would probably be better written with a SELECT CASE statement:
Code:
select val
case < 10: b22=0
case < 50: b22=100
case < 100: b22=155
else: b22=255
endselect
(If I got that right.)
And it is best to define all your "b" variables as you have defined "val", e.g. "symbol b22=pwmVal".
Good luck, try again, test code in the PE6 simulator, and get back to us with additional questions.