Generate a clock signal when the Boolean input changes from false to true. This component generates a clock signal triggered by a continuous-time
Boolean input signal u: Whenever the Boolean input signal u
changes from false to true, then the output
clock signal y ticks.

within Modelica.Clocked.ClockSignals.Clocks;
block EventClock
  "Generate a clock signal when the Boolean input changes from false to true"
  extends Clocked.ClockSignals.Interfaces.PartialClock;
  Modelica.Blocks.Interfaces.BooleanInput u
equation
  if useSolver then
     y = Clock(Clock(u), solverMethod=solverMethod);
  else
     y = Clock(u);
  end if;
end EventClock;


Library of blocks that generate clocks

within Modelica.Clocked.ClockSignals;
package Clocks "Library of blocks that generate clocks"
  extends Modelica.Icons.SourcesPackage;
end Clocks;


Generate a periodic clock signal with a period defined by an Integer number with resolution. This component generates a periodic clock that starts ticking when
the simulation starts. The period is defined as the product
of a resolution, defined with enumeration
Resolution,
and Integer parameter factor. Internally, the period is
represented as a rational number. All clocks with rational number definitions
are exactly time synchronized to each other.

within Modelica.Clocked.ClockSignals.Clocks;
block PeriodicExactClock
  "Generate a periodic clock signal with a period defined by an Integer number with resolution"
  import Modelica.Clocked.Types.Resolution;

  parameter Integer factor(min=0)
    "Sample factor with respect to resolution"
  parameter Clocked.Types.Resolution resolution=Resolution.ms "Clock resolution"
  extends Clocked.ClockSignals.Interfaces.PartialPeriodicClock;
protected
  constant Integer conversionTable[8]={365*24*60*60, 24*60*60, 60*60, 60, 1, 1000, 1000*1000, 1000*1000*1000}
    "Table to convert from Resolution to Integer clock resolution";
  parameter Integer resolutionFactor = conversionTable[Integer(resolution)]
  Clock c
equation
  // The following then-branch using subSample corresponds to the simpler Clock(factor*resolutionFactor, 1),
  // but works better in some odd cases.
  //
  // Specifically the simple variant may fail if the product exceeds 2^31 (seconds), roughly 68 years.
  //
  // Using subSample works reliably up to 2^31 years according to the standard.
  //
  // There is no similar issue with the else-branch.
  if resolution < Resolution.s then
     c = subSample(Clock(factor), resolutionFactor);
  else
     c = Clock(factor, resolutionFactor);
  end if;

  if useSolver then
     y = Clock(c, solverMethod=solverMethod);
  else
     y = c;
  end if;
// Clock ticks every 1/100 seconds

For an introduction to clocks see
UsersGuide.Clocks.

If a clock is associated to a clocked continuous-time partition, then an integrator
has to be defined that is used to integrate the partition from the previous
to the current clock tick. This is performed by setting parameter useSolver
= true and defining the integration method as String with
parameter solver. Both parameters are in tab Advanced.
For an example, see
Examples.Systems.ControlledMixingUnit.

"));
end PeriodicExactClock;


Generate a periodic clock signal with a period defined by a Real number. This component generates a periodic clock that starts ticking when
the simulation starts. The period is defined in seconds
by a Real number. If clocks are synchronized relatively to each other
then only one of the clocks can be defined with PeriodicRealClock.

within Modelica.Clocked.ClockSignals.Clocks;
block PeriodicRealClock
  "Generate a periodic clock signal with a period defined by a Real number"
  parameter SI.Time period
    "Period of clock (defined as Real number)"
  extends Clocked.ClockSignals.Interfaces.PartialPeriodicClock;
equation
  if useSolver then
     y = Clock(Clock(period), solverMethod=solverMethod);
  else
     y = Clock(period);
  end if;
end PeriodicRealClock;


Logical clock ticking whenever all input clocks ticked at least once, then resets and starts the next conjunctive cycle.

within Modelica.Clocked.ClockSignals.Clocks.Logical;
block ConjunctiveClock
  "Logical clock ticking whenever all input clocks ticked at least once, then resets and starts the next conjunctive cycle"
  extends PartialLogicalClock(
    redeclare Modelica.Blocks.MathBoolean.And combinator);
end ConjunctiveClock;


Logical clock ticking whenever any of its input clock signals ticks..

within Modelica.Clocked.ClockSignals.Clocks.Logical;
block DisjunctiveClock
  "Logical clock ticking whenever any of its input clock signals ticks."
  extends PartialLogicalClock(
    redeclare Modelica.Blocks.MathBoolean.Or combinator);
end DisjunctiveClock;


within Modelica.Clocked.ClockSignals.Clocks;
package Logical "Library of blocks for combining several input clock signals by logical combinators"
  extends Modelica.Icons.Package;
end Logical;


Logical clock combining arbitrary many input clock signals according to a replaceable logical combinator.

within Modelica.Clocked.ClockSignals.Clocks.Logical;
partial block PartialLogicalClock
  "Logical clock combining arbitrary many input clock signals according to a replaceable logical combinator"
  extends Interfaces.PartialClock;

  parameter Integer nu = 2
    "Number of input connections.";

  Interfaces.ClockVectorInput u[nu]
    "Vector of Clock input signals."

  replaceable Modelica.Blocks.Interfaces.PartialBooleanMISO combinator
    constrainedby Modelica.Blocks.Interfaces.PartialBooleanMISO(
      nu = nu)
    "Replaceable logical combinator applied on vector of Clock input signals.
     Important: Must not be any kind of negation since such would result in
     infinite many ticks for an infinitesimal short time period."

  EventClock clock(useSolver=useSolver, solverMethod=solverMethod)

  // Array of input trackers:
  BooleanSignals.NonPeriodic.ClockToBoolean input_ticked[nu]
  Modelica.Blocks.Logical.And forbidden_state[nu]
  Modelica.Blocks.Sources.BooleanConstant S_false[nu](each k = false)
  Modelica.Blocks.Logical.LogicalSwitch suppress_S[nu]
  Modelica.Blocks.Logical.RSFlipFlop input_memory[nu]

  // Resetter:
  BooleanSignals.NonPeriodic.ClockToBoolean reset_ticked
  Modelica.Blocks.Routing.BooleanReplicator splitter(nout = nu)

equation
  connect(clock.y, y)
  connect(combinator.y, clock.u)
  connect(suppress_S.y, input_memory.S)
  connect(input_memory.Q, combinator.u)
  connect(S_false.y, suppress_S.u1)
  connect(splitter.y, input_memory.R)
  connect(splitter.y, forbidden_state.u1)
  connect(forbidden_state.y, suppress_S.u2)
  connect(clock.y, reset_ticked.u)
  connect(reset_ticked.y, splitter.u)
  connect(input_ticked.y, suppress_S.u3)
  connect(forbidden_state.u2, input_ticked.y)
  connect(u, input_ticked.u)
end PartialLogicalClock;


Event clock generating a clock tick each time an observed input angle changed for a certain, constant rotational-interval.

within Modelica.Clocked.ClockSignals.Clocks.Rotational;
model FixedRotationalClock
  "Event clock generating a clock tick each time an observed input angle changed for a certain, constant rotational-interval"
  extends PartialRotationalClock;

  parameter SI.Angle trigger_interval = 2*Modelica.Constants.pi
    "Rotational-interval the input angle must be changed to trigger the next clock tick";

  RotationalClock rotationalClock(useSolver=useSolver, solverMethod=solverMethod)
  Modelica.Blocks.Sources.Constant threshold(k = trigger_interval)

equation
  connect(angle, rotationalClock.angle)
  connect(threshold.y, rotationalClock.trigger_interval)
  connect(rotationalClock.y, y)
  connect(rotationalClock.direction_changed, direction_changed)
  connect(rotationalClock.direction, direction)
end FixedRotationalClock;


within Modelica.Clocked.ClockSignals.Clocks;
package Rotational "Library of blocks that generate a clock tick each time an observed input angle changes"
  extends Modelica.Icons.Package;

end Rotational;


Base class for event clocks that generate a clock tick each time an observed input angle changes.

within Modelica.Clocked.ClockSignals.Clocks.Rotational;
partial block PartialRotationalClock
  "Base class for event clocks that generate a clock tick each time an observed input angle changes"
  extends ClockSignals.Interfaces.PartialClock;

  Modelica.Blocks.Interfaces.RealInput angle(unit = "rad")
    "Input angle observed for generating clock ticks."
  Modelica.Blocks.Interfaces.IntegerOutput direction
    "Rotation direction (sign: +1 or -1). Sampled with the provided clock signal
     'y'."
  Modelica.Blocks.Interfaces.BooleanOutput direction_changed(start = false)
    "= true, if the rotation direction of the observed angle changed since the last tick of y', otherwise false. Sampled with the provided clock signal y."
end PartialRotationalClock;


Event clock generating a clock tick each time an observed input angle changed for a rotational-interval given as variable input.

within Modelica.Clocked.ClockSignals.Clocks.Rotational;
block RotationalClock
  "Event clock generating a clock tick each time an observed input angle changed for a rotational-interval given as variable input"
  extends PartialRotationalClock;

  Modelica.Blocks.Interfaces.RealInput trigger_interval(unit = "rad")
    "Rotational-interval the input angle must be changed to trigger the next clock tick"

  ClockSignals.Clocks.EventClock y_clock(
    useSolver = useSolver,
    solverMethod = solverMethod)
  RealSignals.Sampler.SampleClocked update_offset
  RealSignals.Sampler.Hold angular_offset
  Modelica.Blocks.Math.Add sub(k2 = -1)
  Modelica.Blocks.Logical.Less less
  Modelica.Blocks.Math.Abs abs2
  Modelica.Blocks.Math.Abs abs1
  Modelica.Blocks.Math.Sign direction_sign(generateEvent = false)
  Modelica.Blocks.Math.RealToInteger cast
  IntegerSignals.NonPeriodic.IntegerChange changed
  RealSignals.Sampler.SampleClocked update_direction

algorithm
  assert(trigger_interval > 0 or trigger_interval < 0,
    "The rotational-interval of rotational clocks must be non-zero.");

equation
  connect(angle, update_offset.u)
  connect(y_clock.y, update_offset.clock)
  connect(update_offset.y, angular_offset.u)
  connect(angular_offset.y,sub. u2)
  connect(less.y, y_clock.u)
  connect(y_clock.y, y)
  connect(sub.y, abs1.u)
  connect(angle, sub.u1)
  connect(trigger_interval, abs2.u)
  connect(abs1.y, less.u2)
  connect(abs2.y, less.u1)
  connect(direction_sign.y, cast.u)
  connect(cast.y, changed.u)
  connect(y_clock.y, update_direction.clock)
  connect(update_direction.y, direction_sign.u)
  connect(sub.y, update_direction.u)
  connect(changed.y, direction_changed)
  connect(cast.y, direction)
end RotationalClock;


Basic graphical layout of block where at least one input or output is a clocked variable.

within Modelica.Clocked.ClockSignals.Interfaces;
partial block ClockedBlockIcon
  "Basic graphical layout of block where at least one input or output is a clocked variable"
end ClockedBlockIcon;


within Modelica.Clocked.ClockSignals;
package Interfaces "Library of connectors and partial blocks with clock signals"
  extends Modelica.Icons.InterfacesPackage;
end Interfaces;


Icon, connector, and solver method of a block that generates a clock.

within Modelica.Clocked.ClockSignals.Interfaces;
partial block PartialClock
  "Icon, connector, and solver method of a block that generates a clock"
  parameter Boolean useSolver = false
    "= true, if solverMethod shall be explicitly defined"
  parameter ModelicaServices.Types.SolverMethod solverMethod="ExplicitEuler"
    "Integration method used for discretized continuous-time partitions"
  Clocked.ClockSignals.Interfaces.ClockOutput y
end PartialClock;


Icon, connector, and solver method of a block that generates a periodic clock.

within Modelica.Clocked.ClockSignals.Interfaces;
partial block PartialPeriodicClock
  "Icon, connector, and solver method of a block that generates a periodic clock"
  extends Clocked.ClockSignals.Interfaces.PartialClock;

end PartialPeriodicClock;


within Modelica.Clocked.ClockSignals;
package Sampler "Library of blocks that sub-, super-, shift-sample clock signals"
  extends Modelica.Icons.Package;
end Sampler;


Shift the input clock by a fraction of the last interval and provide it as output clock. This block shifts the first activation of clock output y by
fraction shiftCounter/resolution of the period (or for a non-periodic signal by a fraction of the last interval).
Here, shiftCounter and resolution are positive Integer parameters.

within Modelica.Clocked.ClockSignals.Sampler;
block ShiftSample
  "Shift the input clock by a fraction of the last interval and provide it as output clock"
  parameter Integer shiftCounter(min=0)=0 "Numerator of shifting formula"
  parameter Integer resolution(min=1)=1 "Denominator of shifting formula"

  Interfaces.ClockInput                u "Connector of clock input signal"
  Interfaces.ClockOutput                y
    "Connector of clock output signal"
equation
  y = shiftSample(u,shiftCounter,resolution);
end ShiftSample;


Sub-sample the input clock and provide it as output clock. This block sub-samples the input clock u and provides it as
output clock y.

within Modelica.Clocked.ClockSignals.Sampler;
block SubSample "Sub-sample the input clock and provide it as output clock"
  parameter Integer factor(min=1) "Sub-sampling factor (>= 1)"

  Clocked.ClockSignals.Interfaces.ClockInput u
    "Connector of a clock as input signal"
  Clocked.ClockSignals.Interfaces.ClockOutput y
    "Connector of a clock as output signal (clock y is slower as clock of u)"
equation
  y = subSample(u,factor);
end SubSample;


Super-sample the input clock and provide it as output clock. This block super-samples the clock input signal u and provides it as
clock output signal y.

within Modelica.Clocked.ClockSignals.Sampler;
block SuperSample
  "Super-sample the input clock and provide it as output clock"
  parameter Integer factor(min=1) "Super-sampling factor (>= 1)"

  Clocked.ClockSignals.Interfaces.ClockInput u
    "Connector of a clock as input signal"
  Clocked.ClockSignals.Interfaces.ClockOutput y
    "Connector of a clock as output signal (clock y is faster as clock of u)"
equation
  y = superSample(u,factor);
end SuperSample;


within Modelica.Clocked;
package Examples "Library of examples to demonstrate the usage of package Modelica.Clocked"
  extends Modelica.Icons.ExamplesPackage;
  import Modelica.Units.SI;
end Examples;


Drive with clocked cascade controller where all partitions are defined with exact (integer) clock that need to be compatible to each other. Cascade control drive with discrete-time controller where two
periodic clock with absolute periods are defined and
are associated to
the corresponding controller partitions.
The super-sampling factor of block \"super\" is derived by
clock inference.

within Modelica.Clocked.Examples.CascadeControlledDrive;
model AbsoluteClocks
  "Drive with clocked cascade controller where all partitions are defined with exact (integer) clock that need to be compatible to each other"

 extends Modelica.Icons.Example;

  Modelica.Mechanics.Rotational.Components.Inertia load(J=10,
    phi(fixed=true, start=0),
    w(fixed=true, start=0))
  Modelica.Mechanics.Rotational.Sensors.SpeedSensor speed

  Clocked.RealSignals.NonPeriodic.PI PI(
    k=100,
    T=0.5,
    x(fixed=true))
  Modelica.Blocks.Math.Feedback feedback2

  Modelica.Mechanics.Rotational.Sources.Torque torque

  Modelica.Mechanics.Rotational.Sensors.AngleSensor angle
  Modelica.Blocks.Sources.KinematicPTP2 kinematicPTP(
    q_end={Modelica.Constants.pi},
    qd_max={2},
    qdd_max={3})
  Modelica.Blocks.Math.Feedback feedback1
  Modelica.Blocks.Math.Gain gain(k=20)
  Clocked.RealSignals.Sampler.SampleClocked sample1
  Clocked.RealSignals.Sampler.Sample sample2
  Clocked.RealSignals.Sampler.Hold hold1
  Clocked.RealSignals.Sampler.SampleClocked sample3
  Clocked.RealSignals.Sampler.SuperSample super(inferFactor=true)
  Clocked.ClockSignals.Clocks.PeriodicExactClock slowClock(factor=10,
      resolution=Modelica.Clocked.Types.Resolution.ms)
  Clocked.ClockSignals.Clocks.PeriodicExactClock fastClock(factor=2,
      resolution=Modelica.Clocked.Types.Resolution.ms)
equation
  connect(speed.flange, load.flange_b)
  connect(feedback2.y, PI.u)
  connect(torque.flange, load.flange_a)
  connect(angle.flange, load.flange_b)
  connect(feedback1.y, gain.u)
  connect(speed.w, sample1.u)
  connect(angle.phi, sample2.u)
  connect(sample1.y, feedback2.u2)
  connect(sample2.y, feedback1.u2)
  connect(PI.y, hold1.u)
  connect(hold1.y, torque.tau)
  connect(sample3.y, feedback1.u1)
  connect(kinematicPTP.q[1], sample3.u)
connect(gain.y, super.u)
connect(super.y, feedback2.u1)
  connect(slowClock.y, sample3.clock)
  connect(fastClock.y, sample1.clock)
end AbsoluteClocks;


Drive with continuous-time cascade controller. Original cascade controlled drive with a
continuous-time controller.

within Modelica.Clocked.Examples.CascadeControlledDrive;
model Continuous "Drive with continuous-time cascade controller"
 extends Modelica.Icons.Example;

  Modelica.Mechanics.Rotational.Components.Inertia load(J=10,
    phi(fixed=true, start=0),
    w(fixed=true, start=0))
  Modelica.Mechanics.Rotational.Sensors.SpeedSensor speed

  Modelica.Blocks.Continuous.PI PI(
    k=100,
    initType=Modelica.Blocks.Types.Init.InitialState,
    x_start=0,
    T=0.5)
  Modelica.Blocks.Math.Feedback feedback2

  Modelica.Mechanics.Rotational.Sources.Torque torque

  Modelica.Mechanics.Rotational.Sensors.AngleSensor angle
  Modelica.Blocks.Sources.KinematicPTP2 kinematicPTP(
    q_end={Modelica.Constants.pi},
    qd_max={2},
    qdd_max={3})
  Modelica.Blocks.Math.Feedback feedback1
  Modelica.Blocks.Math.Gain gain(k=20)
equation
  connect(speed.flange, load.flange_b)
  connect(feedback2.y, PI.u)
  connect(torque.flange, load.flange_a)
  connect(angle.flange, load.flange_b)
  connect(PI.y, torque.tau)
  connect(speed.w, feedback2.u2)
  connect(angle.phi, feedback1.u2)
  connect(kinematicPTP.q[1], feedback1.u1)
  connect(feedback1.y, gain.u)
  connect(gain.y, feedback2.u1)
end Continuous;


within Modelica.Clocked.Examples;
package CascadeControlledDrive "Examples based on a simple drive with cascade controller and different ways to define the sampling and super-sampling"
  extends Modelica.Icons.ExamplesPackage;
end CascadeControlledDrive;


Drive with clocked cascade controller where clocks are defined with sub-sampling and partitions with super-sampling. Cascade control drive with discrete-time controller where one
periodic clock is defined, the second periodic clock is derived by
sub-sampling of the first clock, and both clocks are associated to
the corresponding controller partitions.
The super-sampling factor of block \"super\" is derived by
clock inference.

within Modelica.Clocked.Examples.CascadeControlledDrive;
model SubClocked
  "Drive with clocked cascade controller where clocks are defined with sub-sampling and partitions with super-sampling"
 extends Modelica.Icons.Example;

  Modelica.Mechanics.Rotational.Components.Inertia load(J=10,
    phi(fixed=true, start=0),
    w(fixed=true, start=0))
  Modelica.Mechanics.Rotational.Sensors.SpeedSensor speed

  Clocked.RealSignals.NonPeriodic.PI PI(
    k=100,
    T=0.5,
    x(fixed=true))
  Modelica.Blocks.Math.Feedback feedback2

  Modelica.Mechanics.Rotational.Sources.Torque torque

  Modelica.Mechanics.Rotational.Sensors.AngleSensor angle
  Modelica.Blocks.Sources.KinematicPTP2 kinematicPTP(
    q_end={Modelica.Constants.pi},
    qd_max={2},
    qdd_max={3})
  Modelica.Blocks.Math.Feedback feedback1
  Modelica.Blocks.Math.Gain gain(k=20)
  Clocked.RealSignals.Sampler.SampleClocked sample1
  Clocked.RealSignals.Sampler.Sample sample2
  Clocked.RealSignals.Sampler.Hold hold1
  Clocked.RealSignals.Sampler.SampleClocked sample3
  Clocked.RealSignals.Sampler.SuperSample super(inferFactor=true)
  Clocked.ClockSignals.Sampler.SubSample subSample1(factor=5)
  Clocked.ClockSignals.Clocks.PeriodicRealClock periodicRealClock(period=
        0.002)
equation
  connect(speed.flange, load.flange_b)
  connect(feedback2.y, PI.u)
  connect(torque.flange, load.flange_a)
  connect(angle.flange, load.flange_b)
  connect(feedback1.y, gain.u)
  connect(speed.w, sample1.u)
  connect(angle.phi, sample2.u)
  connect(sample1.y, feedback2.u2)
  connect(sample2.y, feedback1.u2)
  connect(PI.y, hold1.u)
  connect(hold1.y, torque.tau)
  connect(sample3.y, feedback1.u1)
  connect(kinematicPTP.q[1], sample3.u)
connect(gain.y, super.u)
connect(super.y, feedback2.u1)
  connect(subSample1.y, sample3.clock)
  connect(periodicRealClock.y, sample1.clock)
  connect(periodicRealClock.y, subSample1.u)
end SubClocked;


Drive with clocked cascade controller where fastest partition is defined with a clock and slower partition is defined with super-sampling. Cascade control drive with discrete-time controller where one
periodic clock is defined for the fastest control loop,
and the periodic clock of the slower control loop is implicitly
defined by the super-sampling factor defined at the \"super\" block.

