Message Boards Message Boards

0
|
10554 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:
GROUPS:

Modelica language question

Posted 11 years ago

The code below, when checked in SystemModeler reports the following error message:

[133] 4:21:42 PM Validation of model test Validation of model test completed successfully. The model myCounter has 45 equations and 47 variables. 22 of these are non-trivial equations.

When I try to simulate this, the simulator reports:

Building "test" as experiment "test 1" started at 16:48:24 Error: [:0:0-0:0]Simulation model is not globally balanced, having 35 variables and 33 equations. Error: No executable generated C:/Users/fspagna/AppData/Local/Temp/3/sme.4.0.0141549410427740.exe Error: No settings file generated C:/Users/fspagna/AppData/Local/Temp/3/sme.4.0.0141549410427740_init.sim

It is not obvious (to me) what is wrong with this code so any help would be welcome. This also raises another more general question. How does one debug this kind of issued? The error messages are not very helpful and there does not seem to be any option to make them more verbose.

Thank you,

Fulvio

==========================================================

model test

import D = Modelica.Electrical.Digital; import L = Modelica.Electrical.Digital.Interfaces.Logic; import S = Modelica.Electrical.Digital.Interfaces.Strength; parameter Integer n=1; parameter Integer nn (min=1) = 2 "Number of bits"; parameter Modelica.SIunits.Time tHL = 0.1 "High->Low delay"; parameter Modelica.SIunits.Time tLH = 0.1 "Low->High delay"; parameter D.Interfaces.Strength strength = S.'S_X01' "output strength"; D.Registers.DFFREG FF[nn]; D.Basic.Not INV; D.Interfaces.DigitalInput reset; D.Interfaces.DigitalInput clock; D.Interfaces.DigitalOutput q[nn] ;

equation connect(clock, FF[1].clock); connect(reset, FF[1].reset); connect(FF[1].dataOut[1], q[1]); connect(FF[1].dataOut[1], FF[2].dataIn[1]);

connect(clock, FF[2].clock); connect(reset, FF[2].reset); connect(FF[2].dataOut[1], q[2]);

connect(FF[2].dataOut[1], INV.x); connect(INV.y, FF[1].dataIn[1]);

end test;

POSTED BY: Fulvio Spagna
4 Replies
Posted 10 years ago

Hello Johan

First of all, thank you for your reply. I am really glad you did what you did, because it highlights the crux of the problem I am having. The reason I wrote the code the way I did is that I am trying to make the number of FF variable. Think of it as something like the code below:

model test
  import D = Modelica.Electrical.Digital;
  import L = Modelica.Electrical.Digital.Interfaces.Logic;
  import S = Modelica.Electrical.Digital.Interfaces.Strength;
  parameter Integer n = 1;
  parameter Integer nn(min = 1) = 2 "Number of bits";
  parameter Modelica.SIunits.Time tHL = 0.1 "High->Low delay";
  parameter Modelica.SIunits.Time tLH = 0.1 "Low->High delay";
  parameter D.Interfaces.Strength strength = S.'S_X01' "output strength";
  D.Registers.DFFREG FF[nn](each tHL = tHL, each tLH = tLH);
  D.Gates.InvGate INV (tHL= tHL, tLH = tLH, y0 = L.'1');
  D.Interfaces.DigitalInput reset ;
  D.Interfaces.DigitalInput clock ;
  D.Interfaces.DigitalOutput q[nn] ;
equation
  connect(clock, FF[1].clock);
  connect(reset, FF[1].reset);
  connect(FF[1].dataOut[1], q[1]);
  connect(FF[nn].dataOut[1], INV.x);
  connect(INV.y, FF[2].dataIn[1]);
  for i in 2:nn loop
    connect(clock, FF[i].clock);
    connect(reset, FF[i].reset);
    connect(FF[i].dataOut[1], q[i]);
    connect(FF[i-1].dataOut[1], FF[i].dataIn[1]);
  end for
 end test;

As you can see, this defaults to the original code for nn=2 and, as in the original form, the checker complains that there is mismatch between the number of variables and the number of equations. I had noticed that writing the code in the form you suggested takes care of the problem but doing so removes, I think, the ability of making the number of FFs variable. So why is there a difference? To my, admittedly, uneducated eye, the two formulations should be equivalent and I am not sure why they are not.

Thank you,

Fulvio

POSTED BY: Fulvio Spagna
Posted 10 years ago

Fulvio, You are correct in that it should work the same. We're investigating this issue. I hope you can work around it for now by manually creating more instances.

POSTED BY: Johan Rhodin
Posted 10 years ago

Hi Johan,

It has now been four months since the original post was published and I have not hear anything on this topic. Can you give me an update?

Thank you,

Fulvio

POSTED BY: Fulvio Spagna
Posted 10 years ago

Some comments that might help:

You haven't connected any sources to the component, that would be needed for you to get a useful simulation. See Modelica.Electrical.Digital.Examples.DFFREG for an example of connecting (and initializing) sources.

To make it easier to debug I renamed FF[1], FF[2] to FF1 and FF2:

model test
  import D = Modelica.Electrical.Digital;
  import L = Modelica.Electrical.Digital.Interfaces.Logic;
  import S = Modelica.Electrical.Digital.Interfaces.Strength;
  parameter Integer n = 1;
  parameter Integer nn(min = 1) = 2 "Number of bits";
  parameter Modelica.SIunits.Time tHL = 0.1 "High->Low delay";
  parameter Modelica.SIunits.Time tLH = 0.1 "Low->High delay";
  parameter D.Interfaces.Strength strength = S.'S_X01' "output strength";
  D.Registers.DFFREG FF1;
  D.Registers.DFFREG FF2;
  D.Basic.Not INV;
  D.Interfaces.DigitalInput reset;
  D.Interfaces.DigitalInput clock;
  D.Interfaces.DigitalOutput q[nn];
equation
  connect(clock, FF1.clock);
  connect(reset, FF1.reset);
  connect(FF1.dataOut[1], q[1]);
  connect(FF1.dataOut[1], FF2.dataIn[1]);
  connect(clock, FF2.clock);
  connect(reset, FF2.reset);
  connect(FF2.dataOut[1], q[2]);
  connect(FF2.dataOut[1], INV.x);
  connect(INV.y, FF1.dataIn[1]);
end test;

The model now validates and has 47 equations and 47 variables. I hope that helps.

POSTED BY: Johan Rhodin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract