Buildings.Controls.OBC.CDL.Logical

Package with logical blocks

Information

Package with blocks for elementary mathematical functions for boolean variables.

Package Content

Name Description
Buildings.Controls.OBC.CDL.Logical.And And Logical 'and': y = u1 and u2
Buildings.Controls.OBC.CDL.Logical.Change Change Output y is true, if the input u has a rising or falling edge (y = change(u))
Buildings.Controls.OBC.CDL.Logical.Edge Edge Output y is true, if the input u has a rising edge (y = edge(u))
Buildings.Controls.OBC.CDL.Logical.FallingEdge FallingEdge Output y is true, if the input u has a falling edge (y = edge(not u))
Buildings.Controls.OBC.CDL.Logical.Latch Latch Maintains a true signal until cleared
Buildings.Controls.OBC.CDL.Logical.MultiAnd MultiAnd Logical MultiAnd, y = u[1] and u[2] and u[3] and ...
Buildings.Controls.OBC.CDL.Logical.MultiOr MultiOr Logical MultiOr, y = u[1] or u[2] or u[3] or ...
Buildings.Controls.OBC.CDL.Logical.Nand Nand Logical 'nand': y = not (u1 and u2)
Buildings.Controls.OBC.CDL.Logical.Nor Nor Logical 'nor': y = not (u1 or u2)
Buildings.Controls.OBC.CDL.Logical.Not Not Logical not
Buildings.Controls.OBC.CDL.Logical.Or Or Logical 'or': y = u1 or u2
Buildings.Controls.OBC.CDL.Logical.Pre Pre Breaks algebraic loops by adding a delay of the output without advancing time (y = pre(u): event iteration continues until u = pre(u))
Buildings.Controls.OBC.CDL.Logical.Proof Proof Verify two boolean inputs
Buildings.Controls.OBC.CDL.Logical.Switch Switch Switch between two boolean signals
Buildings.Controls.OBC.CDL.Logical.Timer Timer Timer measuring the time from the time instant where the Boolean input became true
Buildings.Controls.OBC.CDL.Logical.TimerAccumulating TimerAccumulating Accumulating timer that can be reset
Buildings.Controls.OBC.CDL.Logical.Toggle Toggle Toggles output value whenever its input turns true
Buildings.Controls.OBC.CDL.Logical.TrueDelay TrueDelay Delay a rising edge of the input, but do not delay a falling edge
Buildings.Controls.OBC.CDL.Logical.TrueFalseHold TrueFalseHold Block that holds an output signal for at least a specified duration
Buildings.Controls.OBC.CDL.Logical.VariablePulse VariablePulse Generate boolean pulse with the width specified by input
Buildings.Controls.OBC.CDL.Logical.Xor Xor Logical 'xor': y = u1 xor u2
Buildings.Controls.OBC.CDL.Logical.Sources Sources Package with blocks that generate source signals
Buildings.Controls.OBC.CDL.Logical.Validation Validation Collection of models that validate the logical blocks of the CDL

Buildings.Controls.OBC.CDL.Logical.And Buildings.Controls.OBC.CDL.Logical.And

Logical 'and': y = u1 and u2

Buildings.Controls.OBC.CDL.Logical.And

Information

Block that outputs true if all inputs are true. Otherwise the output is false.

Connectors

TypeNameDescription
input BooleanInputu1Input signal for logical 'and'
input BooleanInputu2Input signal for logical 'and'
output BooleanOutputyOutputs true if u1 and u2 are both true

Modelica definition

block And "Logical 'and': y = u1 and u2" Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1 "Input signal for logical 'and'"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2 "Input signal for logical 'and'"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Outputs true if u1 and u2 are both true"; equation y=u1 and u2; end And;

Buildings.Controls.OBC.CDL.Logical.Change Buildings.Controls.OBC.CDL.Logical.Change

Output y is true, if the input u has a rising or falling edge (y = change(u))

Buildings.Controls.OBC.CDL.Logical.Change

Information

Block that outputs true if the Boolean input has either a rising edge from false to true or a falling edge from true to false. Otherwise the output is false.

Parameters

TypeNameDefaultDescription
Booleanpre_u_startfalseStart value of pre(u) at initial time

Connectors

TypeNameDescription
input BooleanInputuInput to be monitored for a change
output BooleanOutputyOutput with true when the input changes

Modelica definition

block Change "Output y is true, if the input u has a rising or falling edge (y = change(u))" parameter Boolean pre_u_start=false "Start value of pre(u) at initial time"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u "Input to be monitored for a change"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output with true when the input changes"; initial equation pre(u)=pre_u_start; equation y=change(u); end Change;

Buildings.Controls.OBC.CDL.Logical.Edge Buildings.Controls.OBC.CDL.Logical.Edge

Output y is true, if the input u has a rising edge (y = edge(u))

Buildings.Controls.OBC.CDL.Logical.Edge

Information

Block that outputs true if the Boolean input has a rising edge from false to true. Otherwise the output is false.

Parameters

TypeNameDefaultDescription
Booleanpre_u_startfalseStart value of pre(u) at initial time

Connectors

TypeNameDescription
input BooleanInputuInput to be monitored
output BooleanOutputyOutputs true when the input switches to true

Modelica definition

block Edge "Output y is true, if the input u has a rising edge (y = edge(u))" parameter Boolean pre_u_start=false "Start value of pre(u) at initial time"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u "Input to be monitored"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Outputs true when the input switches to true"; initial equation pre(u)=pre_u_start; equation y=edge(u); end Edge;

