8 Control Basic Programming

 
 
Control Basic is the language used in the T3000 Building Automation System to implement the user defined logic of the controllers. These Control Basic programs live and run in the controllers to manage the environment in the building. The basic language has been around a long time so it may sound a bit 'dated' to be using this but its easy for newcomers to learn and there are many extensions on the root language to make the programming of controls applications easy. The programs read like a sequence of operations, a couple simple examples follow:
 
  Here's a quick program to turn a fan on and off based on a schedule:
  IF SCHEDULE1 THEN START FAN101 ELSE STOP FAN101
 
  And here's a simple program to open an on/off type valve to heat a room for example.
  IF TEMP101 < SETPOINT THEN OPEN VALVE101
  IF TEMP101 > SETPOINT + 0.5 THEN CLOSE VALVE101
 
If you have a modulating valve things are also easy using the built in PID objects:
VALVE101 = PID1
 
 
The English like structure makes it easy for non programmers to follow along and debug. The following chapter describes the Control Basic language along with some examples.
 
 
8.1     THE CONTROL BASIC EDITOR
 
To get to the program editor, hit the Hot-Key combination ALT-P, or maneuver in the menu system to CONTROL, PROGRAMS and the table of programs appears as shown below:
 
 
This table lists all the programs in a particular T3000 panel, the size of each program, and a 20 and 8 character description of each program, similar to the naming conventions of INPUTS and OUTPUTS. To see a particular program, use the arrow keys to maneuver the cursor onto one of the records, and press the “INS” key. A full screen editor should pop- up and depending on what is in the particular program, you should see a listing of that program, or a blank screen if there is no example file loaded.
 
To enter a line, type a line number followed by a simple “Statement” as shown:
 
10 START OUT1
 
Program lines are checked for errors when the “F2" command is given to send the current program. The editor screen has a Help Bar along the top and bottom row of the screen to remind you of the special function keys. When you hit F2, the current program is checked for errors. If the check was successful, the T3000 will begin executing the current program. If errors are found, messages will appear in the Error Window at the bottom of the screen, and the T3000 continues executing whatever program was last successfully sent.
 
Cursor movement within the editor is accomplished using the arrow keys on the key pad. If the program is longer than a single screen, the program will scroll in the editor window.
 
The special function keys which are active during the editing of basic programs are as follows:
 
“Ins”
The Insert key which causes a pop- up window to appear showing detailed information
 
 
on any INPUT, OUTPUT or VARABLE in the program. This is very useful
 
 
 for debugging programs. The pop-up window can be used to toggle the item
 
 
On or Off, or to manually set the outdoor air temperature to 35 Deg C for example
 
 
 
 
 
 
 
“Del”
The Delete key deletes the character at the current cursor position.
 
 
 
 
“End”
The End key moves the cursor to the end of the line in which it is in.
 
 
 
 
“Esc”
Exits the current editing session, prompting you to send the program if changes
 
 
have been made.
 
 
 
 
“PgUp”
The PageUp keystroke scrolls the editor window one screen upwards.
 
 
 
 
“PgDn”
The PageDown keystroke scrolls the editor window one screen downwards.
 
 
 
 
CTRL-L
Highlights the current line for copying or deleting.
 
 
 
 
CTRL-U
Un-selects the currently selected block.
 
 
 
 
CTRL-D
Deletes the currently selected block.
 
 
 
 
CTRL-Y
Deletes a line at the current cursor position, regardless of whether the line is
 
 
highlighted or not.
 
 
 
 
CTRL-O
Undoes the last block or line delete.
 
 
 
 
CTRL-C
Copies the currently highlighted block.
 
 
 
 
CTRL-F
Searches the current program for a specified string. The default search string is
 
 
taken from the current cursor position, or a new one can be typed in by the user.
 
 
 
 
CTRL-N
Searches for the next occurrence of the same string previously searched for the
 
 
FIND command (CTRL-F).
 
 
 
 
CTRL-R
Searches for all occurrences of a specified string and re places them with a second
 
 
string. The replace command does not prompt on each substitution. The
 
 
default search string is taken from the current cursor position, but a new one
 
 
can be typed in by the user.
 
 
 
 
CTRL-E
Re-numbers the entire program in increments of 10. Use this command to
 
 
make space between two lines for a new line.
 
 
 
 
F2
Checks the current program for errors and sends it to be executed if there are
 
 
no errors. If there are errors, the old program continues executing (if there was
 
 
one) and the user is able to continue editing.
 
 
 
 
F3
Clears the current editor buffer. If there was a program executing in the T3000,
 
 
that program is cleared as well. The user is prompted before al lowing the cur-
 
 
rent program to be cleared.
 
 
 
 
F4
Prints the current program on the printer.
 
 
 
 
F5
Loads a BASIC file from the hard disk. Works in conjunction with the F6 command
 
 
 to allow the user to transfer Basic programs from old projects, other panels ,
 
 
