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

Signal Routing, Triggering of State Machines

Signal Routing, Triggering of State Machines

Hi,

i'm fairly new to OM and having some problems with a project i'm working on. My task is to model a simplifierd Computer/Software which gets command packets as an input and routes the right signals to the according triggers of state machines. My main problem with the model i've come up with is that it doesn't allow repated alteration between two states since i used when equations so i can trigger a transition only once. Is there a good possibility to reset the trigger variable immediately after the transition of the state machine? The only solution i've come up with is to set back the signal manually after a certain amount of time because otherwise i'm always having to much equations.
Here is a basic example of my code (Trigger Variables: outPortOn.Signal, outPortOff.Signal):

Code:


class Simulator
  Console console;
  PacketRouter packetrouter;
  Buffer buffer;
 
  equation
 
   connect(console.outPort,packetrouter.inPort);
   connect(packetrouter.outPortOn,buffer.inPortOn);
   connect(packetrouter.outPortOff,buffer.inPortOff);
 
end Simulator;

connector Port
  Boolean Signal;
end Port;

connector PacketPort
  extends Port;
  Integer Address;
end PacketPort;

class Console
  PacketPort outPort;
 
  equation
 
  when time >= 8 then
    outPort.Signal=true;
    outPort.Address=0;
  elsewhen time >= 6 then
    outPort.Signal=true;
    outPort.Address=1;
  elsewhen time >= 4 then
    outPort.Signal=true;
    outPort.Address=0;
  elsewhen time >= 2 then
    outPort.Signal=true;
    outPort.Address=1;
  end when;
 
end Console;

class PacketRouter
  PacketPort inPort;
  Port outPortOn;
  Port outPortOff;
 
  equation
 
  when inPort.Address==1 then
    outPortOn.Signal=inPort.Signal;
  end when;

  when inPort.Address==0 then
    outPortOff.Signal=inPort.Signal;
  end when;
     
end PacketRouter;

class Buffer
  Port inPortOn;
  Port inPortOff;
  Port outPortOn;
  Port outPortOff;
 
  equation
 
  when sample(0,1) then
   outPortOn.Signal=inPortOn.Signal;
   outPortOff.Signal=inPortOff.Signal;
  end when;
 
end Buffer;

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