Buildings.Controls.OBC.CDL.Logical.FallingEdge Buildings.Controls.OBC.CDL.Logical.FallingEdge

Output y is true, if the input u has a falling edge (y = edge(not u))

Buildings.Controls.OBC.CDL.Logical.FallingEdge

Information

Block that outputs true if the Boolean input has a falling edge from true to false. Otherwise the output is false.

Parameters

TypeNameDefaultDescription
Booleanpre_u_startfalseStart value of pre(u) at initial time

Connectors

TypeNameDescription
input BooleanInputuInput to be monitored
output BooleanOutputyOutputs true when the input switches to false

Modelica definition

block FallingEdge "Output y is true, if the input u has a falling edge (y = edge(not u))" parameter Boolean pre_u_start=false "Start value of pre(u) at initial time"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u "Input to be monitored"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Outputs true when the input switches to false"; protected Boolean not_u=not u "Boolean not of the input"; initial equation pre(not_u)=not pre_u_start; equation y=edge(not_u); end FallingEdge;

Buildings.Controls.OBC.CDL.Logical.Latch Buildings.Controls.OBC.CDL.Logical.Latch

Maintains a true signal until cleared

Buildings.Controls.OBC.CDL.Logical.Latch

Information

Block that generates a true output when the latch input u rises from false to true, provided that the clear input clr is false or also became at the same time false. The output remains true until the clear input clr rises from false to true.

If the clear input clr is true, the output y switches to false (if it was true) and it remains false, regardless of the value of the latch input u.

At initial time, if clr = false, then the output will be y = u. Otherwise it will be y=false (because the clear input clr is true).

Latch.png

Connectors

TypeNameDescription
input BooleanInputuLatch input
input BooleanInputclrClear input
output BooleanOutputyOutput with latched signal

Modelica definition

block Latch "Maintains a true signal until cleared" Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u "Latch input"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput clr "Clear input"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output with latched signal"; equation when initial() then y=not clr and u; elsewhen {clr, u} then y=not clr and u; end when; end Latch;

Buildings.Controls.OBC.CDL.Logical.MultiAnd Buildings.Controls.OBC.CDL.Logical.MultiAnd

Logical MultiAnd, y = u[1] and u[2] and u[3] and ...

Buildings.Controls.OBC.CDL.Logical.MultiAnd

Information

Block that outputs y = true if and only if all elements of the input vector u are true. If no connection to the input connector u is present, the output is y=false.

See Buildings.Controls.OBC.CDL.Logical.Validation.MultiAnd for an example.

Connectors

TypeNameDescription
input BooleanInputu[nin]Input signals
output BooleanOutputyOutput with true if all input signals are true

Modelica definition

block MultiAnd "Logical MultiAnd, y = u[1] and u[2] and u[3] and ..." parameter Integer nin(min=0)=0 "Number of input connections"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u[nin] "Input signals"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output with true if all input signals are true"; protected Boolean uTemp[nin] "Temporary variable"; equation if size(u, 1) > 1 then uTemp[1]=u[1]; for i in 2:size(u, 1) loop uTemp[i]=u[i] and uTemp[i-1]; end for; y=uTemp[nin]; elseif (size(u, 1) == 1) then uTemp[1]=u[1]; y=uTemp[1]; else y=false; end if; end MultiAnd;

Buildings.Controls.OBC.CDL.Logical.MultiOr Buildings.Controls.OBC.CDL.Logical.MultiOr

Logical MultiOr, y = u[1] or u[2] or u[3] or ...

Buildings.Controls.OBC.CDL.Logical.MultiOr

Information

Block that outputs y = true if any element in the input vector u is true. If no connection to the input connector u is present, the output is y=false.

See Buildings.Controls.OBC.CDL.Logical.Validation.MultiOr for an example.

Connectors

TypeNameDescription
input BooleanInputu[nin]Input signals
output BooleanOutputyOutput with true if at least one input is true

Modelica definition

block MultiOr "Logical MultiOr, y = u[1] or u[2] or u[3] or ..." parameter Integer nin(min=0)=0 "Number of input connections"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u[nin] "Input signals"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output with true if at least one input is true"; protected Boolean uTemp[nin] "Temporary variable"; equation if size(u, 1) > 1 then uTemp[1]=u[1]; for i in 2:size(u, 1) loop uTemp[i]=u[i] or uTemp[i-1]; end for; y=uTemp[nin]; elseif (size(u, 1) == 1) then uTemp[1]=u[1]; y=uTemp[1]; else y=false; end if; end MultiOr;

Buildings.Controls.OBC.CDL.Logical.Nand Buildings.Controls.OBC.CDL.Logical.Nand

Logical 'nand': y = not (u1 and u2)

Buildings.Controls.OBC.CDL.Logical.Nand

Information

Block that outputs true if at least one input is false. Otherwise the output is false.

Connectors

TypeNameDescription
input BooleanInputu1Input signal for 'nand'
input BooleanInputu2Input signal for 'nand'
output BooleanOutputyOutput with false if both inputs are true

Modelica definition

block Nand "Logical 'nand': y = not (u1 and u2)" Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1 "Input signal for 'nand'"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2 "Input signal for 'nand'"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output with false if both inputs are true"; equation y=not (u1 and u2); end Nand;