and different versions by using the Save and Load commands. Basic files
 
 
are saved in text format with the .BAS ex tension. The directory used by the file
 
 
Operations is determined in the CONFIGURATION, SETUP, FILEPATH screen.
 
 
 
 
F6
The Save command allows the user to save Basic files in a text format on the
 
 
hard disk. Operates in conjunction with the LOAD command above.
 
 
 
 
 
10.2     CONTROL BASIC EXAMPLE
 
Control Basic program as used by the T3000 system is essentially the same as any other Basic program, a sample of which is shown below:
 
10 REM *** START / STOP ***
 
20  DA LARM AHU7- FRZ , 60 , AHU7 FREEZE STAT ALARM 30 DA LARM AHU7- FS , 300 , AHU7 FIL TER PRESS HIGH
 
40 REM **** DE CIDE IF HEAT ING MODE IN FORCE ****
 
50 IF AHU7- HV 1 THEN AHU7- HM = 1 ELSE AHU7- HM = 0
 
60 IF DM-7 OR PC-7 OR WU-7 THEN START AHU7-S/S ELSE STOP AHU7-S/S 70 REM *** MIXED AIR DAMPER ***
 
80 REM ** FREE COOL MODE **
 
90 IF OAT AHU7- RTS - 2.5 THEN START AHU7- FCM
 
100 IF OAT AHU7- RTS - 1 THEN STOP AHU7- FCM 110 AHU7- MAD = MAX( AHU7- AIR , 1- CON1 )
 
120 IF NOT AHU7- FCM THEN AHU7- MAD = AHU7- AIR
 
 130 IF AHU7- HV 1 THEN AHU7- MAD = AHU7- AIR
 
140 IF OAT 10 THEN AHU7- MAD = MIN( AHU7- MAD , TIME- ON( AHU7-S ) )
 
150 IF NOT AHU7-S THEN AHU7- MAD = 0
 
160 AHU7- DSP = MAX( 12 , MIN( OCCT-7 , 24 ) )
 
170 IF NOT AHU7-S/S THEN AHU7- DSP = AHU7- MAT
 
180 REM *** HEAT ING CON TROL ***
 
190 AHU7- HV = 1- CON2
 
200 IF AHU7- SAT 30 THEN AHU7- HV = 0
 
210 IF AHU7- RTS OCCT-7 THEN AHU7- HV = 0
 
 220 IF NOT AHU7-S THEN AHU7- HV = 0
 
230 IF AHU7- FRZ THEN AHU7- HV = 100
 
 240 AHU7- HSP = AHU7- DSP - 0.5
 
250 IF NOT AHU7-S/S THEN AHU7- HSP = AHU7- SAT
 
260 REM *** COOL ING CON TROL ***
 
270 AHU7- CSP = AHU7- DSP + 0.5
 
280 IF NOT AHU7-S/S THEN AHU7- CSP = AHU7- SAT
 
290 AHU7- CV = 1- CON3
 
295 IF AHU7- RTS OCCT-7 + 1 THEN GOTO 330
 
300 IF AHU7- FCM AND AHU7- MAD 90 THEN AHU7- CV = 0
 
330 IF AHU7- SAT 10 THEN AHU7- CV = 0
 
340 IF NOT AHU7-S THEN AHU7- CV = 0
 
 
Control Basic programs have line numbers for each new program statement. Each statement, command, and operator is separated from the next item by a space. Program execution starts at the top-most line and barring any GOTO
 
statements in the program, follows on through each line in the program.
 
10.3     PROGRAM FLOW
 
There are some special mechanisms employed by the T3000 operating system to protect the pumps and fans, and control them efficiently. Understanding the program flow in a T3000 system will help understand how to better program a real time system and will also make your programs easier to follow.
 
For the most part, program logic in the T3000 panel follows through from the top of the program to the last line in sequential order. Since Basic supports the GOTO command, but program execution can actually take any path that you desire, but GOTO statements can cause a program to be difficult to follow.
 
Although an OUTPUT can appear many times in a program, with some lines commanding the output to go on, and other lines telling the output to go off, the output is not actually switched until all the lines in a particular panel are evaluated. This mechanism gives lines appearing at the end of the program veto power over earlier lines. Safety program statements such as emergency shutdown appear at the end of a program to be sure the shut down logic over rides all other possible logic. A useful consequence of this mechanism is that a particular output can appear many times in a program, breaking up the logic amongst several simple program statements.
 
