Redefining Symbols in program

SMC

Member
symbol pwmmin = 30
symbol pwmmax = 215
symbol pwmdif = pwmmax - pwmmin
symbol pressure = w0
symbol startpot = w1
symbol maxpot = w2
symbol DC = w3


main:
pause 30
low 0
READADC10 0, pressure
READADC 1, startpot
READADC 2, maxpot
if w0 < 200 then goto set_zero 'this section rescales w0 to 0-255
w0 = w0 - 200
goto continue1

set_zero:
w0 = 0

continue1:
w0 = 65 * w0
w0 = w0 / 220 'adjust this down to raise max of w0 to 248
w0 = w0 + 5 'adjust this to set low end of w0

w1 = 65 * w1
w1 = w1 / 125


IF pin6 = 1 THEN usemaxpwm
rem IF pressure >= maxpot THEN usemaxpwm
IF pressure <= startpot THEN turnpwmoff
IF pressure <= 20 THEN turnpwmoff
IF maxpot <= startpot THEN turnpwmoff



DC = maxpot - startpot 'math section for DC calculation
DC = pressure - startpot * pwmdif / DC
If DC >= pwmdif THEN usemaxpwm
DC = DC + pwmmin
GOTO setpwm


usemaxpwm:
DC = pwmmax
goto setpwm


turnpwmoff:
DC = 0
goto setpwm

setpwm:
pwmout 3,62,DC
GOTO main


Answer me this please.......the above symbols pwmmin and pwmmax are defined as numbers. These numbers are used in a math section of the main program. I need to change pwmmax depending on an input. (such as)

IF pin7 = 1 THEN pwmmax150
PWMMAX150:
pwmmax = 150
goto main

I tried jumping the program to a subroutine to change pwmmax, but I get an "mistake in this line" message.
How can you change a SYMBOL's value from within the main program loop? Are the numbers defined by the symbols variables or constants? If constants- how to change into vars w/o messing up the rest?
 

hippy

Ex-Staff (retired)
As defined ...

- symbol pwmmax = 215
- symbol pwmdif = pwmmax - pwmmin

both 'pwmmax' and 'pwmdif' are constants, and therefore can't be changed programmatically. To make them chnageable they need to be defined as variables, and you need to assign them a pre-defined varaibale name ...

- symbol pwmmax = b12
- symbol pwmdif = b13

or similar. Also you will have to programatically set the value for 'pwmdif' before it is used ...

- pwmdif = pwmmax - pwmmin

or rewrite your calculations to not use pwmdif itself.

When using the symbol definitions to assign variables to 'pwmmax' and 'pwmdif' you will need to ensure that you do not use variables which conflict with their use elsewhere in your code, and should be byte or word variables according upon the range of values they need to hold. In this case byte variables should be suitable.
 

SMC

Member
Thanks Hippy- that's what I thought!
Now- How can make this happen below?

IF pin7 = 1 THEN gosub pwm215

pwm215:
pwmmax = 215
return

Apparently you can't IF-THEN-GOSUB....
 

Technical

Technical Support
Staff member
Technically:

IF pin7 = 1 THEN call_pwm215
return_point:

[next bit of code]

call_pwm215:
gosub pwm215
goto return_point

pwm215:
pwmmax = 215
return

however this is better (no gosub required):


IF pin7 = 1 THEN call_pwm215
return_point:

[next code]

call_pwm215:
pwmmax = 215
goto return_point


 
 

Technical

Technical Support
Staff member
Not really, return can <b>only </b> be used with gosub. So it is

gosub...return
or
goto..goto

(not goto...return)

An if...then statement is a 'conditional goto' not a 'conditional gosub'
 
Top