within Modelica.Clocked.Examples.CascadeControlledDrive;
model SuperSampled
  "Drive with clocked cascade controller where fastest partition is defined with a clock and slower partition is defined with super-sampling"

 extends Modelica.Icons.Example;

  Modelica.Mechanics.Rotational.Components.Inertia load(J=10,
    phi(fixed=true, start=0),
    w(fixed=true, start=0))
  Modelica.Mechanics.Rotational.Sensors.SpeedSensor speed

  Clocked.RealSignals.NonPeriodic.PI PI(
    k=100,
    T=0.5,
    x(fixed=true))
  Modelica.Blocks.Math.Feedback feedback2

  Modelica.Mechanics.Rotational.Sources.Torque torque

  Modelica.Mechanics.Rotational.Sensors.AngleSensor angle
  Modelica.Blocks.Sources.KinematicPTP2 kinematicPTP(
    q_end={Modelica.Constants.pi},
    qd_max={2},
    qdd_max={3})
  Modelica.Blocks.Math.Feedback feedback1
  Modelica.Blocks.Math.Gain gain(k=20)
  Clocked.RealSignals.Sampler.SampleClocked sample1
  Clocked.RealSignals.Sampler.Sample sample2
  Clocked.RealSignals.Sampler.Hold hold1
  Clocked.RealSignals.Sampler.Sample sample3
  Clocked.RealSignals.Sampler.SuperSample super(factor=5, inferFactor=false)
  Clocked.ClockSignals.Clocks.PeriodicRealClock periodicRealClock(period=
        0.002)
equation
  connect(speed.flange, load.flange_b)
  connect(feedback2.y, PI.u)
  connect(torque.flange, load.flange_a)
  connect(angle.flange, load.flange_b)
  connect(feedback1.y, gain.u)
  connect(speed.w, sample1.u)
  connect(angle.phi, sample2.u)
  connect(sample1.y, feedback2.u2)
  connect(sample2.y, feedback1.u2)
  connect(PI.y, hold1.u)
  connect(hold1.y, torque.tau)
  connect(sample3.y, feedback1.u1)
  connect(kinematicPTP.q[1], sample3.u)
connect(gain.y, super.u)
connect(super.y, feedback2.u1)
  connect(periodicRealClock.y, sample1.clock)
end SuperSampled;


within Modelica.Clocked.Examples;
package Elementary "Examples that are used for the documentation of the blocks"
  extends Modelica.Icons.ExamplesPackage;
end Elementary;


Example of an AssignClock block for Boolean signals. Elementary example for the documentation of block
Modelica.Clocked.BooleanSignals.Sampler.AssignClock.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model AssignClock "Example of an AssignClock block for Boolean signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.BooleanSignals.Sampler.AssignClock assignClock1
Modelica.Clocked.BooleanSignals.NonPeriodic.UnitDelay unitDelay1
Modelica.Blocks.Logical.Xor xor
  Modelica.Blocks.Sources.BooleanConstant integerConstant(k=true)
equation
connect(periodicClock.y, assignClock1.clock)
connect(assignClock1.y, unitDelay1.u)
connect(assignClock1.u, xor.y)
connect(integerConstant.y, xor.u2)
connect(unitDelay1.y, xor.u1)
end AssignClock;


Example of an AssignClockVectorized block for Boolean signals. Elementary example for the documentation of block
Modelica.Clocked.BooleanSignals.Sampler.AssignClockVectorized.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model AssignClockVectorized
  "Example of an AssignClockVectorized block for Boolean signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.BooleanSignals.NonPeriodic.UnitDelay unitDelay1
Modelica.Clocked.BooleanSignals.Sampler.AssignClockVectorized
  assignClock1(n=2)
Modelica.Clocked.BooleanSignals.NonPeriodic.UnitDelay unitDelay2(y_start=
      true)
Modelica.Blocks.Logical.Xor xor
  Modelica.Blocks.Sources.BooleanConstant integerConstant(k=true)
Modelica.Blocks.Logical.Xor xor1
  Modelica.Blocks.Sources.BooleanConstant integerConstant1(k=true)
equation
connect(periodicClock.y, assignClock1.clock)
connect(xor.u1, unitDelay1.y)
connect(xor.u2, integerConstant.y)
connect(xor1.u1, integerConstant1.y)
connect(unitDelay2.y, xor1.u2)
connect(xor.y, assignClock1.u[1])
connect(xor1.y, assignClock1.u[2])
connect(assignClock1.y[1], unitDelay1.u)
connect(assignClock1.y[2], unitDelay2.u)
end AssignClockVectorized;


Example of a BackSample block for Boolean signals. Elementary example for the documentation of block
Modelica.Clocked.BooleanSignals.Sampler.BackSample.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model BackSample "Example of a BackSample block for Boolean signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.BooleanSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Clocked.BooleanSignals.Sampler.ShiftSample shiftSample1(
      shiftCounter=4, resolution=3)
Modelica.Clocked.BooleanSignals.Sampler.BackSample backSample1(
  backCounter=4,
  resolution=3,
  y_start=true)
  Modelica.Blocks.Sources.BooleanTable table(table={0.05,0.15})
equation
  connect(periodicClock.y, sample1.clock)
  connect(sample1.u, table.y)
  connect(shiftSample1.u, sample1.y)
connect(backSample1.u, shiftSample1.y)
end BackSample;


Example of a Hold block for Boolean signals. Elementary example for the documentation of block
Modelica.Clocked.BooleanSignals.Sampler.Hold.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model Hold "Example of a Hold block for Boolean signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanTable table(table={0.05,0.15})
  Modelica.Clocked.BooleanSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.BooleanSignals.Sampler.Hold hold1(y_start=false)
Modelica.Clocked.BooleanSignals.Sampler.ShiftSample shiftSample1(shiftCounter=2)
equation
  connect(periodicClock.y, sample1.clock)
  connect(table.y, sample1.u)
  connect(shiftSample1.u, sample1.y)
  connect(hold1.u, shiftSample1.y)
end Hold;


within Modelica.Clocked.Examples.Elementary;
package BooleanSignals "Examples that are used for the documentation of the Modelica.Clocked.BooleanSignals sub-library"
  extends Modelica.Icons.ExamplesPackage;
end BooleanSignals;


Example of a Sample block for Boolean signals. Elementary example for the documentation of block
Modelica.Clocked.BooleanSignals.Sampler.Sample.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model Sample1 "Example of a Sample block for Boolean signals"
 extends Modelica.Icons.Example;
  Modelica.Clocked.BooleanSignals.Sampler.AssignClock  assignClock
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Blocks.Sources.BooleanStep
                             step(startTime=0.1)
Modelica.Clocked.BooleanSignals.Sampler.Sample sample1
equation
  connect(periodicClock.y, assignClock.clock)
  connect(step.y, sample1.u)
  connect(sample1.y, assignClock.u)
end Sample1;


Example of a Sample block for Boolean signals with direct feed-through in the continuous-time and the clocked partition. Elementary example for the documentation of block
Modelica.Clocked.BooleanSignals.Sampler.Sample.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model Sample2
  "Example of a Sample block for Boolean signals with direct feed-through in the continuous-time and the clocked partition"
 extends Modelica.Icons.Example;
  Modelica.Clocked.BooleanSignals.Sampler.SampleClocked  sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Blocks.Sources.BooleanStep
                             step(startTime=0.04)
  Modelica.Clocked.BooleanSignals.Sampler.Hold hold1
  Modelica.Clocked.BooleanSignals.Sampler.Sample  sample2
  Modelica.Blocks.Sources.BooleanConstant integerConstant(k=true)
Modelica.Blocks.Logical.Xor xor
Modelica.Blocks.Logical.Xor xor1
equation
  connect(periodicClock.y, sample1.clock)
connect(step.y, sample1.u)
  connect(hold1.y, sample2.u)
connect(sample2.y, xor.u2)
connect(xor.u1, sample1.y)
  connect(hold1.u, xor1.y)
connect(xor1.u1, integerConstant.y)
connect(xor1.u2, xor.y)
end Sample2;


Example of a SampleClocked block for Boolean signals. Elementary example for the documentation of block
Modelica.Clocked.BooleanSignals.Sampler.SampleClocked.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model SampleClocked
  "Example of a SampleClocked block for Boolean signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep
                               step(startTime=0.1)
  Modelica.Clocked.BooleanSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
equation
  connect(periodicClock.y, sample1.clock)
  connect(sample1.u, step.y)
end SampleClocked;


Example of a SampleVectorizedAndClocked block for Boolean signals. Elementary example for the documentation of block
Modelica.Clocked.BooleanSignals.Sampler.SampleVectorizedAndClocked.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model SampleVectorizedAndClocked
  "Example of a SampleVectorizedAndClocked block for Boolean signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep
                               step2(startTime=0.04)
  Modelica.Clocked.BooleanSignals.Sampler.SampleVectorizedAndClocked sample1(n=2)
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Blocks.Sources.BooleanStep
                               step1(startTime=0.08)
equation
  connect(periodicClock.y, sample1.clock)
  connect(sample1.u[1], step2.y)
  connect(step1.y, sample1.u[2])
end SampleVectorizedAndClocked;


Example of a ShiftSample block for Boolean signals. Elementary example for the documentation of block
Modelica.Clocked.BooleanSignals.Sampler.ShiftSample.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model ShiftSample "Example of a ShiftSample block for Boolean signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.BooleanSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Clocked.BooleanSignals.Sampler.ShiftSample shiftSample1(
      shiftCounter=4, resolution=3)
  Modelica.Blocks.Sources.BooleanTable table(table={0.05,0.15})
equation
  connect(periodicClock.y, sample1.clock)
  connect(sample1.u, table.y)
  connect(shiftSample1.u, sample1.y)
end ShiftSample;


Example of a SubSample block for Boolean signals. Elementary example for the documentation of block
Modelica.Clocked.BooleanSignals.Sampler.SubSample.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model SubSample "Example of a SubSample block for Boolean signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.BooleanSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.BooleanSignals.Sampler.SubSample subSample1(inferFactor=false,
      factor=3)
  Modelica.Blocks.Sources.BooleanTable table(table={0.05,0.15})
equation
  connect(periodicClock.y, sample1.clock)
  connect(sample1.u, table.y)
  connect(subSample1.u, sample1.y)
end SubSample;


Example of a SuperSample block for Boolean signals. Elementary example for the documentation of block
Modelica.Clocked.BooleanSignals.Sampler.SuperSample.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model SuperSample "Example of a SuperSample block for Boolean signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.BooleanSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.BooleanSignals.Sampler.SuperSample superSample1(inferFactor=
        false, factor=3)
  Modelica.Blocks.Sources.BooleanTable table(table={0.05,0.15})
equation
  connect(periodicClock.y, sample1.clock)
  connect(table.y, sample1.u)
  connect(superSample1.u, sample1.y)
end SuperSample;


Example of using the clock tick based Boolean Pulse source block. Example for block
Modelica.Clocked.BooleanSignals.TickBasedSources.Pulse.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model TickBasedPulse
  "Example of using the clock tick based Boolean Pulse source block"
   extends Modelica.Icons.Example;