When the last line is processed, the T3000 system automatically begins execution from the start of the program again. There is no need for a RETURN statement as in other Basic dialects as the return is implied in a T3000 program. Each program can be thought of as a treadmill on which the T3000 keeps on running continuously churning through the code and adjusting the outputs based on the program logic. The example below shows the logic flow for the T3000 system:
 
 
Good programming practice will dictate that a particular output is programmed in only one program. If the program for a particular system is so large that it must be broken up, the program would be broken along logical boundaries so that each output only appears in one program. Future trouble shooting sessions will be simplified if each output is programmed in only one program.
 
 
 
 
10.4     CONTROL BASIC COMPONENTS
 
 
 
 
This section lists the components used in Basic program. Following this list is a detailed list of all the program commands and functions. Most of the items are explained with a short ex ample on how to use the command.
 
The following is a list of the fundamental components of a Basic program:
 
REAL NUMBERS .  .     Ordinary numbers.
 
DAYS .  .  .  .  .  .  .     The 7 days of the week.
 
DATES  .  .  .  .  .  .     The calendar date.
 
TIMES .  .  .  .  .  .  .     Time in HH:MM:SS format.
 
VARIABLES .  .  .  .     The T3000 soft ware sup ports a large table of Variables or memory locations which can be used for setpoints, accumulators, modes and other useful bits of information pertinent to the particular application.
 
OPERATORS     .  .  .     Mathematical operators such as the greater than( >), less than (<), and equals ( =) symbols.
 
COMMANDS .  .  .  .     Specifies an action word in programming language such as the START command in the following example:
 
IF IN1 > 20 THEN START OUT1
 
FUNCTIONS .  .  .  .     Functions are built in routines which return a value. For instance MAX(T1, T2, T3... ) in the example shown will return the larger of the items enclosed in brackets.
 
VAR1 = MAX( IN1 , IN2 , IN3 )
 
EXPRESSIONS. . . . Notation that has a value. Usually a combination of above elements.
 
The complete list of Control Basic components:
 
 
 
 
 
 
STATEMENT
TYPE
DESCRIPTONSUMMARY
 
 
NUMBERS
DATA
Real numbers are handled by the T3000 in full floating point for mat
 
 
DAYS
DATA
Days are evaluated as an integer from 0 for sun day to 6  for   saturday
 
 
DATES
DATA
Dates are handled internally by the T3000 as a number from 1 to 365
 
 
TIMES
DATA
Times are handled internally as hours, but can be typed HH:MM:SS in a program
 
 
VARIABLES
DATA
Variables are handled internally as real numbers with full floating point notation
 
 
NOT
OPERATOR
Evaluates to TRUE if the opposite is true. IF NOT HOT evaluates to true when COLD
 
 
^
OPERATOR
Exponent, raises a number to a power as in 2^2 = 4
 
 
* /   \  MOD
OPERATOR
Multiplication, division, integer portion of a division, remained of a division
 
 
+ -
OPERATOR
 Addition and subtraction
 
 
< > ... etc
OPERATOR
Less than, greater than, and other combinations.
 
 
AND
LOGIC
Logical AND, both conditions must be TRUE for the expression to evaluate to TRUE
 
OR
LOGIC
Logical OR, if either expression is TRUE the result is TRUE
 
XOR
LOGIC
Logical Exclusive OR,  evalutates  to TRUE if the two expressions are different
 
ABS
FUNCTION
Absolute Value, returns the positive equivalent of a negative or positive number
 
ALARM
COMMAND
Causes an alarm, has built in hysterisis to avoid multiple alarms from the same event
 
ALARM-AT
COMMAND
Selects which panel will annunciate alarms, default is ALL panels
 
AVG
FUNCTION
Average of all numbers enclosed in the brackets following this command
 
CALL
COMMAND
Calls an other program which functions as a sub routine, takes arguments
 
CLEAR
COMMAND
Clears all the local variables in a given program
 
CLOSE
COMMAND
Sets a variable or out put to 0, same as STOP but is more intuitive in some cases
 
CONPROP
FUNCTION
Allows a Basic program to up date the proportional term in a particular PID controller
 
CONRATE
FUNCTION
Allows a Basic program to up date the derivative term in a particular PID controller
 
CONRESET
FUNCTION
Allows a Basic program to up date the integral term in a particular PID controller
 
DALARM
COMMAND
Delayed alarm, allows generation of alarms if a condition is true for a certain time
 
DECLARE
COMMAND
First line of a sub routine to accept the list of arguments from a CALL statement
 
DISABLE
COMMAND
Same as STOP or CLOSE, sets an item to 0
 
