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

Resting Time to Zero at a Switching Voltage

Resting Time to Zero at a Switching Voltage

HI,
I am using the attached simple RLC circuit with a time dependent inductance.

I am trying to get the time (LTime) start from zero at each switching point of the voltage for the inductance.  It is clear that I don't know what I am doing looking at lines 36 to 45 of the attachment.

How do I use a "booleanPulse" value as a trigger to set an event, in this case to reset the time = 0 for the time dependent inductance at the end of each period?

Any help would be appreciated.

Thanks!

Code:

model Test3

  extends Modelica.Icons.Example;
  import Modelica.Constants.pi;
  import Modelica.Math.sin;
  type Time1 = Real(unit = "Sec");
  type Frequency = Real(unit = "Hz");
  type Inductance = Real(unit = "H");
  type FResonant = Real(unit = "HZ");
  type Period1 = Real(unit = "Sec");
  input Boolean u = true;
  input Real LTime;
  parameter Modelica.SIunits.Resistance R = 20 "Resistance";
  parameter Modelica.SIunits.Inductance L0 = 0.004 "Inductance";
  parameter Modelica.SIunits.Capacitance C = 1e-12 "Capacitance";
  parameter Modelica.SIunits.Voltage V = 50 "DC Voltage";
  parameter Time1 T1 = 1e-6;
  parameter Frequency w2 = 2 * pi * 2e6;
  parameter FResonant Fr = 1 / (2 * pi * sqrt(L0 * C));
  Modelica.Electrical.Analog.Basic.Ground ground annotation(
    Placement(visible = true, transformation(origin = {-70, -66}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor capacitor(C = C) annotation(
    Placement(visible = true, transformation(origin = {30, -24}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Basic.Resistor resistor(R = R) annotation(
    Placement(visible = true, transformation(origin = {30, 60}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  //Inductance L;
  Modelica.Electrical.Analog.Ideal.IdealCommutingSwitch switch annotation(
    Placement(visible = true, transformation(origin = {-42, 74}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
  Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage(V = 5) annotation(
    Placement(visible = true, transformation(origin = {-78, 14}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Blocks.Sources.BooleanPulse booleanPulse(period = 24.579e-6, startTime = 0, width = 50) annotation(
    Placement(visible = true, transformation(origin = {-46, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Sources.RealExpression realExpression(y = L0 * (1 - exp(-LTime / T1) * sin(w2 * LTime))) annotation(
    Placement(visible = true, transformation(origin = {68, 24}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.VariableInductor inductor annotation(
    Placement(visible = true, transformation(origin = {30, 24}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
protected
  discrete Modelica.SIunits.Time entryTime "Time instant when u became true";
initial equation
  pre(entryTime) = 0;
equation
  when true then
    LTime = time;
  end when;
  LTime = if u then time - LTime
  else 0.0;
 
  connect(capacitor.n, ground.p) annotation(
    Line(points = {{30, -34}, {-20, -34}, {-20, -56}, {-70, -56}}, color = {0, 0, 255}));
  connect(switch.p, resistor.p) annotation(
    Line(points = {{-32, 74}, {30, 74}, {30, 70}}, color = {0, 0, 255}));
  connect(constantVoltage.n, ground.p) annotation(
    Line(points = {{-78, 4}, {-70, 4}, {-70, -56}}, color = {0, 0, 255}));
  connect(constantVoltage.p, switch.n1) annotation(
    Line(points = {{-78, 24}, {-74, 24}, {-74, 70}, {-52, 70}}, color = {0, 0, 255}));
  connect(switch.n2, ground.p) annotation(
    Line(points = {{-52, 74}, {-98, 74}, {-98, -56}, {-70, -56}}, color = {0, 0, 255}));
  connect(inductor.p, resistor.n) annotation(
    Line(points = {{30, 34}, {30, 50}}, color = {0, 0, 255}));
  connect(realExpression.y, inductor.L) annotation(
    Line(points = {{58, 24}, {42, 24}}, color = {0, 0, 127}));
  connect(capacitor.p, inductor.n) annotation(
    Line(points = {{30, -14}, {30, 14}}, color = {0, 0, 255}));
  connect(booleanPulse.y, switch.control) annotation(
    Line(points = {{-34, 20}, {-16, 20}, {-16, 48}, {-42, 48}, {-42, 62}, {-42, 62}}, color = {255, 0, 255}));
  annotation(
    uses(Modelica(version = "3.2.3")));
end Test3;

Edited by: Getudan - Jan-13-20 16:03:46

Re: Resting Time to Zero at a Switching Voltage

Sorry, but I can't help too much. I would say that in order to reset LTime every time that u is true you need some thing as this in the equation section:
 
LTime = time-entryTime;
  when u then
    entryTime = time;
  end when;

But I do not know how do you determine that u is true. It is also strange for me to see LTime and u with the input qualifier as this is not a function or a connector.

Re: Resting Time to Zero at a Switching Voltage

Thanks for your response!

The idea was to represent an out put of a Boolean true value with u. Do you any idea on how to get/use an out put of a Boolean value?

Thanks again!

Re: Resting Time to Zero at a Switching Voltage

It seems clear that you need to give value to u in some way. You can declare it just as a Boolean, and to determine its value inside your model.
for example:
  if LTime>0.2 then
    u=true;
  else
    u=false;
  end if;
This will produce LTime to reinitialize every 0.2 seconds. Although here it is easier to put the condition inside the when statement and no need for u.

I think that another possibility should be to declare u as:

Modelica.Blocks.Interfaces.BooleanInput u;

In this way u becomes a connector, and you should be able to connect it with a BooleanOutput connector,  for example with a BooleanPulse, as the one you are already using in the switch. But I have tested this and the old frontend tells me that I am connecting two signal sources, and really I can't understand this. Probably is due to the fact that the BooleanInput should be inside a model part, not directly in the model.

Re: Resting Time to Zero at a Switching Voltage

How should I declare LTime?
Would the below work?
type LTime = Real(unit = "Sec");

Re: Resting Time to Zero at a Switching Voltage

Please bear with me, the shame!
How do I declare LTime as Boolean?

Re: Resting Time to Zero at a Switching Voltage

I understand that you need LTime as a Real, as you are using it for controlling the time. The declaration is immediate:
Modelica.SIunits.Time LTime;
I do not understand why you build types that are already defined in Modelica.
If you declare LTime as boolean, using
Boolean LTime;
It will be impossible to use it for time control.

Re: Resting Time to Zero at a Switching Voltage

Just one sugestion. If you tell me with which condition you want to reinitialize the timer, i will send you a possible implementation.

Re: Resting Time to Zero at a Switching Voltage

Well; I have prapared a possible solution. The determination of the event to restart the timer is done by a pulse generator (you can change this as needed). I have used connectors, and yes the problem was due to the fact that it is not allowed to connect connectors at the outer (main model) level. I have changed the switch rate, because it has no sense to switch at a speed much faster than the interval of the simulation.

ModelicaTest9.mo

Attachments:

Re: Resting Time to Zero at a Switching Voltage

YOU ARE THE MAN!!
I don't know how I can thank you!!!

Beer?

Re: Resting Time to Zero at a Switching Voltage

OK

A virtual beer coming!

Good luck!

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