Buildings.Controls.OBC.CDL.Logical.Nor Buildings.Controls.OBC.CDL.Logical.Nor

Logical 'nor': y = not (u1 or u2)

Buildings.Controls.OBC.CDL.Logical.Nor

Information

Block that outputs true if none of the inputs is true. Otherwise the output is false.

Connectors

TypeNameDescription
input BooleanInputu1Input signal for 'nor'
input BooleanInputu2Input signal for 'nor'
output BooleanOutputyOutput with false if at least one of the inputs is true

Modelica definition

block Nor "Logical 'nor': y = not (u1 or u2)" Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1 "Input signal for 'nor'"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2 "Input signal for 'nor'"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output with false if at least one of the inputs is true"; equation y=not (u1 or u2); end Nor;

Buildings.Controls.OBC.CDL.Logical.Not Buildings.Controls.OBC.CDL.Logical.Not

Logical not

Buildings.Controls.OBC.CDL.Logical.Not

Information

Block that outputs true if the input is false, and false if the input is true.

Connectors

TypeNameDescription
input BooleanInputuInput to be negated
output BooleanOutputyOutput with negated input

Modelica definition

block Not "Logical not" Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u "Input to be negated"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output with negated input"; equation y=not u; end Not;

Buildings.Controls.OBC.CDL.Logical.Or Buildings.Controls.OBC.CDL.Logical.Or

Logical 'or': y = u1 or u2

Buildings.Controls.OBC.CDL.Logical.Or

Information

Block that outputs true if at least one input is true. Otherwise the output is false.

Connectors

TypeNameDescription
input BooleanInputu1Input for logical 'or'
input BooleanInputu2Input for logical 'or'
output BooleanOutputyOutput with true if at least one of the inputs is true

Modelica definition

block Or "Logical 'or': y = u1 or u2" Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1 "Input for logical 'or'"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2 "Input for logical 'or'"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output with true if at least one of the inputs is true"; equation y=u1 or u2; end Or;

Buildings.Controls.OBC.CDL.Logical.Pre Buildings.Controls.OBC.CDL.Logical.Pre

Breaks algebraic loops by adding a delay of the output without advancing time (y = pre(u): event iteration continues until u = pre(u))

Buildings.Controls.OBC.CDL.Logical.Pre

Information

This block delays the Boolean input by an infinitesimal small time delay and therefore breaks algebraic loops. In a network of logical blocks, in every closed connection loop, at least one logical block must have a delay, since algebraic systems of Boolean equations are not solvable.

This block returns the value of the input signal u from the last event iteration. The event iteration stops once both values are identical, i.e., if u = pre(u).

Parameters

TypeNameDefaultDescription
Booleanpre_u_startfalseStart value of pre(u) at initial time

Connectors

TypeNameDescription
input BooleanInputuInput to be delayed by one event iteration
output BooleanOutputyInput delayed by one event iteration

Modelica definition

block Pre "Breaks algebraic loops by adding a delay of the output without advancing time (y = pre(u): event iteration continues until u = pre(u))" parameter Boolean pre_u_start=false "Start value of pre(u) at initial time"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u "Input to be delayed by one event iteration"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Input delayed by one event iteration"; initial equation pre(u)=pre_u_start; equation y=pre(u); end Pre;

Buildings.Controls.OBC.CDL.Logical.Proof Buildings.Controls.OBC.CDL.Logical.Proof

Verify two boolean inputs

Buildings.Controls.OBC.CDL.Logical.Proof

Information

Block that compares a boolean set point u_s with a measured signal u_m and produces two outputs that may be used to raise alarms about malfunctioning equipment.

The block sets the output yLocFal = true if the set point is u_s = true but the measured signal is locked at false, i.e., u_m = false. Similarly, the block sets the output yLocTru = true if the set point is u_s = false but the measured signal is locked at true, i.e., u_m = true. Hence, any output being true indicates an operational problem.

To use this block, proceed as follows: Set the parameter feedbackDelay ≥ 0 to specify how long the feedback of the controlled device is allowed to take to report its measured operational signal u_s after a set point change u_m. Set the parameter debounce ≥ 0 to specify how long the measured signal u_m need to remain constant for it to be considered stable. Connect the inputs for the set point u_s and the measured signal u_m to the output signals that need to be checked. If either output is true, raise an alarm, such as by connecting instances of Buildings.Controls.OBC.CDL.Utilities.Assert to the outputs of this block.

Any output being true indicates a problem.

The block has two timers that each start whenever the corresponding input changes. One timer, called feedbackDelay+debounce timer, starts whenever the set point u_s change, and it runs for a time equal to feedbackDelay+debounce. The other timer, called debounce timer, starts whenever the measured signal u_m changes, and it runs for a time equal to debounce. The block starts verifying the inputs whenever the feedbackDelay+debounce timer lapsed, or the debounce timer lapsed, (and hence the measurement is stable,) whichever is first.

Both outputs being true indicates that the measured signal u_m is not stable within feedbackDelay+debounce time. Exactly one output being true indicates that the measured signal u_m is stable, but u_s ≠ u_m. In this case, the block sets yLocFal = true if u_s = true (the measured signal is locked at false), or it sets yLocTru = true if u_s = false (the measured signal is locked at true).

Therefore, exactly one output being true can be interpreted as follows: Suppose true means on and false means off.
Then, yLocTru = true indicates that an equipment is locked in operation mode but is commanded off; and similarly, yLocFal = true indicates that it is locked in off mode when it is commanded on.