DOM
FUNCTION
Day of month, returns the day of the month, starting with 1 on the first of the month
 
DOW
FUNCTION
Day of week, returns a number from 0 to 6 starting with Sun day as zero
 
DOY
FUNCTION
Day of the year, starting with Jan1 as 1
 
ENABLE
COMMAND
Same as START or OPEN, sets the value of an item to 1.
 
END
COMMAND
Ends execution of a program, T3000 assumes and end at the end of each program
 
FOR
COMMAND
Loop control statement, FOR A =1 TO 10 ....PRO GRAM LINES.....NEXT A
 
GOSUB
COMMAND
Branches to sub routine, executes program till next RE TURN statement, and loops back
 
GOTO
COMMAND
Unconditionally branches program execution to an other line
 
HANGUP
COMMAND
Ends a phone call in progress
 
IF
COMMAND
Logical decision, IF HEAT MODE THEN START OUT1
 
IF+
COMMAND
Executes the program line only once when the condition goes from FALSE to TRUE
 
IF-
COMMAND
Opposite of IF+, executes the line only when a condition be comes FALSE
 
INT
FUNCTION
Returns the integer part of an expression
 
INTERVAL
FUNCTION
IF INTERVAL(0:01:00) executes the following programming once every minute
 
LET
COMMAND
Assignment operator, LET B = 20, has the same effect as B = 20
 
LN
FUNCTION
Natural logarithm of the argument
 
LN-1
FUNCTION
In verse logarithm of the argument
 
MAX
FUNCTION
Maximum of a list of arguments enclosed in brackets following the statement
 
MIN
FUNCTION
Minimum of a list of arguments enclosed in brackets following the statement
 
NEXT
COMMAND
Used in conjunction with the FOR statement to increment the loop counter
 
ON
COMMAND
ON VAR1 GOTO 100 , 200 , 300 , controls program path depending on VAR1
 
ON-ALARM
COMMAND
Evaluates to TRUE when ever there is an alarm in the system.
 
ON-ERROR
COMMAND
Used with PHONE, REMOTE- GET, REMOTE- SET, and RUN- SYSTEM
 
OPEN
COMMAND
Sets an item to 1, OPEN OUT1 is the same as START OUT1
 
PHONE
COMMAND
Phones a number, allows T3000 to dial with a modem for numeric paging
 
POWER -LOSS
FUNCTION
Looks for loss of power, 1 the first time the function is evaluated, o afterwards
 
PRINT
COMMAND
Print strings at a printer connected to the panel
 
PRINT- AT
COMMAND
Print strings at a printer connected to an other panel on the net work
 
REM
COMMAND
Remark, used to add comments to a program
 
REMOTE- GET
COMMAND
10 REMOTE- GET VAR1 = 2IN1, gets a reading from an other site via modem
 
REMOTE-SET
COMMAND
Sets a variable at a remote site via modem.
 
RE TURN
COMMAND
Causes program execution to return from a sub routine
 
RUN-MACRO
COMMAND
Causes a macro command or series of key strokes to be run
 
SCANS
FUNCTION
The number of scans a panel is per forming in one second
 
SET-PRINTER
COMMAND
Tells a T3000 system there is a printer at a particular panel
 
SQR
FUNCTION
Returns the square root of the argument
 
START
COMMAND
Sets the value of an items to 1, same as OUT1 = 1 or OPEN OUT1
 
STATUS
FUNCTION
Status of a panel on the net work, 0 = No Comm, 1 =OK, 2 = no program
 
STOP
COMMAND
Sets the value of an items to 0, same as OUT1 = 0 or CLOSE OUT1
 
TBL
FUNCTION
Looks up a value in a table
 
TIME
FUNCTION
Finds the cur rent time
 
 
 
 
 
TIME-OFF
FUNCTION
Finds the time variable has been false
 
TIME-ON
FUNCTION
Finds the time variable has been true
 
WAIT
COMMAND
Pauses program execution
 
WR-ON
FUNCTION
Finds when a weekly routine is set to come on
 
WR-OFF
FUNCTION
Finds when a weekly routine is set to go off
 
UNACK
FUNCTION
Determines if there are unacknowledged alarms in system
 
USER-A
FUNCTION
Finds the user logged on to the local port
 
USER-B
FUNCTION
Finds the user logged on to the remote port
 
 
The following sections list the components of a Basic program, along with some examples and descriptions on how they operate.
 
In this section the various components are listed alphabetically. The explanation of each term consists of 3 parts:
 
1.     Purpose .  .  .  .  .  Explains when the function is used.
 
2.     Format  .  .  .  .  .  Shows how the function is used.
 
3.    Example  .  .  .  .  Gives a practical application.