BAS-220 · Lesson 4 of 12 · 23 min
Boolean logic and timers
▶ Video coming soon A video version of this lesson is on the way.
On Thursday, September 24, three days after Ilona Vescovi approved the RTU-1 controller replacement at Ninefield Tower, Sophie started writing the program that all four podium rooftop units would eventually share. Callie spent the afternoon beside her. Sophie began with the compressors, because compressors are where control logic does the most good and the most harm. "A compressor is the most expensive thing on the roof," she said. "It doesn't care about our setpoints. It cares about how often we start it, how long we run it, and whether its safeties are respected." The tools for that are Boolean logic and timers, the subject of this lesson.
Binary values and Boolean logic
Much of a control program deals with binary values: a fan is running or not, a schedule is occupied or not, a safety is made or tripped, a stage is commanded on or off. Boolean logic, named after the mathematician George Boole, combines binary values with a small set of operators. Every operator has a truth table that lists its output for every combination of inputs. Programmers use the tables to check logic in the same way electricians use a schematic.
| A | B | A AND B | A OR B | A XOR B | NOT A |
|---|---|---|---|---|---|
| false | false | false | false | false | true |
| false | true | false | true | true | true |
| true | false | false | true | true | false |
| true | true | true | true | false | false |
AND is true only when every input is true. It is the natural operator for permissives: a compressor may run only if the fan is proven AND the smoke detector is normal AND the low-pressure safety is made. OR is true when any input is true. It suits alarms and demands: raise a general alarm if the freezestat has tripped OR the fan has failed OR the filter is dirty. NOT inverts a value. XOR, exclusive or, is true when its inputs differ, which makes it useful for detecting a mismatch between a command and a status: if the fan is commanded on but its status is off, or commanded off but running, XOR is true.
Building permissives and interlocks
BAS-130 introduced interlocks and permissives: conditions that must be satisfied before equipment may run. In a program, a permissive is usually one AND of all the required conditions, written once at the top of the section and used by everything below. Sophie wrote the RTU compressor permissive as a single statement, so that a reader could see in one place every reason the compressor might be prevented from running.
(* RTU compressor stage 1 : permissive, protection and command *)
Stage1Permit := FanProven AND NOT SmokeAlarm AND NOT LowPressTrip
AND (OAT > CompLockoutOAT) AND CoolEnable;
(* minimum off: the stage may not restart until it has been off 5 minutes *)
OffTimer(IN := NOT Comp1Cmd, PT := T#5m);
(* minimum on: once started, the stage stays on at least 3 minutes *)
OnTimer(IN := Comp1Cmd, PT := T#3m);
IF Stage1Permit AND CoolCall1 AND OffTimer.Q THEN
Comp1Cmd := TRUE;
ELSIF NOT Stage1Permit THEN
Comp1Cmd := FALSE; (* safeties stop it at once *)
ELSIF NOT CoolCall1 AND OnTimer.Q THEN
Comp1Cmd := FALSE; (* normal stop after minimum on *)
END_IF;The permissive combines five conditions: the supply fan is proven, there is no smoke alarm, the unit's low-pressure safety has not tripped, the outdoor air temperature is above the compressor lockout setting, and cooling is enabled by the mode logic. If any one is false, the whole permissive is false and the compressor is stopped at once, regardless of the timers. Sophie stressed that the hardwired safeties in the rooftop unit itself, such as its high-pressure switch, act directly on the compressor contactor in the unit's own control circuit. The program's permissive adds to them; it never replaces them, as BAS-120 and BAS-130 both insisted.
Latches and edge detection
Some conditions must be remembered after their cause has gone. A freezestat trip, for example, should keep the air handler off until someone has looked at it and reset it, even if the coil warms up again. A latch, or set-reset block, does this: its output goes true when the set input becomes true and stays true until the reset input becomes true. If set and reset are both true at once, the block's priority decides which wins; for safety latches, reset should not override an active trip.
An edge detector, sometimes called a one-shot or pulse block, produces a true output for exactly one scan when its input changes. A rising edge detector fires when the input goes from false to true; a falling edge detector fires on the change from true to false. Edge detectors are used to count events, such as compressor starts, and to trigger an action once rather than continuously, such as logging the time a fan started.
Worked problem
Counting starts with an edge detector
A rising edge detector on Comp1Cmd adds one to a starts counter each time the compressor starts. During a test, the command changes as follows over ten scans: off, on, on, on, off, off, on, on, off, on. How many starts are counted?
Show solution
- Rising edges occur where the command changes from off to on: scan 2, scan 7 and scan 10.
- The counter adds one at each rising edge: 3 starts.
Answer: Three starts. A counter that added one on every scan the compressor was on would have counted 6, which is why counters use edges rather than levels.
Timers
Timers bring time into logic. The three most common are the on-delay, the off-delay and the pulse. IEC 61131-3 calls them TON, TOF and TP, and most building automation tools have equivalents under their own names. Each has an input, a preset time and an output, and the programmer must know exactly what each does when the input changes before the time is up.
| Timer | Output goes true | Output goes false | Typical use |
|---|---|---|---|
| On-delay (TON) | When the input has been true continuously for the preset time | As soon as the input goes false | Alarm delays, proof delays, staging delays |
| Off-delay (TOF) | As soon as the input goes true | When the input has been false continuously for the preset time | Fan run-on after heating, pump run-on |
| Pulse (TP) | When the input goes true | After the preset time, whatever the input does | Fixed-length commands, such as a reset pulse |
The detail that catches people is what happens when the input drops out before the time is up. An on-delay timer starts again from zero; the time is continuous, not cumulative. That is exactly what an alarm delay needs: a high temperature that lasts nine minutes of a ten-minute delay, then dips, does not raise the alarm. If the programmer wanted cumulative time, the right block is a retentive timer or an accumulator, which keeps its count while the input is false and must be reset separately.
Minimum on and minimum off: protecting compressors
A compressor that starts and stops too often, called short cycling, wears its contacts, overheats its motor windings from repeated starting current and may not run long enough to return oil to its crankcase. Manufacturers state limits, typically as a maximum number of starts per hour or as minimum on and off times. The control program enforces them with timers: a minimum on timer keeps the compressor running for a set time once it has started, and a minimum off timer, often called an anti-short-cycle timer, keeps it off for a set time after it stops.
In the listing, the off timer's input is NOT Comp1Cmd, so it times while the compressor is off, and its output OffTimer.Q becomes true only after five minutes off. The start condition requires OffTimer.Q, so the compressor cannot restart sooner. The on timer times while the compressor runs, and the normal stop condition requires OnTimer.Q, so a call that ends after one minute does not stop the compressor until three minutes have passed. The safety branch, NOT Stage1Permit, does not wait for either timer: a safety always wins over protection timers. Values of three minutes on and five minutes off are typical; the rooftop unit's documentation sets the real ones, and some units have their own built-in timers, in which case Sophie sets the program's timers no shorter than the unit's.
Worked problem
How timers change cycling
A badly located thermostat calls for cooling for 2 minutes, then is satisfied for 2 minutes, over and over. Without timers, how many starts per hour would the compressor make? With a 3 minute minimum on and a 5 minute minimum off, how long is each cycle, and how many starts per hour?
Show solution
- Without timers: one cycle is 2 + 2 = 4 minutes, so 60 ÷ 4 = 15 starts per hour.
- With timers: each run lasts at least 3 minutes and each off period at least 5 minutes, so each cycle is at least 3 + 5 = 8 minutes.
- Starts per hour: 60 ÷ 8 = 7.5.
Answer: Fifteen starts per hour without timers, and at most 7.5 with them. The timers protect the compressor, but the real fix is to move the sensor or widen the differential so that the call itself lasts longer.
The 2004 controllers on Ninefield's podium units had used fixed timers built into their firmware. Reading the old controllers' manual, Sophie found that their minimum off time was only two minutes. The rooftop unit manufacturer's current guidance asked for five. The new program would use five, with the value as a named constant and a comment citing the guidance.
Staging delays and restart delays
Timers also space out equipment. When a call for cooling is large, the program brings on stage 2 only after stage 1 has run for a set time and the call is still unmet, so the unit does not jump to full capacity for a short peak. After a power failure, many controllers in a building restart at the same moment; staggered restart delays, set differently in each controller, stop every fan and compressor in the building from starting at once and overloading the electrical service. Lesson 1's restart section was where Sophie put this: each rooftop unit's program would wait a different number of seconds after power returned, set from its unit number.
| Timer use | Typical setting | Why |
|---|---|---|
| Fan proof delay | About 30 to 60 seconds | Gives the fan time to prove before a failure alarm |
| Minimum compressor on | About 3 minutes | Returns oil and avoids short runs |
| Minimum compressor off | About 5 minutes | Lets pressures equalize and limits starts |
| Stage-up delay | About 5 to 10 minutes | Avoids full capacity for short peaks |
| Restart stagger | A few seconds to a minute per unit | Spreads starting current after a power failure |
| Alarm delay | Minutes, depending on the point | Filters brief excursions |
Checking logic with a truth table
Before Sophie trusted a permissive, she wrote its truth table, at least for the combinations that mattered. For the compressor permissive, with five inputs, there are 2 × 2 × 2 × 2 × 2 = 32 combinations, but only one gives true: every condition satisfied. The useful checks are the five rows where exactly one condition is false, because each should stop the compressor on its own. Callie tested those five in simulation, one at a time, and recorded each in the test plan that lesson 11 describes. A permissive that still allows the compressor with one condition false has an OR where an AND should be, or a NOT in the wrong place, and the truth table finds it in minutes.
| Row | Condition false | Expected permissive |
|---|---|---|
| 1 | None | True |
| 2 | Fan proven | False |
| 3 | No smoke alarm | False |
| 4 | Low pressure not tripped | False |
| 5 | Outdoor air above lockout | False |
| 6 | Cooling enabled | False |
Common mistakes
MistakeUsing a level instead of an edge to count events.
InsteadCount starts and other events with a rising edge detector, which fires once per change.
MistakeExpecting an on-delay timer to add up interrupted time.
InsteadRemember that an on-delay restarts from zero when its input drops; use a retentive timer for cumulative time.
MistakeLetting protection timers delay a safety shutdown.
InsteadWrite safety branches so that they act immediately, ahead of minimum on timers.
MistakeSetting program timers shorter than the equipment's own.
InsteadSet program timers no shorter than the manufacturer's guidance and any timers built into the unit.
MistakeLetting reset override an active safety latch.
InsteadGive the trip priority, so that a reset only works once the cause has cleared.
Summary and key terms
- Boolean logic combines binary values with AND, OR, XOR and NOT, each defined by a truth table.
- Permissives are usually one AND of every required condition, written once and used throughout the section.
- XOR detects a mismatch, such as a fan commanded on whose status is off.
- Latches remember trips until reset; edge detectors fire for one scan when an input changes.
- On-delay, off-delay and pulse timers bring time into logic; an on-delay restarts if its input drops.
- Minimum on and minimum off timers prevent compressor short cycling; safeties override them.
- Staging and restart delays spread capacity and starting current.
- Boolean logic
- Logic that combines true and false values with operators such as AND, OR and NOT.
- Truth table
- A table giving an operator's output for every combination of inputs.
- Permissive
- A condition, or set of conditions, that must be true before equipment may run.
- Latch
- A set-reset block whose output stays true after its set input until it is reset.
- Edge detector
- A block that is true for one scan when its input changes.
- On-delay timer
- A timer whose output goes true after its input has been true for the preset time.
- Off-delay timer
- A timer whose output stays true for the preset time after its input goes false.
- Short cycling
- Starting and stopping equipment too often.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Fan proven is true, smoke alarm is false. What is FanProven AND NOT SmokeAlarm?
Show answer
True.
A fan is commanded off but its status shows running. What does command XOR status give?
Show answer
True, a mismatch.
An alarm on-delay of 10 minutes sees a condition for 9 minutes, a 30 second break, then 6 minutes. Does it alarm?
Show answer
No. The timer restarted after the break and only reached 6 minutes.
A call cycles 3 minutes on and 3 minutes off. With 3 minute minimum on and 5 minute minimum off timers, what is the most starts per hour?
Show answer
Each cycle is at least 3 + 5 = 8 minutes, so 7.5 starts per hour.
Why stagger restart delays between rooftop units?
Show answer
So that all units do not start together after a power failure and overload the electrical service.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.