Detailed description

The block works as follows. Any change in set point u_s starts the feedbackDelay+debounce timer, and any change in measured signal u_m starts the debounce timer.

As soon as the feedbackDelay+debounce timer or the debounce timer lapsed, whichever happens first, the controller continuously performs these checks:

  1. Check for stable measured signal.
    If u_m is stable, then
        goto step 2.
    Else:
        Set yLocFal = yLocTru = true.
        (Equipment is commanded on but we cannot conclude it is running;
        set both true to flag an unstable measurement signal.)
  2. Check for commanded and measured input to be equal.
    If u_s ≠ u_m, then
        goto step 3.
    Else,
        set yLocFal = false and yLocTru = false.
        (Equipment is operating as commanded, verified using stable input.)
  3. Inputs differ.
    If u_s = true , then
        set yLocFal = true and yLocTru = false.
        (The equipment is commanded on, but it is off.)
    Else,
        set yLocFal = false and yLocTru = true.
        (The equipment is commanded off, but it is on.)

Parameters

TypeNameDefaultDescription
Realdebounce Time during which input must remain unchanged for signal to considered valid and used in checks [s]
RealfeedbackDelay Delay after which the two inputs are checked for equality once they become valid [s]

Connectors

TypeNameDescription
input BooleanInputu_sCommanded status setpoint
input BooleanInputu_mMeasured status
output BooleanOutputyLocFalOutput with true if the measured input is locked to false even after the setpoint has changed to true
output BooleanOutputyLocTruOutput with true if the measured input is locked to true even after the setpoint has changed to false

Modelica definition

block Proof "Verify two boolean inputs" parameter Real debounce( final quantity="Time", final unit="s") "Time during which input must remain unchanged for signal to considered valid and used in checks"; parameter Real feedbackDelay( final quantity="Time", final unit="s") "Delay after which the two inputs are checked for equality once they become valid"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u_s "Commanded status setpoint"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u_m "Measured status"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yLocFal "Output with true if the measured input is locked to false even after the setpoint has changed to true"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yLocTru "Output with true if the measured input is locked to true even after the setpoint has changed to false"; protected Buildings.Controls.OBC.CDL.Logical.Or valInp "Output true if the input becomes stable after the delay time"; Buildings.Controls.OBC.CDL.Logical.And invInp "Output true if debounce time has passed and there is still no stable input"; Buildings.Controls.OBC.CDL.Logical.Or pasDel "Output true if the feedback checking time has passed"; Buildings.Controls.OBC.CDL.Logical.Or cheDif "Output true if the measured input is stable, or the feedback checking time has passed"; Buildings.Controls.OBC.CDL.Logical.And botTru "Output true if both valid measured input and the setpoint input are true"; Buildings.Controls.OBC.CDL.Logical.And truFal "Output true if the setpoint input is true but the valid measured input is false"; Buildings.Controls.OBC.CDL.Logical.TrueDelay valTru( final delayTime=debounce) "Valid measured input change from false to true"; Buildings.Controls.OBC.CDL.Logical.Switch valFal "Output false if measured input is stable and changed from true to false"; Buildings.Controls.OBC.CDL.Logical.Switch cheDif1 "Output the difference check result if the difference check condition is satisfied"; Buildings.Controls.OBC.CDL.Logical.TrueDelay truDel1( final delayTime=debounce) "Delay a rising edge, to check if the false input is valid"; Buildings.Controls.OBC.CDL.Logical.Not not1 "Logical not"; Buildings.Controls.OBC.CDL.Logical.Not notBotFal "Not both false inputs"; Buildings.Controls.OBC.CDL.Logical.Not not2 "Logical not"; Buildings.Controls.OBC.CDL.Logical.And falTru "Output true if the setpoint input is false but the valid measured input is true"; Buildings.Controls.OBC.CDL.Logical.TrueDelay delChe1( final delayTime=feedbackDelay + debounce) "Delay the difference check"; Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt "Convert boolean input to integer output"; Buildings.Controls.OBC.CDL.Integers.Equal equSta "Output true if both inputs are same"; Buildings.Controls.OBC.CDL.Conversions.BooleanToInteger booToInt1 "Convert boolean input to integer output"; Buildings.Controls.OBC.CDL.Logical.And botFal "Output true if both valid measured input and the setpoint input are false"; Buildings.Controls.OBC.CDL.Logical.Sources.Constant conTru( final k=true) "True constant"; Buildings.Controls.OBC.CDL.Logical.Not not3 "Input is invalid"; Buildings.Controls.OBC.CDL.Logical.Switch cheStaMea "Output true if there is no stable measured input"; Buildings.Controls.OBC.CDL.Logical.TrueDelay delChe2( final delayTime=feedbackDelay + debounce) "Delay the difference check"; Buildings.Controls.OBC.CDL.Logical.Sources.Constant conFal( final k=false) "False constant"; Buildings.Controls.OBC.CDL.Logical.Not notBotTru "Not both true inputs"; Buildings.Controls.OBC.CDL.Logical.Switch cheDif2 "Output the difference check result if the difference check condition is satisfied"; Buildings.Controls.OBC.CDL.Logical.Switch cheStaMea1 "Output true if there is no stable measured input"; Buildings.Controls.OBC.CDL.Logical.Timer pasDeb( final t=feedbackDelay + debounce) "Check if the debounce time has passed"; Buildings.Controls.OBC.CDL.Logical.Latch holTru "Hold the true output when the input changes to true"; Buildings.Controls.OBC.CDL.Logical.Latch holTru1 "Hold the true output when the input changes to true"; Buildings.Controls.OBC.CDL.Logical.Or equInp "Output true if the measured input equal to the set point"; Buildings.Controls.OBC.CDL.Logical.Edge samInpEdg "Output a rising edge when both inputs are same"; Buildings.Controls.OBC.CDL.Logical.And valEqu "Output true if the measured input is valid and equal to the set point"; initial equation assert( feedbackDelay >= debounce, "In " + getInstanceName() + ": Require feedbackDelay >= debounce, setting feedbackDelay = debounce.", level=AssertionLevel.warning); equation connect(u_m, valTru.u); connect(u_m, not1.u); connect(not1.y, truDel1.u); connect(valTru.y, valInp.u1); connect(truDel1.y, valInp.u2); connect(truDel1.y, valFal.u2); connect(u_m, valFal.u1); connect(conTru.y, valFal.u3); connect(valInp.y, not3.u); connect(not3.y, invInp.u1); connect(conTru.y, cheStaMea.u1); connect(u_s, not2.u); connect(not2.y, delChe1.u); connect(u_s, delChe2.u); connect(delChe2.y, pasDel.u1); connect(delChe1.y, pasDel.u2); connect(valInp.y, cheDif.u2); connect(pasDel.y, cheDif.u1); connect(cheDif.y, cheDif1.u2); connect(botTru.y, notBotTru.u); connect(notBotTru.y, truFal.u1); connect(valTru.y, botTru.u1); connect(u_s, truFal.u2); connect(u_s, booToInt1.u); connect(valFal.y, booToInt.u); connect(booToInt.y, equSta.u1); connect(booToInt1.y, equSta.u2); connect(not2.y, botFal.u1); connect(equSta.y, botFal.u2); connect(botFal.y, notBotFal.u); connect(notBotFal.y, falTru.u1); connect(not2.y, falTru.u2); connect(cheDif1.y, cheStaMea.u3); connect(cheDif.y, cheDif2.u2); connect(cheDif2.y, cheStaMea1.u3); connect(conTru.y, cheStaMea1.u1); connect(conFal.y, cheDif1.u3); connect(conFal.y, cheDif2.u3); connect(falTru.y, cheDif2.u1); connect(truFal.y, cheDif1.u1); connect(u_s, botTru.u2); connect(cheStaMea.y, holTru.u); connect(cheStaMea1.y, holTru1.u); connect(holTru.y, yLocFal); connect(holTru1.y, yLocTru); connect(botTru.y, equInp.u1); connect(equSta.y, equInp.u2); connect(samInpEdg.y, holTru.clr); connect(samInpEdg.y, holTru1.clr); connect(invInp.y, cheStaMea.u2); connect(invInp.y, cheStaMea1.u2); connect(not3.y, pasDeb.u); connect(pasDeb.passed, invInp.u2); connect(equInp.y, valEqu.u1); connect(valEqu.y, samInpEdg.u); connect(valInp.y, valEqu.u2); end Proof;