Modelica.Clocked.ClockSignals.Clocks.PeriodicRealClock
  periodicClock1(period=0.1)
  Modelica.Clocked.BooleanSignals.Sampler.AssignClock assignClock1
  Modelica.Clocked.BooleanSignals.TickBasedSources.Pulse pulse(
    widthTicks=2,
    periodTicks=4,
    startTick=2)
equation
  connect(periodicClock1.y, assignClock1.clock)
  connect(pulse.y, assignClock1.u)
end TickBasedPulse;


Example of using the clocked simulation tick/sample based Boolean Step source block. Example for block
Modelica.Clocked.BooleanSignals.TickBasedSources.Step.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model TickBasedStep
  "Example of using the clocked simulation tick/sample based Boolean Step source block"
   extends Modelica.Icons.Example;

Modelica.Clocked.ClockSignals.Clocks.PeriodicRealClock
  periodicClock1(period=0.1)
  Modelica.Clocked.BooleanSignals.Sampler.AssignClock assignClock1
Modelica.Clocked.BooleanSignals.TickBasedSources.Step step(startTick=
        3)
equation
  connect(periodicClock1.y, assignClock1.clock)
  connect(assignClock1.u, step.y)
end TickBasedStep;


Example of using the clocked simulation time based Boolean Pulse source block. Example for block
Modelica.Clocked.BooleanSignals.TimeBasedSources.Pulse.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model TimeBasedPulse
  "Example of using the clocked simulation time based Boolean Pulse source block"
   extends Modelica.Icons.Example;

  Modelica.Clocked.BooleanSignals.TimeBasedSources.Pulse pulse(
    width=50,
    period=0.4,
    startTime=0.1)
Modelica.Clocked.ClockSignals.Clocks.PeriodicRealClock
  periodicClock1(period=0.1)
  Modelica.Clocked.BooleanSignals.Sampler.AssignClock assignClock1
equation
  connect(periodicClock1.y, assignClock1.clock)
  connect(pulse.y, assignClock1.u)
end TimeBasedPulse;


Example of using the clocked simulation time based Boolean Step source block. Example for block
Modelica.Clocked.BooleanSignals.TimeBasedSources.Step.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model TimeBasedStep
  "Example of using the clocked simulation time based Boolean Step source block"
   extends Modelica.Icons.Example;

  Modelica.Clocked.BooleanSignals.TimeBasedSources.Step step(
    startTime=0.2)
Modelica.Clocked.ClockSignals.Clocks.PeriodicRealClock
  periodicClock1(period=0.1)
  Modelica.Clocked.BooleanSignals.Sampler.AssignClock assignClock1
equation
  connect(periodicClock1.y, assignClock1.clock)
  connect(step.y, assignClock1.u)
end TimeBasedStep;


Example of an UpSample block for Boolean signals. Elementary example for the documentation of block
Modelica.Clocked.BooleanSignals.Sampler.Utilities.UpSample.

within Modelica.Clocked.Examples.Elementary.BooleanSignals;
model UpSample "Example of an UpSample block for Boolean signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Clocked.BooleanSignals.Sampler.SampleClocked sample1
Modelica.Clocked.BooleanSignals.Sampler.Utilities.UpSample upSample1
Modelica.Clocked.BooleanSignals.Sampler.Utilities.UpSample upSample2(
    inferFactor=false, factor=3)
  Modelica.Blocks.Sources.BooleanTable table1(table={0.05,0.15})
Modelica.Blocks.Logical.And and1
equation
  connect(periodicClock.y, sample1.clock)
  connect(table1.y, sample1.u)
  connect(upSample1.u, sample1.y)
  connect(upSample2.u, sample1.y)
connect(upSample1.y, and1.u1)
connect(upSample2.y, and1.u2)
end UpSample;


Simple example of conjunctive and disjunctive logical clocks, combining clock signals to derive new event driven clocks.. Simple example of two logical clocks, a conjunctive and a disjunctive clock.
    Both receive the very same clock inputs, produced by two rotational clocks
    with slightly shifted input angle waves (sine and cosine respectively). The
    configuration and results of the rotational clocks are explained in the
    rotational clocks example.
    The generated clocked signals of the disjunctive and conjunctive clock are
    therefore:

within Modelica.Clocked.Examples.Elementary.ClockSignals;
model LogicalSample
  "Simple example of conjunctive and disjunctive logical clocks, combining clock signals to derive new event driven clocks."
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine_angle_input(
    amplitude = 10,
    f = 1)
  Modelica.Blocks.Sources.Cosine cosine_angle_input(
    amplitude = 10,
    f = 1)
  Modelica.Blocks.Sources.Pulse trigger_interval_input(
    amplitude = 2,
    period = 1,
    offset = 1)

  Clocked.ClockSignals.Clocks.Rotational.RotationalClock rotational_clock_1
  Clocked.ClockSignals.Clocks.Rotational.RotationalClock rotational_clock_2

  Clocked.ClockSignals.Clocks.Logical.ConjunctiveClock conjunctiveClock
  Clocked.ClockSignals.Clocks.Logical.DisjunctiveClock disjunctiveClock

  Clocked.RealSignals.Sampler.SampleClocked sample_conjunctive
  Clocked.RealSignals.Sampler.SampleClocked sample_disjunctive
equation
  connect(sine_angle_input.y, rotational_clock_1.angle)
  connect(trigger_interval_input.y, rotational_clock_1.trigger_interval)
  connect(trigger_interval_input.y, rotational_clock_2.trigger_interval)
  connect(cosine_angle_input.y, rotational_clock_2.angle)
  connect(rotational_clock_1.y, conjunctiveClock.u[1])
  connect(rotational_clock_2.y, conjunctiveClock.u[2])
  connect(rotational_clock_1.y, disjunctiveClock.u[1])
  connect(rotational_clock_2.y, disjunctiveClock.u[2])

  connect(disjunctiveClock.y, sample_disjunctive.clock)
  connect(conjunctiveClock.y, sample_conjunctive.clock)
  connect(sample_conjunctive.u, sine_angle_input.y)
  connect(sample_disjunctive.u, sine_angle_input.y)
end LogicalSample;


within Modelica.Clocked.Examples.Elementary;
package ClockSignals "Examples that are used for the documentation of the Modelica.Clocked.ClockSignals sub-library"
  extends Modelica.Icons.ExamplesPackage;
end ClockSignals;


Simple example of a rotational clock with variable trigger interval and switching rotation-direction.. Simple example of a rotational clock with variable trigger interval and
    switching direction of rotation. The input rotation is just sinusoidal,
    switching direction every half second. The trigger interval is changed with
    the same pace; every half second it is doubled or halved respectively. The
    generated clocked signals are therefore:

within Modelica.Clocked.Examples.Elementary.ClockSignals;
model RotationalSample
  "Simple example of a rotational clock with variable trigger interval and switching rotation-direction."
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine angle_input(
    amplitude = 10,
    f = 1)
  Modelica.Blocks.Sources.Pulse trigger_interval_input(
    amplitude = 2,
    period = 1,
    offset = 1)
  Clocked.ClockSignals.Clocks.Rotational.RotationalClock rotationalClock
  Clocked.RealSignals.Sampler.SampleClocked sample_angle

equation
  connect(angle_input.y, rotationalClock.angle)
  connect(rotationalClock.y, sample_angle.clock)
  connect(angle_input.y, sample_angle.u)
  connect(trigger_interval_input.y, rotationalClock.trigger_interval)
end RotationalSample;


Example of a ShiftSample block for Clock signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.ClockSignals.Sampler.ShiftSample.

within Modelica.Clocked.Examples.Elementary.ClockSignals;
model ShiftSample "Example of a ShiftSample block for Clock signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Clocked.ClockSignals.Sampler.ShiftSample shiftSample1(shiftCounter=4,
      resolution=3)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
equation
  connect(periodicClock.y, shiftSample1.u)
  connect(sine.y, sample1.u)
  connect(shiftSample1.y, sample1.clock)
end ShiftSample;


Example of a SubSample block for Clock signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.ClockSignals.Sampler.SubSample.

within Modelica.Clocked.Examples.Elementary.ClockSignals;
model SubSample "Example of a SubSample block for Clock signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.ClockSignals.Sampler.SubSample subSample1(factor=3)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
equation
  connect(periodicClock.y, subSample1.u)
  connect(sine.y, sample1.u)
  connect(subSample1.y, sample1.clock)
end SubSample;


Example of a SuperSample block for Clock signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.ClockSignals.Sampler.SuperSample.

within Modelica.Clocked.Examples.Elementary.ClockSignals;
model SuperSample "Example of a SuperSample block for Clock signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.ClockSignals.Sampler.SuperSample superSample1(factor=3)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
equation
  connect(periodicClock.y, superSample1.u)
  connect(sine.y, sample1.u)
  connect(superSample1.y, sample1.clock)
end SuperSample;


Example of an AssignClock block for Integer signals. Elementary example for the documentation of block
Modelica.Clocked.IntegerSignals.Sampler.AssignClock.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model AssignClock "Example of an AssignClock block for Integer signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.IntegerSignals.Sampler.AssignClock assignClock1
Modelica.Clocked.IntegerSignals.NonPeriodic.UnitDelay unitDelay1
Modelica.Blocks.Sources.IntegerConstant
                                 const(k=1)
Modelica.Blocks.MathInteger.Sum sum(nu=2)
equation
connect(periodicClock.y, assignClock1.clock)
connect(assignClock1.y, unitDelay1.u)
connect(unitDelay1.y, sum.u[1])
connect(const.y, sum.u[2])
connect(sum.y, assignClock1.u)
end AssignClock;


Example of an AssignClockVectorized block for Integer signals. Elementary example for the documentation of block
Modelica.Clocked.IntegerSignals.Sampler.AssignClockVectorized.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model AssignClockVectorized
  "Example of an AssignClockVectorized block for Integer signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.IntegerSignals.NonPeriodic.UnitDelay unitDelay1
Modelica.Blocks.Sources.IntegerConstant
                                 const(k=1)
Modelica.Clocked.IntegerSignals.Sampler.AssignClockVectorized
  assignClock1(n=2)
Modelica.Blocks.Sources.IntegerConstant
                                 const1(k=2)
Modelica.Clocked.IntegerSignals.NonPeriodic.UnitDelay unitDelay2
Modelica.Blocks.MathInteger.Sum sum1(nu=2)
Modelica.Blocks.MathInteger.Sum sum2(nu=2)
equation
connect(periodicClock.y, assignClock1.clock)
connect(assignClock1.y[1], unitDelay1.u)
connect(assignClock1.y[2], unitDelay2.u)
connect(unitDelay1.y, sum1.u[1])
connect(const.y, sum1.u[2])
connect(const1.y, sum2.u[1])
connect(unitDelay2.y, sum2.u[2])
connect(sum1.y, assignClock1.u[1])
connect(sum2.y, assignClock1.u[2])
end AssignClockVectorized;


Example of a BackSample block for Integer signals. Elementary example for the documentation of block
Modelica.Clocked.IntegerSignals.Sampler.BackSample.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model BackSample "Example of a BackSample block for Integer signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.IntegerSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Clocked.IntegerSignals.Sampler.ShiftSample shiftSample1(
      shiftCounter=4, resolution=3)
