8 Control Basic ProgrammingControl 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:
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:
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.
|