Buildings.Controls.OBC.CDL.Logical.Switch Buildings.Controls.OBC.CDL.Logical.Switch

Switch between two boolean signals

Buildings.Controls.OBC.CDL.Logical.Switch

Information

Block that outputs one of two boolean input signals based on a boolean input signal.

If the input signal u2 is true, the block outputs y = u1. Otherwise, it outputs y = u3.

Connectors

TypeNameDescription
input BooleanInputu1Input u1
input BooleanInputu2Boolean switch input signal, if true, y=u1, else y=u3
input BooleanInputu3Input u3
output BooleanOutputyOutput with u1 if u2 is true, else u3

Modelica definition

block Switch "Switch between two boolean signals" Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1 "Input u1"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2 "Boolean switch input signal, if true, y=u1, else y=u3"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u3 "Input u3"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output with u1 if u2 is true, else u3"; equation y=if u2 then u1 else u3; end Switch;

Buildings.Controls.OBC.CDL.Logical.Timer Buildings.Controls.OBC.CDL.Logical.Timer

Timer measuring the time from the time instant where the Boolean input became true

Buildings.Controls.OBC.CDL.Logical.Timer

Information

If the Boolean input u is true, the output y is the time that has elapsed since u became true. Otherwise, y is 0. If the output y becomes greater than the threshold time t, the output passed is true. Otherwise it is false.

In the limiting case where the timer value reaches the threshold t and the input u becomes false simultaneously, the output passed remains false.

Parameters

TypeNameDefaultDescription
Realt0Threshold time for comparison [s]

Connectors

TypeNameDescription
input BooleanInputuInput that switches timer on if true, and off if false
output RealOutputyElapsed time [s]
output BooleanOutputpassedOutput with true if the elapsed time is greater than threshold

Modelica definition

block Timer "Timer measuring the time from the time instant where the Boolean input became true" parameter Real t( final quantity="Time", final unit="s")=0 "Threshold time for comparison"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u "Input that switches timer on if true, and off if false"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y( final quantity="Time", final unit="s") "Elapsed time"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput passed "Output with true if the elapsed time is greater than threshold"; protected discrete Real entryTime( final quantity="Time", final unit="s") "Time instant when u became true"; initial equation pre(entryTime)=time; pre(passed)=t <= 0; equation when u then entryTime=time; // When u becomes true, and t=0, we want passed to be true // at the first step (in superdense time). passed=t <= 0; elsewhen(u and time >= t+pre(entryTime)) then passed=true; entryTime=pre(entryTime); elsewhen not u then // Set passed to false. // This is the behavior a timer would have if the threshold test is done with a greater block connected to the output of the timer passed=false; entryTime=pre(entryTime); end when; y=if u then time-entryTime else 0.0; end Timer;

Buildings.Controls.OBC.CDL.Logical.TimerAccumulating Buildings.Controls.OBC.CDL.Logical.TimerAccumulating

Accumulating timer that can be reset

Buildings.Controls.OBC.CDL.Logical.TimerAccumulating

Information

Timer that accumulates time until it is reset by an input signal.

If the Boolean input u is true, the output y is the time that has elapsed while u has been true since the last time reset became true. If u is false, the output y holds its value. If the output y becomes greater than the threshold time t, the output passed is true. Otherwise it is false.

When reset becomes true, the timer is reset to 0.

In the limiting case where the timer value reaches the threshold t and the input u becomes false simultaneously, the output passed remains false.

Parameters

TypeNameDefaultDescription
Realt0Threshold time for comparison [s]

Connectors

TypeNameDescription
input BooleanInputuInput that switches timer on if true, and off if false
input BooleanInputresetConnector for signal that sets timer to zero if it switches to true
output RealOutputyElapsed time [s]
output BooleanOutputpassedOutput with true if the elapsed time is greater than threshold

Modelica definition

block TimerAccumulating "Accumulating timer that can be reset" parameter Real t( final quantity="Time", final unit="s")=0 "Threshold time for comparison"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u "Input that switches timer on if true, and off if false"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput reset "Connector for signal that sets timer to zero if it switches to true"; Buildings.Controls.OBC.CDL.Interfaces.RealOutput y( final quantity="Time", final unit="s") "Elapsed time"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput passed "Output with true if the elapsed time is greater than threshold"; protected discrete Real entryTime( final quantity="Time", final unit="s") "Time instant when u became true"; discrete Real yAcc( final quantity="Time", final unit="s") "Accumulated time up to last change to true"; initial equation pre(u)=false; pre(reset)=false; pre(entryTime)=time; pre(passed)=t <= 0; yAcc=0; equation // The when constructs below are identical to the ones in Buildings.Controls.OBC.CDL.Logical.Timer when reset then entryTime=time; passed=t <= 0; yAcc=0; elsewhen u then entryTime=time; // When u becomes true, and t=0, we want passed to be true // at the first step (in superdense time). passed=t <= yAcc; yAcc=pre(yAcc); elsewhen u and time >= t+pre(entryTime)-pre(yAcc) then passed=true; entryTime=pre(entryTime); yAcc=pre(yAcc); elsewhen not u then passed=pre(passed); //time >= t_internal + pre(entryTime); entryTime=pre(entryTime); yAcc=pre(y); end when; y=if u then yAcc+time-entryTime else yAcc; end TimerAccumulating;

Buildings.Controls.OBC.CDL.Logical.Toggle Buildings.Controls.OBC.CDL.Logical.Toggle

Toggles output value whenever its input turns true

Buildings.Controls.OBC.CDL.Logical.Toggle

Information

Block that generates a true output when toggle input u rises from false to true, provided that the clear input clr is false or also became at the same time false. The output remains true until

If the clear input clr is true, the output y switches to false (if it was true) and it remains false, regardless of the value of the toggle input u.

At initial time, if clr = false, then the output will be y = u. Otherwise it will be y=false (because the clear input clr is true).

Toggle.png

Connectors

TypeNameDescription
input BooleanInputuToggle input
input BooleanInputclrClear input
output BooleanOutputyOutput with toggled signal

Modelica definition

block Toggle "Toggles output value whenever its input turns true" Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u "Toggle input"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput clr "Clear input"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output with toggled signal"; initial equation pre(y)=false; pre(u)=false; pre(clr)=false; equation when initial() then //scenario = 1 y=if clr then false else u; elsewhen (not clr) and change(u) and (pre(u) == false) and (pre(y) == false) then //scenario = 2 y=true; elsewhen (not clr) and change(u) and (pre(u) == false) and (pre(y) == true) then //scenario = 3 y=false; elsewhen (not clr) and change(u) and (pre(u) == true) then //scenario = 4 y=pre(y); elsewhen clr then //scenario = 5 y=false; end when; end Toggle;

Buildings.Controls.OBC.CDL.Logical.TrueDelay Buildings.Controls.OBC.CDL.Logical.TrueDelay

Delay a rising edge of the input, but do not delay a falling edge

Buildings.Controls.OBC.CDL.Logical.TrueDelay

Information

Block that delays a signal when it becomes true.

A rising edge of the Boolean input u gives a delayed output. A falling edge of the input is immediately given to the output. If delayOnInit = true, then a true input signal at the start time is also delayed, otherwise the input signal is produced immediately at the output.

Simulation results of a typical example with a delay time of 0.1 second is shown below.

OnDelay1.png
OnDelay2.png

Parameters

TypeNameDefaultDescription
RealdelayTime Delay time [s]
BooleandelayOnInitfalseSet to true to delay initial true input

Connectors

