model Boolean_Test
Modelica.Blocks.Sources.BooleanPulse BooleanPulse(period = 20e-3, width = 20) annotation(
Placement(visible = true, transformation(origin = {-66, 6}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Real counter(start=0); // Counter to count the number of sets and resets
Real frequency(start=0);
equation
when Modelica.Math.BooleanVectors.oneTrue([BooleanPulse.y,pre(BooleanPulse.y)]) then
counter =pre(counter)+1;
frequency=0.5*counter/time;
end when;
annotation(
uses(Modelica(version = "3.2.3")));
end Boolean_Test;
You can use the above example to achieve your objective. Here I use xor
principle to sense the toggle
in the boolen output (BooleanPulse.y
). A similar idea can be implemented in your source code. The above code is a simple example where I used to validate the computed frequency
. For me the computed is equal to frequency value defined in Modelica.Blocks.Sources.BooleanPulse