Modelica.Clocked.IntegerSignals.Sampler.BackSample backSample1(
  backCounter=4,
  resolution=3,
  y_start=1)
  Modelica.Blocks.Sources.IntegerTable table(table=[0,1; 0.025,2; 0.05,
      0; 0.075,-1; 0.1,3])
equation
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, shiftSample1.u)
connect(shiftSample1.y, backSample1.u)
  connect(table.y, sample1.u)
end BackSample;


Example of a Hold block for Integer signals. Elementary example for the documentation of block
Modelica.Clocked.IntegerSignals.Sampler.Hold.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model Hold "Example of a Hold block for Integer signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.IntegerTable table(table=[0,1; 0.05,2; 0.1,0; 0.15,-1;
        0.2,3])
  Modelica.Clocked.IntegerSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.IntegerSignals.Sampler.Hold hold1(y_start=-1)
Modelica.Clocked.IntegerSignals.Sampler.ShiftSample  shiftSample1(
    shiftCounter=2)
equation
  connect(periodicClock.y, sample1.clock)
  connect(table.y, sample1.u)
  connect(sample1.y, shiftSample1.u)
  connect(shiftSample1.y, hold1.u)
end Hold;


within Modelica.Clocked.Examples.Elementary;
package IntegerSignals "Examples that are used for the documentation of the Modelica.Clocked.IntegerSignals sub-library"
  extends Modelica.Icons.ExamplesPackage;
end IntegerSignals;


Example of a Sample block for Integer signals. Elementary example for the documentation of block
Modelica.Clocked.IntegerSignals.Sampler.Sample.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model Sample1 "Example of a Sample block for Integer signals"
 extends Modelica.Icons.Example;
  Modelica.Clocked.IntegerSignals.Sampler.AssignClock  assignClock
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Blocks.Sources.IntegerStep
                             step(startTime=0.1)
Modelica.Clocked.IntegerSignals.Sampler.Sample sample1
equation
  connect(periodicClock.y, assignClock.clock)
  connect(step.y, sample1.u)
  connect(sample1.y, assignClock.u)
end Sample1;


Example of a Sample block for Integer signals with direct feed-through in the continuous-time and the clocked partition. Elementary example for the documentation of block
Modelica.Clocked.IntegerSignals.Sampler.Sample.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model Sample2
  "Example of a Sample block for Integer signals with direct feed-through in the continuous-time and the clocked partition"
 extends Modelica.Icons.Example;
  Modelica.Clocked.IntegerSignals.Sampler.SampleClocked  sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Blocks.Sources.IntegerStep
                             step(startTime=0.04)
  Modelica.Clocked.IntegerSignals.Sampler.Hold hold1
  Modelica.Clocked.IntegerSignals.Sampler.Sample  sample2
Modelica.Blocks.MathInteger.Sum sum1(k={1,-1}, nu=2)
Modelica.Blocks.MathInteger.Sum sum2(         nu=2)
  Modelica.Blocks.Sources.IntegerConstant integerConstant(k=2)
equation
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, sum1.u[1])
  connect(sample2.y, sum1.u[2])
  connect(integerConstant.y, sum2.u[1])
  connect(sum1.y, sum2.u[2])
  connect(hold1.u, sum2.y)
  connect(hold1.y, sample2.u)
  connect(sample1.u, step.y)
end Sample2;


Example of a SampleClocked block for Integer signals. Elementary example for the documentation of block
Modelica.Clocked.IntegerSignals.Sampler.SampleClocked.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model SampleClocked
  "Example of a SampleClocked block for Integer signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.IntegerStep
                               step(startTime=0.1, offset=1)
  Modelica.Clocked.IntegerSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
equation
  connect(periodicClock.y, sample1.clock)
  connect(step.y, sample1.u)
end SampleClocked;


Example of a SampleVectorizedAndClocked block for Integer signals. Elementary example for the documentation of block
Modelica.Clocked.IntegerSignals.Sampler.SampleVectorizedAndClocked.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model SampleVectorizedAndClocked
  "Example of a SampleVectorizedAndClocked block for Integer signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.IntegerStep
                               step2(offset=1, startTime=0.04)
  Modelica.Clocked.IntegerSignals.Sampler.SampleVectorizedAndClocked sample1(n=2)
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Blocks.Sources.IntegerStep
                               step1(startTime=0.08)
equation
  connect(periodicClock.y, sample1.clock)
  connect(step1.y, sample1.u[1])
  connect(step2.y, sample1.u[2])
end SampleVectorizedAndClocked;


Example of a ShiftSample block for Integer signals. Elementary example for the documentation of block
Modelica.Clocked.IntegerSignals.Sampler.ShiftSample.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model ShiftSample "Example of a ShiftSample block for Integer signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.IntegerSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Clocked.IntegerSignals.Sampler.ShiftSample shiftSample1(
      shiftCounter=4, resolution=3)
  Modelica.Blocks.Sources.IntegerTable table(table=[0,1; 0.025,2; 0.05,
      0; 0.075,-1; 0.1,3])
equation
  connect(periodicClock.y, sample1.clock)
  connect(table.y, sample1.u)
  connect(sample1.y, shiftSample1.u)
end ShiftSample;


Example of a SubSample block for Integer signals. Elementary example for the documentation of block
Modelica.Clocked.IntegerSignals.Sampler.SubSample.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model SubSample "Example of a SubSample block for Integer signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.IntegerSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.IntegerSignals.Sampler.SubSample subSample1(inferFactor=false,
      factor=3)
  Modelica.Blocks.Sources.IntegerTable table(table=[0,1; 0.05,2; 0.1,0; 0.15,-1;
        0.2,3])
equation
  connect(periodicClock.y, sample1.clock)
  connect(table.y, sample1.u)
  connect(sample1.y, subSample1.u)
end SubSample;


Example of a SuperSample block for Integer signals. Elementary example for the documentation of block
Modelica.Clocked.IntegerSignals.Sampler.SuperSample.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model SuperSample "Example of a SuperSample block for Integer signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.IntegerSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.IntegerSignals.Sampler.SuperSample superSample1(inferFactor=
        false, factor=3)
  Modelica.Blocks.Sources.IntegerTable table(table=[0,1; 0.05,2; 0.1,0; 0.15,-1;
        0.2,3])
equation
  connect(periodicClock.y, sample1.clock)
  connect(table.y, sample1.u)
  connect(sample1.y, superSample1.u)
end SuperSample;


Example of using the clocked simulation tick/sample based Integer Step source block. Example for block
Modelica.Clocked.IntegerSignals.TickBasedSources.Step.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model TickBasedStep
  "Example of using the clocked simulation tick/sample based Integer Step source block"
   extends Modelica.Icons.Example;

Modelica.Clocked.ClockSignals.Clocks.PeriodicRealClock
  periodicClock1(period=0.1)
  Modelica.Clocked.IntegerSignals.Sampler.AssignClock assignClock1
Modelica.Clocked.IntegerSignals.TickBasedSources.Step step(
  height=3,
  offset=1,
    startTick=3)
equation
  connect(periodicClock1.y, assignClock1.clock)
connect(step.y, assignClock1.u)
end TickBasedStep;


Example of using the clocked simulation time based Integer Step source block. Example for block
Modelica.Clocked.IntegerSignals.TimeBasedSources.Step.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model TimeBasedStep
  "Example of using the clocked simulation time based Integer Step source block"
   extends Modelica.Icons.Example;

  Modelica.Clocked.IntegerSignals.TimeBasedSources.Step step(
    height=3,
    offset=1,
    startTime=0.2)
Modelica.Clocked.ClockSignals.Clocks.PeriodicRealClock
  periodicClock1(period=0.1)
  Modelica.Clocked.IntegerSignals.Sampler.AssignClock assignClock1
equation
  connect(step.y, assignClock1.u)
  connect(periodicClock1.y, assignClock1.clock)
end TimeBasedStep;


Example of an UpSample block for Integer signals. Elementary example for the documentation of block
Modelica.Clocked.IntegerSignals.Sampler.Utilities.UpSample.

within Modelica.Clocked.Examples.Elementary.IntegerSignals;
model UpSample "Example of an UpSample block for Integer signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Clocked.IntegerSignals.Sampler.SampleClocked sample1
Modelica.Clocked.IntegerSignals.Sampler.Utilities.UpSample upSample1
Modelica.Clocked.IntegerSignals.Sampler.Utilities.UpSample upSample2(
    inferFactor=false, factor=3)
  Modelica.Blocks.Sources.IntegerTable table(table=[0,1; 0.025,2; 0.05,
      0; 0.075,-1; 0.1,3])
Modelica.Blocks.MathInteger.Sum sum(nu=2)
equation
  connect(periodicClock.y, sample1.clock)
  connect(table.y, sample1.u)
  connect(sample1.y, upSample1.u)
  connect(sample1.y, upSample2.u)
connect(upSample1.y, sum.u[1])
connect(upSample2.y, sum.u[2])
end UpSample;


Example of a AssignClock block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.AssignClock.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model AssignClock "Example of a AssignClock block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.RealSignals.Sampler.AssignClock assignClock1
Modelica.Clocked.RealSignals.NonPeriodic.UnitDelay unitDelay1
Modelica.Blocks.Math.Add add
Modelica.Blocks.Sources.Constant const(k=1)
equation
connect(periodicClock.y, assignClock1.clock)
connect(add.u2, const.y)
connect(assignClock1.y, unitDelay1.u)
connect(unitDelay1.y, add.u1)
connect(add.y, assignClock1.u)
end AssignClock;


Example of an AssignClockToSquareWaveHold block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.Utilities.AssignClockToSquareWaveHold.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model AssignClockToSquareWaveHold
  "Example of an AssignClockToSquareWaveHold block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
Modelica.Clocked.RealSignals.Sampler.Utilities.AssignClockToSquareWaveHold
  clockToSquareWave
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, clockToSquareWave.u)
end AssignClockToSquareWaveHold;


Example of an AssignClockToTriggerHold block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.Utilities.AssignClockToTriggerHold.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model AssignClockToTriggerHold
  "Example of an AssignClockToTriggerHold block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
Modelica.Blocks.Discrete.TriggeredSampler triggeredSampler
Modelica.Clocked.RealSignals.Sampler.Utilities.AssignClockToTriggerHold
  clockToTrigger
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
connect(triggeredSampler.u, sine.y)
  connect(sample1.y, clockToTrigger.u)
connect(triggeredSampler.trigger, clockToTrigger.y)
end AssignClockToTriggerHold;


Example of a AssignClockVectorized block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.AssignClockVectorized.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model AssignClockVectorized
  "Example of a AssignClockVectorized block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.RealSignals.NonPeriodic.UnitDelay unitDelay1
Modelica.Blocks.Math.Add add
Modelica.Blocks.Sources.Constant const(k=1)
Modelica.Clocked.RealSignals.Sampler.AssignClockVectorized
  assignClock1(n=2)
Modelica.Blocks.Math.Add add1
Modelica.Blocks.Sources.Constant const1(k=2)
Modelica.Clocked.RealSignals.NonPeriodic.UnitDelay unitDelay2
equation
connect(add.u2, const.y)
connect(unitDelay1.y, add.u1)
connect(periodicClock.y, assignClock1.clock)
connect(const1.y, add1.u1)
connect(unitDelay2.y, add1.u2)
connect(add.y, assignClock1.u[1])
connect(add1.y, assignClock1.u[2])
connect(assignClock1.y[2], unitDelay2.u)
connect(assignClock1.y[1], unitDelay1.u)
end AssignClockVectorized;


Example of a BackSample block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.BackSample.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model BackSample "Example of a BackSample block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Clocked.RealSignals.Sampler.ShiftSample shiftSample1(
      shiftCounter=4, resolution=3)
Modelica.Clocked.RealSignals.Sampler.BackSample backSample1(
  backCounter=4,
  resolution=3,
  y_start=0.5)
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, shiftSample1.u)
connect(shiftSample1.y, backSample1.u)
end BackSample;


Example of a FractionalDelay block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.NonPeriodic.FractionalDelay.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model FractionalDelay
  "Example of a FractionalDelay block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
Modelica.Clocked.RealSignals.NonPeriodic.FractionalDelay
  fractionalDelay(shift=3, resolution=2)
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
  connect(fractionalDelay.u, sample1.y)
end FractionalDelay;


Example of a Hold block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.Hold.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model Hold "Example of a Hold block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.RealSignals.Sampler.Hold hold1(y_start=-1.0)
Modelica.Clocked.RealSignals.Sampler.ShiftSample shiftSample1(shiftCounter=2)
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, shiftSample1.u)
  connect(shiftSample1.y, hold1.u)
end Hold;


Example of a HoldWithDAeffects block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.HoldWithDAeffects.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model HoldWithDAeffects1
  "Example of a HoldWithDAeffects block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine(f=2,
    startTime=0,
  amplitude=2)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.RealSignals.Sampler.HoldWithDAeffects hold1(
    computationalDelay=true,
    shiftCounter=1,
    resolution=2,
    y_start=0.5,
    limited=true,
    yMax=1.9)
Modelica.Clocked.RealSignals.Sampler.ShiftSample shiftSample1(shiftCounter=2)
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, shiftSample1.u)
  connect(shiftSample1.y, hold1.u)
end HoldWithDAeffects1;


Example of a HoldWithDAeffects block for Real signals (with a computational delay of one sample period). Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.HoldWithDAeffects.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model HoldWithDAeffects2
  "Example of a HoldWithDAeffects block for Real signals (with a computational delay of one sample period)"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine(f=2,
    startTime=0,
  amplitude=2)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.RealSignals.Sampler.HoldWithDAeffects hold1(
    computationalDelay=true,
    shiftCounter=1,
    y_start=0.5,
    limited=true,
    yMax=1.9,
    resolution=1)
Modelica.Clocked.RealSignals.Sampler.ShiftSample shiftSample1(shiftCounter=2)
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, shiftSample1.u)
  connect(shiftSample1.y, hold1.u)
end HoldWithDAeffects2;


within Modelica.Clocked.Examples.Elementary;
package RealSignals "Examples that are used for the documentation of the Modelica.Clocked.RealSignals sub-library"
  extends Modelica.Icons.ExamplesPackage;
end RealSignals;


Example of a Sample block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.Sample.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model Sample1 "Example of a Sample block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
  Clocked.RealSignals.Sampler.Sample sample1
  Clocked.RealSignals.Sampler.AssignClock assignClock
  Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(factor=20,
      resolution=Modelica.Clocked.Types.Resolution.ms)
equation
  connect(sine.y, sample1.u)
  connect(sample1.y, assignClock.u)
  connect(periodicClock.y, assignClock.clock)
end Sample1;


Example of a Sample block with discontinuous Real input signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.Sample.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model Sample2
  "Example of a Sample block with discontinuous Real input signals"
 extends Modelica.Icons.Example;
  Clocked.RealSignals.Sampler.Sample sample1
  Clocked.RealSignals.Sampler.AssignClock assignClock
  Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(factor=20,
      resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Blocks.Sources.Step step(startTime=0.1)
equation
  connect(sample1.y, assignClock.u)
  connect(periodicClock.y, assignClock.clock)
  connect(step.y, sample1.u)
end Sample2;


Example of a Sample block for Real signals with direct feed-through in the continuous-time and the clocked partition. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.Sample.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model Sample3
  "Example of a Sample block for Real signals with direct feed-through in the continuous-time and the clocked partition"
 extends Modelica.Icons.Example;
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Blocks.Sources.Step step(startTime=0.04)
  Modelica.Blocks.Math.Gain gain(k=1.2)
  Modelica.Clocked.RealSignals.Sampler.Hold hold1
  Modelica.Blocks.Math.Feedback feedback
  Modelica.Clocked.RealSignals.Sampler.Sample sample2
equation
  connect(step.y, sample1.u)
  connect(gain.y, hold1.u)
  connect(feedback.y, gain.u)
  connect(sample2.y, feedback.u2)
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, feedback.u1)
  connect(hold1.y, sample2.u)
end Sample3;


Example of a SampleClocked block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.SampleClocked.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model SampleClocked "Example of a SampleClocked block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
end SampleClocked;


Example of a SampleVectorizedAndClocked block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.SampleVectorizedAndClocked.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model SampleVectorizedAndClocked
  "Example of a SampleVectorizedAndClocked block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine2(
  f=2,
  offset=0.1,
  startTime=0)
  Modelica.Clocked.RealSignals.Sampler.SampleVectorizedAndClocked sample1(n=2)
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Blocks.Sources.Sine sine1(startTime=0, f=3)
equation
  connect(periodicClock.y, sample1.clock)
  connect(sine1.y, sample1.u[1])
  connect(sine2.y, sample1.u[2])
end SampleVectorizedAndClocked;


Example of a SampleWithADeffects block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.SampleWithADeffects.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model SampleWithADeffects
  "Example of a SampleWithADeffects block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine(f=2,
    startTime=0,
    amplitude=0.95)
  Modelica.Clocked.RealSignals.Sampler.SampleWithADeffects sample1(
    noisy=true,
    limited=true,
    quantized=true,
    yMax=0.8,
    redeclare
      Modelica.Clocked.RealSignals.Sampler.Utilities.Internal.UniformNoise
      noise(noiseMax=0.2))
  Modelica.Clocked.RealSignals.Sampler.AssignClock assignClock
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      resolution=Modelica.Clocked.Types.Resolution.ms, factor=20)
equation
  connect(sine.y, sample1.u)
  connect(sample1.y, assignClock.u)
  connect(periodicClock.y, assignClock.clock)
end SampleWithADeffects;


Example of a ShiftSample block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.ShiftSample.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model ShiftSample "Example of a ShiftSample block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Clocked.RealSignals.Sampler.ShiftSample shiftSample1(
      shiftCounter=4, resolution=3)
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, shiftSample1.u)
end ShiftSample;


Example of a SubSample block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.SubSample.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model SubSample "Example of a SubSample block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.RealSignals.Sampler.SubSample subSample1(inferFactor=false,
      factor=3)
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, subSample1.u)
end SubSample;


Example of a SuperSample block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.SuperSample.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model SuperSample "Example of a SuperSample block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.RealSignals.Sampler.SuperSample superSample1(inferFactor=false,
      factor=3)
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, superSample1.u)
end SuperSample;


Example of a SuperSampleInterpolated block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.SuperSampleInterpolated.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model SuperSampleInterpolated
  "Example of a SuperSampleInterpolated block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.RealSignals.Sampler.SuperSampleInterpolated superSampleIpo(
    inferFactor=false, factor=3)
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, superSampleIpo.u)
end SuperSampleInterpolated;


Example of using the clocked tick based Ramp source block. Example for block
Modelica.Clocked.RealSignals.TickBasedSources.Ramp.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model TickBasedRamp
  "Example of using the clocked tick based Ramp source block"
   extends Modelica.Icons.Example;
Modelica.Clocked.RealSignals.Sampler.AssignClock assignClock1
Modelica.Clocked.ClockSignals.Clocks.PeriodicRealClock
  periodicClock1(period=0.1)
Modelica.Clocked.RealSignals.TickBasedSources.Ramp ramp(
  height=1,
  durationTicks=3,
  startTick=2,
  offset=0)
equation

connect(periodicClock1.y, assignClock1.clock)
connect(ramp.y, assignClock1.u)
end TickBasedRamp;


Example of using the clocked tick based Sine source block. Example for block
Modelica.Clocked.RealSignals.TickBasedSources.Step.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model TickBasedSine
  "Example of using the clocked tick based Sine source block"
   extends Modelica.Icons.Example;
Modelica.Clocked.RealSignals.Sampler.AssignClock assignClock1
Modelica.Clocked.ClockSignals.Clocks.PeriodicRealClock
  periodicClock1(period=0.1)
Modelica.Clocked.RealSignals.TickBasedSources.Sine sine(
  periodTicks=10,
  periodOffset=2,
    startTick=4)
Modelica.Blocks.Sources.Sine sineRef(
  f=1,
  phase=1/5*(2*Modelica.Constants.pi),
  startTime=0.3)
equation

connect(periodicClock1.y, assignClock1.clock)
connect(sine.y, assignClock1.u)
end TickBasedSine;


Example of using the clocked tick based Step source block. Example for block
Modelica.Clocked.RealSignals.TickBasedSources.Step.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model TickBasedStep
  "Example of using the clocked tick based Step source block"
   extends Modelica.Icons.Example;
Modelica.Clocked.RealSignals.Sampler.AssignClock assignClock1
Modelica.Clocked.ClockSignals.Clocks.PeriodicRealClock
  periodicClock1(period=0.1)
Modelica.Clocked.RealSignals.TickBasedSources.Step step(startTick=3)
equation

connect(periodicClock1.y, assignClock1.clock)
connect(step.y, assignClock1.u)
end TickBasedStep;


Example of using the clocked time based Ramp source block. Example for block
Modelica.Clocked.RealSignals.TimeBasedSources.Ramp.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model TimeBasedRamp
  "Example of using the clocked time based Ramp source block"
   extends Modelica.Icons.Example;
Modelica.Clocked.RealSignals.Sampler.AssignClock assignClock1
Modelica.Clocked.ClockSignals.Clocks.PeriodicRealClock
  periodicClock1(period=0.1)
Modelica.Clocked.RealSignals.TimeBasedSources.Ramp
                                              ramp(duration=0.5)
equation

connect(periodicClock1.y, assignClock1.clock)
connect(ramp.y, assignClock1.u)
end TimeBasedRamp;


Example of using the clocked time based Sine source block. Example for block
Modelica.Clocked.RealSignals.TimeBasedSources.Sine.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model TimeBasedSine
  "Example of using the clocked time based Sine source block"
   extends Modelica.Icons.Example;
Modelica.Clocked.RealSignals.Sampler.AssignClock assignClock1
Modelica.Clocked.ClockSignals.Clocks.PeriodicRealClock
  periodicClock1(period=0.1)
Modelica.Clocked.RealSignals.TimeBasedSources.Sine
                                              sine(f=2)
equation

connect(periodicClock1.y, assignClock1.clock)
connect(sine.y, assignClock1.u)
end TimeBasedSine;


Example of using the clocked simulation time based Step source block. Example for block
Modelica.Clocked.RealSignals.TimeBasedSources.Step.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model TimeBasedStep
  "Example of using the clocked simulation time based Step source block"
   extends Modelica.Icons.Example;
Modelica.Clocked.RealSignals.TimeBasedSources.Step
                                              step(startTime=0.2)
Modelica.Clocked.RealSignals.Sampler.AssignClock assignClock1
Modelica.Clocked.ClockSignals.Clocks.PeriodicRealClock
  periodicClock1(period=0.1)
equation

connect(step.y, assignClock1.u)
connect(periodicClock1.y, assignClock1.clock)
end TimeBasedStep;


Example of a UniformNoise block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.Utilities.Internal.UniformNoise.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model UniformNoise "Example of a UniformNoise block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.RealSignals.Sampler.Utilities.Internal.UniformNoise
  uniformNoise
Modelica.Blocks.Sources.Constant const(k=0)
equation
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, uniformNoise.u)
  connect(const.y, sample1.u)
end UniformNoise;


Example of a UniformNoiseXorshift64star block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.Utilities.Internal.UniformNoiseXorshift64star.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model UniformNoiseXorshift64star
  "Example of a UniformNoiseXorshift64star block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
Modelica.Clocked.RealSignals.Sampler.Utilities.Internal.UniformNoiseXorshift64star
  uniformNoiseXorshift64star
Modelica.Blocks.Sources.Constant const(k=0)
equation
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, uniformNoiseXorshift64star.u)
  connect(const.y, sample1.u)
end UniformNoiseXorshift64star;


Example of an UpSample block for Real signals. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.Utilities.UpSample.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model UpSample1 "Example of an UpSample block for Real signals"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
Modelica.Clocked.RealSignals.Sampler.Utilities.UpSample upSample1
Modelica.Clocked.RealSignals.Sampler.Utilities.UpSample upSample2(
    inferFactor=false, factor=3)
Modelica.Blocks.Math.Add add
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
  connect(sample1.y, upSample1.u)
  connect(upSample2.u, sample1.y)
connect(upSample2.y, add.u2)
connect(upSample1.y, add.u1)
end UpSample1;


Example of an UpSample block for Real signals combined with FIR filter blocks. Example used to generate a figure for the documentation of block
Modelica.Clocked.RealSignals.Sampler.Utilities.UpSample.

within Modelica.Clocked.Examples.Elementary.RealSignals;
model UpSample2
  "Example of an UpSample block for Real signals combined with FIR filter blocks"
   extends Modelica.Icons.Example;

  Modelica.Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(
      factor=20, resolution=Modelica.Clocked.Types.Resolution.ms)
  Modelica.Blocks.Sources.Sine sine(f=2,
    offset=0.1,
    startTime=0)
  Modelica.Clocked.RealSignals.Sampler.SampleClocked sample1
Modelica.Clocked.RealSignals.Sampler.Utilities.UpSample upSample(
      inferFactor=false, factor=3)
  Modelica.Clocked.RealSignals.Sampler.SuperSampleInterpolated
    superSampleIpo(inferFactor=false, factor=3)
  Modelica.Clocked.RealSignals.Periodic.FIRbyCoefficients FIR2(a={1/3,2/3,1,
        2/3,1/3}, cBufStart={0,0,0,0})
  Modelica.Clocked.RealSignals.Periodic.FIRbyCoefficients FIR1(a={1,1,1},
      cBufStart={0,0})
equation
  connect(sine.y, sample1.u)
  connect(periodicClock.y, sample1.clock)
  connect(upSample.u, sample1.y)
  connect(sample1.y, superSampleIpo.u)
  connect(upSample.y, FIR2.u)
  connect(FIR1.u, upSample.y)
end UpSample2;


Simple controlled drive with discrete controller (period is used in the controller). Simple controlled drive with discrete-timer controller
modelled as a clocked partition.
The discrete-time PI controller is parameterized
with the parameters of the continuous-time version and the
discrete-time version is derived from this parameterization
taken into account the actual sample period.

within Modelica.Clocked.Examples.SimpleControlledDrive;
model ClockedWithDiscreteController
  "Simple controlled drive with discrete controller (period is used in the controller)"
 extends Modelica.Icons.Example;

  Modelica.Mechanics.Rotational.Components.Inertia load(J=10,
    phi(fixed=true, start=0),
    w(fixed=true, start=0))
  Modelica.Mechanics.Rotational.Sensors.SpeedSensor speed
  Modelica.Blocks.Sources.Ramp ramp(duration=2)

  Modelica.Blocks.Math.Feedback feedback

  Modelica.Mechanics.Rotational.Sources.Torque torque

  Clocked.RealSignals.Sampler.SampleClocked sample2
  Clocked.RealSignals.Sampler.Hold hold1
  Clocked.RealSignals.Sampler.Sample sample1
  Clocked.RealSignals.NonPeriodic.PI PI(
    x(fixed=true),
    T=0.1,
    k=110)
Clocked.ClockSignals.Clocks.PeriodicRealClock periodicClock(period=0.1)
equation
  connect(speed.flange, load.flange_b)
  connect(torque.flange, load.flange_a)
  connect(ramp.y, sample2.u)
  connect(sample2.y, feedback.u1)
  connect(hold1.y, torque.tau)
  connect(speed.w, sample1.u)
  connect(sample1.y, feedback.u2)
  connect(feedback.y, PI.u)
  connect(PI.y, hold1.u)
connect(periodicClock.y, sample2.clock)
end ClockedWithDiscreteController;


Simple controlled drive with discrete textbook controller (period is not used in the controller). Simple controlled drive with discrete-time textbook controller
modelled as a clocked partition
(period is not used in the controller)

within Modelica.Clocked.Examples.SimpleControlledDrive;
model ClockedWithDiscreteTextbookController
  "Simple controlled drive with discrete textbook controller (period is not used in the controller)"
 extends Modelica.Icons.Example;

  Modelica.Mechanics.Rotational.Components.Inertia load(J=10,
    phi(fixed=true, start=0),
    w(fixed=true, start=0))
  Modelica.Mechanics.Rotational.Sensors.SpeedSensor speed
  Modelica.Blocks.Sources.Ramp ramp(duration=2)

  Modelica.Blocks.Math.Feedback feedback

  Modelica.Mechanics.Rotational.Sources.Torque torque

  Clocked.RealSignals.Periodic.PI PI(
    Td=1,
    x(fixed=true),
    kd=110)
  Clocked.RealSignals.Sampler.SampleClocked sample2
  Clocked.RealSignals.Sampler.Hold hold1
  Clocked.RealSignals.Sampler.Sample sample1
Clocked.ClockSignals.Clocks.PeriodicRealClock periodicClock(period=0.1)
equation
  connect(speed.flange, load.flange_b)
  connect(torque.flange, load.flange_a)
  connect(feedback.y, PI.u)
  connect(ramp.y, sample2.u)
  connect(sample2.y, feedback.u1)
  connect(PI.y, hold1.u)
  connect(hold1.y, torque.tau)
  connect(sample1.u, speed.w)
  connect(feedback.u2, sample1.y)
connect(periodicClock.y, sample2.clock)
end ClockedWithDiscreteTextbookController;


Simple controlled drive with discretized continuous-time controller. Simple controlled drive with discrete-time controller
modelled as a clocked partition.
The PI controller is defined with a continuous-time block.
The clocked partition is automatically discretized with an
implicit Euler method by setting parameter
useSolver = true in the Advanced menu
of block periodicClock and then selecting
ImplicitEuler as SolverMethod for the partition.

within Modelica.Clocked.Examples.SimpleControlledDrive;
model ClockedWithDiscretizedContinuousController
  "Simple controlled drive with discretized continuous-time controller"
 extends Modelica.Icons.Example;

  Modelica.Mechanics.Rotational.Components.Inertia load(J=10,
    phi(fixed=true, start=0),
    w(fixed=true, start=0))
  Modelica.Mechanics.Rotational.Sensors.SpeedSensor speed
  Modelica.Blocks.Sources.Ramp ramp(duration=2)

  Modelica.Blocks.Math.Feedback feedback

  Modelica.Mechanics.Rotational.Sources.Torque torque

  Clocked.RealSignals.Sampler.SampleClocked sample2
  Clocked.RealSignals.Sampler.Hold hold1
  Clocked.RealSignals.Sampler.Sample sample1
  Modelica.Blocks.Continuous.PI PI(
    initType=Modelica.Blocks.Types.Init.InitialOutput,
    y_start=0,
    T=0.1,
    k=110)
Clocked.ClockSignals.Clocks.PeriodicRealClock periodicClock(
    period=0.1,
    useSolver=true,
    solverMethod="ImplicitEuler")
equation
  connect(speed.flange, load.flange_b)
  connect(torque.flange, load.flange_a)
  connect(ramp.y, sample2.u)
  connect(sample2.y, feedback.u1)
  connect(hold1.y, torque.tau)
  connect(speed.w, sample1.u)
  connect(sample1.y, feedback.u2)
  connect(feedback.y, PI.u)
  connect(PI.y, hold1.u)
connect(periodicClock.y, sample2.clock)
end ClockedWithDiscretizedContinuousController;


Simple controlled drive with discrete controller and simulated AD and DA effects. This is the same model as
ClockedWithDiscreteController.
The only difference is that real world effects like limitation, value discretization, noise
and computing time are taken into account.

within Modelica.Clocked.Examples.SimpleControlledDrive;
model ClockedWith_AD_DA_Effects
  "Simple controlled drive with discrete controller and simulated AD and DA effects"
 extends Modelica.Icons.Example;

  Modelica.Mechanics.Rotational.Components.Inertia load(J=10,
    phi(fixed=true, start=0),
    w(fixed=true, start=0))
  Modelica.Mechanics.Rotational.Sensors.SpeedSensor speed
  Modelica.Blocks.Sources.Ramp ramp(duration=2)

  Modelica.Blocks.Math.Feedback feedback

  Modelica.Mechanics.Rotational.Sources.Torque torque

  Clocked.RealSignals.Sampler.SampleWithADeffects sample2(
    limited=true,
    quantized=true,
    yMax=10,
    bits=16)
  Clocked.RealSignals.Sampler.HoldWithDAeffects hold1(
    computationalDelay=true,
    resolution=10,
    shiftCounter=2,
    limited=true,
    quantized=true,
    yMax=9.5,
    yMin=-9.5,
    bits=16)
  Clocked.RealSignals.Sampler.SampleWithADeffects sample1(noisy=true, noise(
        noiseMax=0.01))
  Clocked.RealSignals.NonPeriodic.PI PI(T=0.1, k=110)
  Clocked.RealSignals.Sampler.AssignClock assignClock1
Clocked.ClockSignals.Clocks.PeriodicRealClock periodicClock(period=0.1)
equation
  connect(speed.flange, load.flange_b)
  connect(torque.flange, load.flange_a)
  connect(ramp.y, sample2.u)
  connect(sample2.y, feedback.u1)
  connect(hold1.y, torque.tau)
  connect(speed.w, sample1.u)
  connect(feedback.y, PI.u)
  connect(PI.y, hold1.u)
  connect(sample1.y, assignClock1.u)
  connect(assignClock1.y, feedback.u2)
