The documentation does not cover setting up local and global variables. From reading various forum posts I deduce…
1 Global variables are set up in the VARS table. These can be used in every (sub) program. Values are transferred between (sub)programs, although a later subprogram may over-write the value allocated by an earlier (sub) program
2 Local variable can only be used in a single (sub)program. It is not clear how a local variable is defined. Is it defined just by including its name in a statement? Name can be any alpha-numeric combination - but not a global variable name.
Is the above correct? Are there any other rules that apply.
Thanks
Global Vars: Your writeup is accurate, global vars can be used in any program on a given controller as you state. They are shown in blue at Tab1 once you send and then reload the program. Notice at Tab4 you can hit the INS key or right click to see the global point definition.
Local Variables: Again correct, you can create them on the fly in your programming. They are visible only in the program they are created in and they will show up as grey color at Tab2 to highlight the difference from global vars.
Note to Temco Team: Global vars are supposed to be system wide variables for use in ANY controller in the system with automatic background updating. My test just now at Tab3 in a remote controller shows this is not working.
Further question on local variables…
Also referencing post “Replacing Time Parameter with a Variable” May 2023
Is there any way to set a range/value for local variables? Eg How do I set a local variable to be a time which is itself a mathematical function of say an input temperature? I have the idea to vary HW recirculation pump (OUT1) on/off cycle to (roughly) compensate for extra heat loss during cold weather.
So (roughly),
10 ON_TIME = 0:05 (5 min)
20 OFF_TIME = (40 - OAT)/4 (where OAT is in degC, not negative)
30 IF TIME-OFF (OUT1) > OFF_TIME THEN START OUT1
40 IF TIME-ON (OUT1) > ON_TIME THEN STOP OUT1
With a global variable I can configure the variable OFF_TIME with a time or minute range.
Is it possible to use a local variable in the same way?? Eg does a local variable default to any range??
I’ll suggest a PID for this application. You’ll set up your usual setpoint and feedback temp sensor in PID1 for example. Where var1 and 2 are in the units of TIME, not the other ranges like hours, minutes, seconds. You might have to scale the formula in line 10 to get the correct results in VAR1, I am not sure exactly how this would evaluate but its easy to debug by manually toggling the setpoint up and down.
10 VAR1 = PID1 X 0:05:00 <On time for the output
20 VAR2 = 0:05:00 - VAR1 <Off time for the outpu
30 IF TIME-ON( OUT1 ) > VAR1 THEN STOP OUT1
40 IF TIME-OFF( OUT1 ) > VAR2 THEN START OUT1
Thanks Maurice, I appreciate your assistance, but…
I could not use a PID for the situation I described - there is no process variable.
My question was not about the application per se, but whether it is possible/allowed (& if so, what syntax rules apply) to mix different data formats and perform arithmetic operations with different kinds of data. In particular, when using local variables, given there is no obvious way to define Value/Units for local variables
Let me ask about some other examples:
-
Can I define a LOCAL variable as a time? - eg
20 DELAY1 = 0:00:10 (10sec)
-
Can I perform arithmetic on times? eg
30 DELAY2 = DELAY1 * 2 (20 sec)
-
Can I use (say) an AI defined in % as a factor to perform arithmetic on a time value? eg
40 DELAY 3 = DELAY2 * IN3
-
Can I use a temperature input value (say IN4 reading 25 degC) directly as a time (say 25 sec)?
eg 50 TIME-ON (OUT3) > IN4
-
Is there any way to convert an input with defined range etc into a “bare” (dimension-less) number? eg, convert IN4 (25degC) to the number 25 without it being degC? This might be a precursor to changing between different number formats.
Further…
Would you please explain the user-difference between global variable ranges 46-49 (secs, mins, hours, days) and 50 (time)?
-
Can I define a LOCAL variable as a time? - eg
20 DELAY1 = 0:00:10 (10sec)
Sure, give it a try, in order to see a local variable use a dummy line
VAR1 = DELAY1 < where delay1 is your local variable, once you have the program debugged you can delete the global variables. But why not just use the global variables, that way you can put them on displays, trend logs and so on.
-
Can I perform arithmetic on times? eg
30 DELAY2 = DELAY1 * 2 (20 sec)
Same as question1, give it a try and use globals to debug.
- Can I use (say) an AI defined in % as a factor to perform arithmetic on a time value? eg
40 DELAY 3 = DELAY2 * IN3
Same as question1 and 2, yes you can. Use a temporary global variable to debug it.
- Can I use a temperature input value (say IN4 reading 25 degC) directly as a time (say 25 sec)?
eg 50 TIME-ON (OUT3) > IN4
You have variables, global and local, using mixed units of time, temperature, percent. Just give it a try and if its not exactly what you expected then use a scaling factor to massage it where you need it.
- Is there any way to convert an input with defined range etc into a “bare” (dimension-less) number? eg, convert IN4 (25degC) to the number 25 without it being degC? This might be a precursor to changing between different number formats.
Yes, use the ‘0’ range which is unused and unitless.
VAR1 = IN1 < where VAR1 has the range set to ‘0’ (unused)
Further…
Would you please explain the user-difference between global variable ranges 46-49 (secs, mins, hours, days) and 50 (time)?
Ranges 46 thru 49 just show text for the units, the values are ints.
Range 50 is really TIME, as in hours, minutes and seconds. You can do true math on the time as in
IF+ TIME > 00:00:00 then do something at midnight.
IF TIME-ON( OUT1 ) > 0:0:010 THEN STOP OUT1 < pulse out1 for ten seconds.
For the most part you should be using range 50 for any kind of calculations based on time.
Thanks.
To explain, the reason I am using local variables is that I was/am worried I might not have enough global variables available.
I had originally thought to define all the fixed parameters (eg thresholds, time intervals etc) in a single program to make it easy to find/edit them. Since they needed to be in at least 2 programs (1 for definition, 1 or more for application) they needed to be Global variables. The full list ended up at about 60 - ie about half of the limit.
So I now have a mix of local and global.