Group Abstract Group Abstract

Message Boards Message Boards

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

Modelica language question

Posted 12 years ago
POSTED BY: Fulvio Spagna
4 Replies
Posted 12 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 12 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 12 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 12 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