connect(periodicClock.y, assignClock1.clock)
end ClockedWith_AD_DA_Effects;


Simple controlled drive with continuous controller. Original simple controlled drive with a
continuous-time controller.

within Modelica.Clocked.Examples.SimpleControlledDrive;
model Continuous "Simple controlled drive with continuous controller"
 extends Modelica.Icons.Example;

  Modelica.Mechanics.Rotational.Components.Inertia load(J=10,
    phi(fixed=true, start=0),
    w(fixed=true, start=0))
  Modelica.Mechanics.Rotational.Sensors.SpeedSensor speed
  Modelica.Blocks.Sources.Ramp ramp(duration=2)

  Modelica.Blocks.Continuous.PI PI(
    initType=Modelica.Blocks.Types.Init.InitialOutput,
    y_start=0,
    T=0.1,
    k=110)
  Modelica.Blocks.Math.Feedback feedback

  Modelica.Mechanics.Rotational.Sources.Torque torque

equation
  connect(speed.flange, load.flange_b)
  connect(feedback.y, PI.u)
  connect(torque.flange, load.flange_a)
  connect(ramp.y, feedback.u1)
  connect(PI.y, torque.tau)
  connect(speed.w, feedback.u2)
end Continuous;


Simple controlled drive with discrete controller and exact periodic clocks (period is used in the controller). This is the same model as
ClockedWithDiscreteController.
The only difference is that the clock is defined with an exact periodic clock and not with
a Real periodic clock.

within Modelica.Clocked.Examples.SimpleControlledDrive;
model ExactlyClockedWithDiscreteController
  "Simple controlled drive with discrete controller and exact periodic clocks (period is used in the controller)"
 extends Modelica.Icons.Example;

  Modelica.Mechanics.Rotational.Components.Inertia load(J=10,
    phi(fixed=true, start=0),
    w(fixed=true, start=0))
  Modelica.Mechanics.Rotational.Sensors.SpeedSensor speed
  Modelica.Blocks.Sources.Ramp ramp(duration=2)

  Modelica.Blocks.Math.Feedback feedback

  Modelica.Mechanics.Rotational.Sources.Torque torque

  Clocked.RealSignals.Sampler.SampleClocked sample2
  Clocked.RealSignals.Sampler.Hold hold1
  Clocked.RealSignals.Sampler.Sample sample1
  Clocked.RealSignals.NonPeriodic.PI PI(
    x(fixed=true),
    T=0.1,
    k=110)
Clocked.ClockSignals.Clocks.PeriodicExactClock periodicClock(factor=100,
      resolution=Modelica.Clocked.Types.Resolution.ms)
equation
  connect(speed.flange, load.flange_b)
  connect(torque.flange, load.flange_a)
  connect(ramp.y, sample2.u)
  connect(sample2.y, feedback.u1)
  connect(hold1.y, torque.tau)
  connect(speed.w, sample1.u)
  connect(sample1.y, feedback.u2)
  connect(feedback.y, PI.u)
  connect(PI.y, hold1.u)
connect(periodicClock.y, sample2.clock)
end ExactlyClockedWithDiscreteController;


within Modelica.Clocked.Examples;
package SimpleControlledDrive "Examples based on a simple controlled drive with different ways to define the sampling"
extends Modelica.Icons.ExamplesPackage;
end SimpleControlledDrive;


Simple example of a mixing unit where a (discretized) nonlinear inverse plant model is used as feedforward controller. Since a long time, Modelica is used to model advanced nonlinear control systems.
Especially, Modelica allows a semi-automatic treatment of inverse nonlinear
plant models. In the fundamental article (Looye et.al. 2005, see
Literature or
Download)
this approach is described and several controller structures are presented to
utilize an inverse plant model in the controller. This approach is attractive
because it results in a systematic procedure to design a controller for the
whole operating range of a plant. This is in contrast to standard controller
design techniques that usually design a linear controller for a plant model
that is linearized at a specific operating point. Therefore the operating range of such controllers is inherently limited.

within Modelica.Clocked.Examples.Systems;
model ControlledMixingUnit
  "Simple example of a mixing unit where a (discretized) nonlinear inverse plant model is used as feedforward controller"
   extends Modelica.Icons.Example;

  parameter SI.Frequency freq = 1/300 "Critical frequency of filter";
  parameter Real c0(unit="mol/l") = 0.848 "Nominal concentration";
  parameter SI.Temperature T0 = 308.5 "Nominal temperature";
  parameter Real a1_inv =  0.2674 "Process parameter of inverse plant model (see references in help)";
  parameter Real a21_inv = 1.815 "Process parameter of inverse plant model (see references in help)";
  parameter Real a22_inv = 0.4682 "Process parameter of inverse plant model (see references in help)";
  parameter Real b_inv =   1.5476 "Process parameter of inverse plant model (see references in help)";
  parameter Real k0_inv =  1.05e14 "Process parameter of inverse plant model (see references in help)";
  parameter Real eps = 34.2894 "Process parameter (see references in help)";
  parameter Real x10 = 0.42 "Relative offset between nominal concentration and initial concentration";
  parameter Real x20 = 0.01 "Relative offset between nominal temperature and initial temperature";
  parameter Real u0 = -0.0224 "Relative offset between initial cooling temperature and nominal temperature";
  final parameter Real c_start(unit="mol/l") = c0*(1-x10) "Initial concentration";
  final parameter SI.Temperature T_start = T0*(1+x20) "Initial temperature";
  final parameter Real c_high_start(unit="mol/l") = c0*(1-0.72) "Reference concentration";
  final parameter Real T_c_start = T0*(1+u0) "Initial cooling temperature";
  parameter Real pro=1.5 "Deviations of plant to inverse plant parameters";
  final parameter Real a1=a1_inv*pro "Process parameter of plant model (see references in help)";
  final parameter Real a21=a21_inv*pro "Process parameter of plant model (see references in help)";
  final parameter Real a22=a22_inv*pro "Process parameter of plant model (see references in help)";
  final parameter Real b=b_inv*pro "Process parameter of plant model (see references in help)";
  final parameter Real k0=k0_inv*pro "Process parameter of plant model (see references in help)";
  Clocked.Examples.Systems.Utilities.ComponentsMixingUnit.MixingUnit invMixingUnit(
    c0=c0,
    T0=T0,
    a1=a1_inv,
    a21=a21_inv,
    a22=a22_inv,
    b=b_inv,
    k0=k0_inv,
    eps=eps,
    c(start=c_start, fixed=true),
    T(start=T_start,
      fixed=true,
      stateSelect=StateSelect.always),
    T_c(start=T_c_start))
  Modelica.Blocks.Math.Add add
  Modelica.Blocks.Math.InverseBlockConstraints inverseBlockConstraints
  Clocked.Examples.Systems.Utilities.ComponentsMixingUnit.MixingUnit mixingUnit(
    c(start=c_start, fixed=true),
    T(start=T_start, fixed=true),
    c0=c0,
    T0=T0,
    a1=a1,
    a21=a21,
    a22=a22,
    b=b,
    k0=k0,
    eps=eps)
  Modelica.Blocks.Math.Feedback feedback
  Modelica.Blocks.Math.Gain gain(k=20)

  Utilities.ComponentsMixingUnit.CriticalDamping filter(
    n=3,
    f=freq,
    x(start={0.49,0.49,0.49}, fixed={true,false,false}))
  Clocked.RealSignals.Sampler.Hold hold1(y_start=0)
  Clocked.RealSignals.Sampler.Sample sample1
  Clocked.ClockSignals.Clocks.PeriodicRealClock periodicClock1(
    useSolver=true,
    period=1,
    solverMethod="ExplicitEuler")
  Modelica.Blocks.Sources.Step step(height=c_high_start - c_start, offset=
        c_start)
  RealSignals.Sampler.SampleClocked  sample2
equation
  connect(feedback.y, gain.u)
  connect(gain.y, add.u2)
  connect(inverseBlockConstraints.y2, invMixingUnit.T_c)
  connect(invMixingUnit.c, inverseBlockConstraints.u2)
  connect(invMixingUnit.T, feedback.u1)
  connect(filter.y, inverseBlockConstraints.u1)
  connect(hold1.y, mixingUnit.T_c)
  connect(add.y, hold1.u)
  connect(sample1.u, mixingUnit.T)
  connect(sample1.y, feedback.u2)
  connect(inverseBlockConstraints.y1, add.u1)
  connect(sample2.u,step. y)
  connect(filter.u, sample2.y)
  connect(periodicClock1.y, sample2.clock)
end ControlledMixingUnit;


Closed-loop throttle control synchronized to the crankshaft angle of an
   internal combustion engine. This example shows how to model a non-periodic synchronous sampled data systems
with the Modelica.Clocked library. This is demonstrated at hand
of a closed-loop throttle control synchronized to the crankshaft angle of an
internal combustion engine. This system has the following properties:

within Modelica.Clocked.Examples.Systems;
model EngineThrottleControl
  "Closed-loop throttle control synchronized to the crankshaft angle of an
   internal combustion engine"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Step speedRef(
    startTime = 5,
    offset = 207.34,
    height = 103.67)
  Utilities.ComponentsThrottleControl.SpeedControl speedControl
  RealSignals.Sampler.Sample sample1
  RealSignals.Sampler.Hold hold1(y_start=8.9)
  Utilities.ComponentsThrottleControl.Engine engine
  Modelica.Blocks.Sources.Step step1(
    height = -5,
    offset = 25,
    startTime = 2)
  Modelica.Blocks.Sources.Step step2(
    height = 5,
    offset = 0,
    startTime = 8)
  Modelica.Blocks.Math.Add add(k1 = -1, k2 = -1)
  Modelica.Mechanics.Rotational.Sources.Torque torque(useSupport = false)
  Modelica.Mechanics.Rotational.Sensors.AngleSensor angleSensor
  Modelica.Blocks.Continuous.Der derivative
  RealSignals.Sampler.SampleClocked sample2

equation
  connect(speedRef.y, sample1.u)
  connect(sample1.y, speedControl.N_des)
  connect(speedControl.Theta, hold1.u)
  connect(hold1.y, engine.Theta)
  connect(torque.flange, engine.flange_b)
  connect(add.y, torque.tau)
  connect(step2.y, add.u2)
  connect(step1.y, add.u1)
  connect(engine.flange_b, angleSensor.flange)
  connect(angleSensor.phi, derivative.u)
  connect(derivative.y, sample2.u)
  connect(sample2.y, speedControl.N)
  connect(sample2.clock, engine.synchronize)
end EngineThrottleControl;


Examples of complete systems

within Modelica.Clocked.Examples;
package Systems "Examples of complete systems"
  extends Modelica.Icons.ExamplesPackage;
end Systems;


Utilities for the examples

within Modelica.Clocked.Examples.Systems;
package Utilities "Utilities for the examples"
  extends Modelica.Icons.UtilitiesPackage;

end Utilities;