TypeNameDescription
input BooleanInputuInput signal to be delayed when it switches to true
output BooleanOutputyOutput with delayed input signal after it switched to true

Modelica definition

block TrueDelay "Delay a rising edge of the input, but do not delay a falling edge" parameter Real delayTime( final quantity="Time", final unit="s") "Delay time"; parameter Boolean delayOnInit=false "Set to true to delay initial true input"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u "Input signal to be delayed when it switches to true"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output with delayed input signal after it switched to true"; protected parameter Real t_past( final quantity="Time", final unit="s", fixed=false) "Time before simulation started"; Real t_next( final quantity="Time", final unit="s") "Next event time"; initial equation t_past=time-1000; pre(u)=false; pre(t_next)=time-1000; equation when initial() then t_next=if not delayOnInit then t_past else time+delayTime; y=if not (delayOnInit and delayTime > 0) then u else false; elsewhen u then t_next=time+delayTime; y=if delayTime > 0 then false else true; elsewhen not u then t_next=t_past; y=false; elsewhen time >= pre(t_next) then t_next=t_past; y=u; end when; end TrueDelay;

Buildings.Controls.OBC.CDL.Logical.TrueFalseHold Buildings.Controls.OBC.CDL.Logical.TrueFalseHold

Block that holds an output signal for at least a specified duration

Buildings.Controls.OBC.CDL.Logical.TrueFalseHold

Information

Block that holds a true or false signal for at least a defined time period.

Whenever the input u switches to true (resp. false), the output y switches and remains true for at least the duration specified by the parameter trueHoldDuration (resp. falseHoldDuration). After this duration has elapsed, the output will be y = u.

This block could for example be used to disable an economizer, and not re-enable it for 10 min, and vice versa.

Simulation results of a typical example with trueHoldDuration = falseHoldDuration = 1000 s.

Input and output of the block

Parameters

TypeNameDefaultDescription
RealtrueHoldDuration Duration of true hold [s]
RealfalseHoldDurationtrueHoldDurationDuration of false hold [s]

Connectors

TypeNameDescription
input BooleanInputuInput signal that is to be delayed
output BooleanOutputyOutput with delayed input signal

Modelica definition

block TrueFalseHold "Block that holds an output signal for at least a specified duration" parameter Real trueHoldDuration( final quantity="Time", final unit="s") "Duration of true hold"; parameter Real falseHoldDuration( final quantity="Time", final unit="s")=trueHoldDuration "Duration of false hold"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u "Input signal that is to be delayed"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output with delayed input signal"; protected /* The following parameter is required solely as a warkaround for a bug in OCT [Modelon - 1263]. Both Dymola and OMC can handle the initial equation pre(u)=u, which complies with MLS. */ parameter Boolean pre_u_start=false "Value of pre(u) at initial time"; Boolean not_u = not u "Opposite of u"; Boolean not_y = not y "Opposite of y"; discrete Real entryTimeTrue( final quantity="Time", final unit="s") "Time instant when true hold started"; discrete Real entryTimeFalse( final quantity="Time", final unit="s") "Time instant when false hold started"; initial equation pre(entryTimeTrue) = -Modelica.Constants.inf; pre(entryTimeFalse) = -Modelica.Constants.inf; pre(u) = pre_u_start; pre(not_u) = not pre_u_start; pre(y) = u; pre(not_y) = not u; equation when initial() then y = u; entryTimeTrue = if y then time else pre(entryTimeTrue); entryTimeFalse = if not y then time else pre(entryTimeFalse); elsewhen {edge(u), edge(not_u), time >= pre(entryTimeFalse) + falseHoldDuration and time >= pre(entryTimeTrue) + trueHoldDuration} then y=if time >= pre(entryTimeFalse) + falseHoldDuration and time >= pre(entryTimeTrue) + trueHoldDuration then u else pre(y); entryTimeTrue = if edge(y) then time else pre(entryTimeTrue); entryTimeFalse = if edge(not_y) then time else pre(entryTimeFalse); end when; end TrueFalseHold;

Buildings.Controls.OBC.CDL.Logical.VariablePulse Buildings.Controls.OBC.CDL.Logical.VariablePulse

Generate boolean pulse with the width specified by input

Buildings.Controls.OBC.CDL.Logical.VariablePulse

Information

Block that outputs a boolean pulse.

The output of this block is a pulse with a constant period and a width as obtained from the input 0 ≤ u ≤ 1, which is the width relative to the period.

The block produces the following ouputs:

When the input u changes by more than deltaU and the output has been holding constant for more than minimum holding time minTruFalHol, the output will change to a new pulse with width equal to u*period.

VariablePulse.png

Parameters

TypeNameDefaultDescription
Realperiod Time for one pulse period [s]
RealdeltaU0.01Increment of u that triggers recomputation of output [1]
RealminTruFalHol0.01*periodMinimum time to hold true or false [s]

Connectors

TypeNameDescription
input RealInputuRatio of the period that the output should be true [1]
output BooleanOutputyBoolean pulse when the input is greater than zero

Modelica definition

