I will try to keep the explanations as simple as possible but as detailed as necessary.
I started to model a phase angle control which I tested in a simple electrical circuit.
At every timestep of the simulation I need the angle (only between 0 and 180 degrees) of the feeding voltage source.
Therefore I introduced a new block called "angle". This is the only block I developed myself, all other components are taken from the library (2.2).
The circuit works fine if the voltage source is connected directly to the phase angle control (IdealPhaseControl.mo). If it is connected in series with a resistor (resistor1) I get an error during the translation:
"Error: The current version of Dymola cannot generate code for algebraic loops involving when equations or algorithms with when parts.
You may be able to cut the loop
by putting 'pre' around some of the references to unknown continuous time variables in when parts.".
If I leave the resistor resistor1 this error doesnīt occur. This is really confusing me.
Iīve read through the code over and over again but I couldnīt find any mistake. So it seems that I do not understand a very basic characteristic of Modelica!?
This is the code of the block "angle". Maybe the mistake is so obvious that it is not necessary to look at the complete "TEST_PhasControl"-system.
CODE
block angle "Measuring the angle of a periodic signal"
annotation (
uses(Modelica(version="2.2")),
Diagram,
Icon(Text(
extent=[-40,36; 42,-40],
style(color=3, rgbcolor={0,0,255}),
string="angle")));
extends Modelica.Blocks.Interfaces.SISO; protected
Boolean u_pos(start=false);
Real period_duration(start=0.0);
Real eventtime;
algorithm
u_pos := u >= 0;
//Setting the output
y := if period_duration > 0.0001 then 180*(time - eventtime)/period_duration else
0.0;
//Event at zero crossing
when change(u_pos) == true then
period_duration := time - eventtime;
eventtime := time;
end when;
end angle;
annotation (
uses(Modelica(version="2.2")),
Diagram,
Icon(Text(
extent=[-40,36; 42,-40],
style(color=3, rgbcolor={0,0,255}),
string="angle")));
extends Modelica.Blocks.Interfaces.SISO; protected
Boolean u_pos(start=false);
Real period_duration(start=0.0);
Real eventtime;
algorithm
u_pos := u >= 0;
//Setting the output
y := if period_duration > 0.0001 then 180*(time - eventtime)/period_duration else
0.0;
//Event at zero crossing
when change(u_pos) == true then
period_duration := time - eventtime;
eventtime := time;
end when;
end angle;
Maybe you can help me.
Itīs a bit difficult to explain the whole system here so I start posting only the block I developed an I attach a picture of the phase angle control Click to view attachment and of the complete system Click to view attachment.
Thanks a lot.
