Logic Programming
Basics of Logic Programming
In this article, we will explore all the buttons on the Logic Programming Screen, including Priority, Evaluation periods, and Copying logic.
First of all, you can program logic on just about any point in your system, be it a hardware or software point. For more information on software points,. Software Point Types. Begin by going to any point that you want to add logic to.
From the Point Program Screen, click on
and you will see the following window: 
To start writing a logic sequence, click on the first line and a box will pop up containing choices for starting a sequence (see left).
Click on the first line (If) and another box will pop up with a list of possible point names.

Notice that the list only includes “Local Points”, which are points local to the controller that contains the point you are adding the logic to. To get a list of “All Points” or all the possible points in the database, right-click then click the Local Points button. Keep in mind that if you use a point on another controller, the CBAS Server is required to make the logic work unless that point is a “Peer-to-Peer” point.
Choose the point name you would like to base the “If” condition on, and another box will pop up with condition choices, like “Is greater than.” By now, you are starting to get the picture. The CBAS logic editor will give you appropriate choices based on your previous choices. And, as you might have noticed by now, “If, Then, Else” is the basis of almost all logic statements.
In an “If, Then, Else” sequence, the “Then” is not executed unless the “If” is true. If it is NOT true, the “Else” is executed. See the flow chart below.
There are too many possible choices and sequences to show them all here. For examples of logic, view the Example Database and the Template Database included with CBAS. For more information on this subject, continue on to the next section.
•To go back and edit a row, right-click, click “Edit Row,” then select the row you want to change.
•To delete a row, right-click, click “Delete Row,” and select the row you want to delete.
•To insert a row, right-click and click “Insert Row.” Move your pointer between the lines of logic and a red line will appear. Click there and a window will appear with appropriate choices for that line.
•To save a newly created or edited logic sequence, just right-click or escape to close the window. The Logic button will now appear ? 
•To temporarily disable a logic sequence, click “Enabled” and the button will turn to “Disabled.” Click “Disabled” to re-enable the logic.
•To delete the logic completely, click on “Delete.”
Other Features in the Logic Sequence Window
Click on the “Priority Logic 1 Programming” button below the Logic Sequence window and you will see a list of priorities. From here you can change the priority of a logic sequence so that it overrides, or is overridden by, another logic statement, schedule, etc.

For a list of priorities, go to Text View, Priority Summary. The list is shown here. (You can click on any line and get a Logical Group of points commanded by that priority) Notice that Logic 3 and Logic 4 are the highest priorities and will override any other priority. By using these priorities, you can make sure that one logic sequence overrides the other when 2 sequences command the same point.
•Next to the “Evaluate Every” button, you can change how often a Logic Sequence is evaluated. The default is every 15 seconds.
•Click on the “Evaluate Every” button, and you can change it so that the sequence only evaluates when the status of the point hosting the logic changes.

•The “Copy to Point” button is used to copy the logic statement to another point. However, point names will have to be manually changed on the copied logic statement using the “Edit Row” button.
•To avoid having to do this, use the “Relative Copy to Point” button. Choose the point you want to copy to, then right-click twice to get the following window.
•You can click on any line and select a valid point. Once you make your selections, right-click and the point names are changed.
•The “Copy to Clipboard” button allows you to copy the entire logic sequence to the Windows clipboard. You can then paste the logic sequence into a text document and save or print it.
•The Grouping section arrows will be explained in the Logic Grouping section.

Logic Grouping
There’s one rule of thumb when writing logic on a point for a sequence of operation: “Keep it as simple as you can.” If you can’t keep it simple, because of a complicated sequence of operation, grouping portions of logic statements can help. Sometimes it’s hard to know how to group and, or, and for statements. Here’s a brief explanation, using the following example.
If UV-2 Heat/Cool Mode is OFF
or UV-2 Heat/Cool Mode is HEAT and UV-2 Face/Bypass Limit is less than 100 SEC and UV-2 Supply Air Temp is less than Equation Begin ( UV-2 Supply Air Setpoint – 3 ) Equation End then adjust UV-2 Face/Bypass Damper by 4 SEC adjust UV-2 Face/Bypass Limit by 4 SECIf UV-2 Heat/Cool Mode is OFF
or UV-2 Heat/Cool Mode is HEAT and UV-2 Face/Bypass Limit is greater than -100 SEC and UV-2 Supply Air Temp is greater than Equation Begin ( UV-2 Supply Air Setpoint + 3 ) Equation End then adjust UV-2 Face/Bypass Damper by -4 SEC adjust UV-2 Face/Bypass Limit by -4 SECIn the preceding 2 If/Then statements, the And & Or statements are grouped differently. Let’s look at the first statement. If the first line is true, then there is no need to evaluate the Or on the second line. And, since the 2 And lines are grouped to the right of the Or (subordinate to the Or), they are not evaluated and the Then is executed. Here’s a flow chart to make it easier to understand: 
If the Mode was Heat, then it could not have been Off, so the first line would have been false. Then, the second line would have to be evaluated. By the nature of the Ands, they must also be evaluated. So, the entire statement will evaluate. Here’s a flow chart:

In the second statement, the And lines are no longer subordinate to the Or line because they are grouped equally. So, because of the nature of the Or, the second line is not evaluated if the first line is true. But, by nature, the Ands must be evaluated because they are grouped in line with the Or. Here’s a flow chart:

The same rules apply to the For statement, which adds a requirement that the state be maintained for a period of time before the statement is determined to be true. Whenever a For statement is added, it is always subordinate to the statement it follows. If the statement it follows is not true, the For statement does not execute. In other words, it won’t wait the specified time. Here’s an example:
If UV-12 Heat/Cool Mode is OFF
for 00:10:00 or UV-12 Heat/Cool Mode is HEAT and UV-12 Face/Bypass Limit is less than 100 SEC and UV-12 Supply Air Temp is less than Equation Begin ( UV-12 Supply Air Setpoint – 3 ) Equation End then adjust UV-12 Face/Bypass Damper by 4 SEC adjust UV-12 Face/Bypass Limit by 4 SECIf UV-12 Heat/Cool Mode is OFF
or UV-12 Heat/Cool Mode is HEAT for 00:10:00 and UV-12 Face/Bypass Limit is greater than -100 SEC and UV-12 Supply Air Temp is greater than Equation Begin ( UV-12 Supply Air Setpoint + 3 ) Equation End then adjust UV-12 Face/Bypass Damper by -4 SEC adjust UV-12 Face/Bypass Limit by -4 SECIn the first If/Then statement, let’s say the Mode is OFF for 10 minutes. It will then evaluate the And statements, because the Ands are in line with the Or. If the Mode is HEAT, then it will go straight to the And statements without waiting.
In the second statement, the Ands are subordinate to the Or. So, if the Mode is OFF, the For, and Ands will not be evaluated. Here’s a flow chart:

If the Mode is HEAT for 10 minutes, then the For & And statements will be evaluated.

Suppose you want the For to apply to all the Or & And statements in the sequence. Here is an example of how to do that:
If UV-12 Heat/Cool Mode is OFF or UV-12 Heat/Cool Mode is HEAT
and UV-12 Face/Bypass Limit is less than 100 SEC and UV-12 Supply Air Temp is less than Equation Begin ( UV-12 Supply Air Setpoint3 ) Equation End for 00:10:00
then adjust UV-12 Face/Bypass Damper by 4 SEC
Notice that the “For” is in line with all of the “Ors” and “Ands.” Because of this, the “For” applies to the “Or” and both of the “Ands.” In this case, the 10-minute requirement applies to both of the “Ands” and at least one of the “Ors.”
One more thing should be said about adding “For” statements to logic sequences: There is a limit of 4 “For” statements per logic sequence. If you try to add a 5th, you will get an error message stating that it cannot be saved when exiting the logic editor.
As you can see, grouping can make a big difference in the way your logic is executed and whether or not the sequence of operation is achieved.
To change grouping, click on the left or right arrow in the Grouping section of the Logic Sequence window (shown below). Then, click on the line you want to move.

If and Else If
Have you seen or written logic on a point that contains two or more “If, Then, Else” sequences? Have you seen logic that contains an “If, Then, Else If” sequence? You might have wondered what the difference is and why you would use one or the other. The simple answer is: Use an “Else If” sequence if you want to avoid conflicts between the two sequences.
In an “If, Then, Else” sequence, the “Then” is not executed unless the “If” is true. If it is NOT true, the “Else” is executed. See the flow chart below.
The same is true for the “If, Then, Else If” sequence. Consider the following logic example:
If AHU 10 is OFF or the priority of AHU 10 is Optimal Start or AHU 10 NIGHT SETBACK is ON or AHU 10 OVERRIDE TIMER is greater than 0 MINS
then command AHU 10 MIXED DAMPER to 0 %OPEN
else if AHU 10 is ON and AHU 10 ECONOMIZER MODE is OFF
then command AHU 10 MIXED DAMPER to 15 OPEN
else if AHU 10 is ON and AHU 10 ECONOMIZER MODE is ON
and the priority of AHU 10 MIXED DAMPER is Logic 1 Programming then auto AHU 10 MIXED DAMPERIn the above example, if any of the first conditions are met, the damper is commanded to 0 OPEN and the 2 else if sequences are not evaluated. If none of the first conditions are met, the first else if sequence is evaluated. If both conditions are met in the first else if, the damper is commanded to 15% Open and the next else if is not evaluated. If one condition is not met, the second else if is then evaluated. If one of those conditions is not met, nothing changes and the sequence starts over at the first If.
On the right is a simplified flow chart. Start from the top left “IF” box and follow the True or False arrows. All possibilities are covered in this chart.

Notice that the process starts over after execution of the Then sequence or if the final Else If is false. The amount of time delay before the process starts again can be determined by changing the “Evaluate Every” time, as shown here. Once the bottom of a Logic Sequence is reached, CBAS waits that amount of time before starting over.
When you have two “If, Then, Else” sequences, instead of an “If, Then, Else If” sequence, both sequences are evaluated. You have to be very careful to make sure that both “If” sequences cannot be true at the same time, otherwise the two “Then” sequences could be in conflict. In the following example, there is no way that both sequences could be true because the ranges do not overlap.
If AHU 10 SPACE TEMP is greater than 85.0 DEG F or AHU 10 SPACE TEMP is less than 65.0 DEG F
then ON AHU 10 NIGHT SETBACK
If AHU 10 SPACE TEMP is less than 82.0 DEG F and AHU 10 SPACE TEMP is greater than 68.0 DEG F
then OFF AHU 10 NIGHT SETBACK
In fact, there is a 3-degree dead-band between the ranges. This couldn’t be achieved using a standard “If, Then, Else” sequence, like this:
If AHU 10 SPACE TEMP is greater than 85.0 DEG F or AHU 10 SPACE TEMP is less than 65.0 DEG F
then ON AHU 10 NIGHT SETBACK
else OFF AHU 10 NIGHT SETBACK
However, the dead-band could be achieved with the following “If, Then, Else If” sequence.
If AHU 10 SPACE TEMP is greater than 85.0 DEG F or AHU 10 SPACE TEMP is less than 65.0 DEG F
then ON AHU 10 NIGHT SETBACK
else if AHU 10 SPACE TEMP is less than 82.0 DEG F and AHU 10 SPACE TEMP is greater than 68.0 DEG F
then OFF AHU 10 NIGHT SETBACK
If the actual SPACE TEMP falls in the dead-band area, nothing happens. In other words, Night Setback stays in its previous state. The following flow chart shows what happens if the temperature is 83.

The “For” Statement
Here is some additional information about “FOR.”
Suppose you want the For to apply to all the Or and And statements in the sequence. Here is an example of how to do that:
If UV-12 Heat/Cool Mode is OFF
or UV-12 Heat/Cool Mode is HEAT and UV-12 Face/Bypass Limit is less than 100 SEC and UV-12 Supply Air Temp is less than Equation Begin ( UV-12 Supply Air Setpoint -3 ) Equation End for 00:10:00then adjust UV-12 Face/Bypass Damper by 4 SEC
Notice that the For is in line with all of the Ors and Ands. Because of this, the For applies to the Or and both of the Ands. In this case, the 10-minute requirement applies to both of the Ands and at least one of the Ors.
One more thing should be said about adding For statements to logic sequences: There is a limit of four For statements per logic sequence. If you try to add a 5th, you will get an error message that it cannot be saved when exiting the logic editor.
About
Support