block VariablePulse "Generate boolean pulse with the width specified by input" parameter Real period( final quantity="Time", final unit="s") "Time for one pulse period"; parameter Real deltaU( min = 0.001, max = 0.5, final unit="1") = 0.01 "Increment of u that triggers recomputation of output"; parameter Real minTruFalHol( final quantity="Time", final unit="s", final min=Constants.small)=0.01*period "Minimum time to hold true or false"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u( final min=0, final max=1, final unit="1") "Ratio of the period that the output should be true"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Boolean pulse when the input is greater than zero"; protected parameter Real adjustedPeriod( final quantity="Time", final unit="s") = max(period, minTruFalHol*2.02) "Time for one pulse period"; Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triSam "Sample the input when there is value change"; Buildings.Controls.OBC.CDL.Reals.Subtract sub "Output the difference before and after sampling"; Buildings.Controls.OBC.CDL.Reals.Abs abs1 "Output the absolute value change"; Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr( final t=deltaU, final h=0) "Check if there is a sufficiently large change in input value"; Buildings.Controls.OBC.CDL.Logical.Edge edg2 "Rising edge when there is a width change"; Buildings.Controls.OBC.CDL.Logical.Pre preBre "Break loop"; Cycle cycOut( final period=adjustedPeriod, final minTruFalHol=minTruFalHol) "Produce boolean pulse output"; Buildings.Controls.OBC.CDL.Logical.TrueFalseHold truFalHol( final trueHoldDuration=minTruFalHol, final falseHoldDuration=minTruFalHol) "Ensure the minimum holding time"; block Cycle "Generate boolean pulse with the width specified by the input" parameter Real period( final quantity="Time", final unit="s", final min=Constants.small) "Time for one pulse period"; parameter Real minTruFalHol( final quantity="Time", final unit="s", final min=Constants.small) "Minimum time to hold true or false"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput go "True: cycle the output"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u "Ratio of the period that the output should be true"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Cycling boolean output"; discrete Real t0( final quantity="Time", final unit="s", fixed=false) "Time instant when output begins cycling"; Real t_sta( final quantity="Time", final unit="s", fixed=false) "Begin time instant of one period"; Real t_end( final quantity="Time", final unit="s", fixed=false) "End time instant of one period"; initial equation pre(t0)=time; equation when go then t0 = time; end when; t_sta = t0 + Buildings.Utilities.Math.Functions.round( x=integer((time-t0)/period)*period, n=6); t_end = t_sta + u*period; y = (time>=t_sta) and (time<t_end); end Cycle; initial equation assert(period >= minTruFalHol*2, "In " + getInstanceName() + ": The pulse period must be greater than 2 times of the minimum true and false holding time. Increasing period to " + String(adjustedPeriod) + ".", level = AssertionLevel.warning); equation connect(u, triSam.u); connect(triSam.y, sub.u1); connect(u, sub.u2); connect(sub.y, abs1.u); connect(greThr.y, edg2.u); connect(greThr.y, preBre.u); connect(preBre.y, triSam.trigger); connect(u, cycOut.u); connect(cycOut.y, truFalHol.u); connect(truFalHol.y, y); connect(abs1.y, greThr.u); connect(edg2.y, cycOut.go); end VariablePulse;

Buildings.Controls.OBC.CDL.Logical.Xor Buildings.Controls.OBC.CDL.Logical.Xor

Logical 'xor': y = u1 xor u2

Buildings.Controls.OBC.CDL.Logical.Xor

Information

Block that outputs true if exactly one input is true. Otherwise the output is false.

Connectors

TypeNameDescription
input BooleanInputu1Input for logical 'xor'
input BooleanInputu2Input for logical 'xor'
output BooleanOutputyOutput with u1 xor u2

Modelica definition

block Xor "Logical 'xor': y = u1 xor u2" Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u1 "Input for logical 'xor'"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput u2 "Input for logical 'xor'"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Output with u1 xor u2"; equation y=not ((u1 and u2) or (not u1 and not u2)); end Xor;

Buildings.Controls.OBC.CDL.Logical.VariablePulse.Cycle Buildings.Controls.OBC.CDL.Logical.VariablePulse.Cycle

Generate boolean pulse with the width specified by the input

Buildings.Controls.OBC.CDL.Logical.VariablePulse.Cycle

Parameters

TypeNameDefaultDescription
Realperiod Time for one pulse period [s]
RealminTruFalHol Minimum time to hold true or false [s]

Connectors

TypeNameDescription
input BooleanInputgoTrue: cycle the output
input RealInputuRatio of the period that the output should be true
output BooleanOutputyCycling boolean output

Modelica definition

block Cycle "Generate boolean pulse with the width specified by the input" parameter Real period( final quantity="Time", final unit="s", final min=Constants.small) "Time for one pulse period"; parameter Real minTruFalHol( final quantity="Time", final unit="s", final min=Constants.small) "Minimum time to hold true or false"; Buildings.Controls.OBC.CDL.Interfaces.BooleanInput go "True: cycle the output"; Buildings.Controls.OBC.CDL.Interfaces.RealInput u "Ratio of the period that the output should be true"; Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y "Cycling boolean output"; discrete Real t0( final quantity="Time", final unit="s", fixed=false) "Time instant when output begins cycling"; Real t_sta( final quantity="Time", final unit="s", fixed=false) "Begin time instant of one period"; Real t_end( final quantity="Time", final unit="s", fixed=false) "End time instant of one period"; initial equation pre(t0)=time; equation when go then t0 = time; end when; t_sta = t0 + Buildings.Utilities.Math.Functions.round( x=integer((time-t0)/period)*period, n=6); t_end = t_sta + u*period; y = (time>=t_sta) and (time<t_end); end Cycle;