Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

problem with Modelica.Blocks.MathBoolean.RisingEdge block

problem with Modelica.Blocks.MathBoolean.RisingEdge block

Hello,

i have written a  program which detects crossing zeros from positive to negative. to do this, i have connected my source, a sine wave for instance to "Modelica.Blocks.Logical.LessEqualThreshold" block with threshold=0, and the output of this block is connected to "Modelica.Blocks.MathBoolean.RisingEdge" block. by this mean anytime value of the sine wave bocomes smaller or equal to zero the output of the comparator becomes one and which trigers the rising edge detection block and the output should generate a pulse consequently.

however when i look at the output of risingedge block it always remains zero.

please help me with this issue.

Thanks,
Arvin

PS: code is attached.

Code:


model tmp1
  Modelica.Blocks.Sources.Sine sine1(amplitude = 2, freqHz = 1, offset = 0) annotation(Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Logical.LessEqualThreshold lessequalthreshold1 annotation(Placement(visible = true, transformation(origin = {-20, 60}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.MathBoolean.RisingEdge rising1 annotation(Placement(visible = true, transformation(origin = {20, 60}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(rising1.u, lessequalthreshold1.y) annotation(Line(points = {{6, 60}, {-8.4724, 60}, {-8.4724, 60}, {-9, 60}}, color = {255, 0, 255}));
  connect(lessequalthreshold1.u, sine1.y) annotation(Line(points = {{-32, 60}, {-49.5507, 60}, {-49.5507, 60.077}, {-49.5507, 60.077}}, color = {0, 0, 127}));
  annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-06, Interval = 0.01));
end tmp1;

Re: problem with Modelica.Blocks.MathBoolean.RisingEdge block

Well. rising1.y is an instantaneous change (dirac impulse). It is never true in the continuous sense. Maybe it would make sense to keep it as such in the result-file; I am unsure why we don't do so.

You can still use it as a condition in a when-equation, which is the primary use of the edge function:

Code:

model tmp1

  Modelica.Blocks.Sources.Sine sine1(amplitude = 2, freqHz = 1, offset = 0) annotation(Placement(visible = true, transformation(origin = {-60, 60}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Logical.LessEqualThreshold lessequalthreshold1 annotation(Placement(visible = true, transformation(origin = {-20, 60}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.MathBoolean.RisingEdge rising1 annotation(Placement(visible = true, transformation(origin = {20, 60}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Real r(fixed=true);
equation
  when rising1.y then
    r = pre(r) + 1;
  end when;
  connect(rising1.u, lessequalthreshold1.y) annotation(Line(points = {{6, 60}, {-8.4724, 60}, {-8.4724, 60}, {-9, 60}}, color = {255, 0, 255}));
  connect(lessequalthreshold1.u, sine1.y) annotation(Line(points = {{-32, 60}, {-49.5507, 60}, {-49.5507, 60.077}, {-49.5507, 60.077}}, color = {0, 0, 127}));
  annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-06, Interval = 0.01));
end tmp1;

So it works fine. You just can't tell if it does or not from plotting it.

There are 0 guests and 0 other users also viewing this topic
You are here: