- Index
- » Programming
- » Modelica Language
- » Execution Error due to loop of...
Execution Error due to loop of connectors in state machine
Execution Error due to loop of connectors in state machine
Hello everyone,
I have a problem with a simulation of a computer. The idea is to model the software and the processor as classes. The software can issue a command that switches off the processor. Since the software needs the processor "on" to run, it thereby kills itself. All this is based on state machines of the processor and the software. Both can be in one of the three modes "first", "on" or "off". The communication between the two classes is done via connectors that only transport a boolean signal (on/off).
When executing this in DRModelica I get a windows acces violation error which is due to the fact that at the moment of the switch-off of the processor, the software's port pc_state changes value and hence the if-condition inside the
Code:
when sample() then
clause changes as well.
I already tried several things to circumvent the issue, like delaying the processor switch off after the reception of the command. Or using
Code:
pre(pc_state.Signal)
, none of which seem to work.
Here are the three classes (SW, processor and a simple connector) plus a test class that is used to send the commands in the first place. Btw. please don't get distracted by the rather complicated state machine implementation.
Code:
connector Port
Boolean Signal;
end Port;
class SW
Port out_switchoff(Signal.start=false),out_switchon(Signal.start=false);
Port in_Proc_Off, in_Proc_On;
Port pc_state;
Boolean state_ON(start=true), state_OFF(start=false),init, first;
algorithm
//State machine initialisation
init:=true;
when {init} then
first:=true;
end when;
if first then
state_ON:=true;
first:=false;
state_OFF:=false;
end if;
//SW function
when sample(0.2,1) then
if pc_state.Signal then
out_switchoff.Signal := in_Proc_Off.Signal;
out_switchon.Signal := in_Proc_On.Signal;
end if;
end when;
end SW;
class Processor
Port in_switchoff , in_switchon;
Port pc_state;
Boolean state_ON(start=true), state_OFF(start=false),init, first;
algorithm
//State machine initialisation
init:=true;
when {init} then
first:=true;
end when;
if first then
state_ON:=true;
state_OFF:=false;
first:=false;
end if;
//reaction to switching signals
when in_switchoff.Signal then
state_OFF:=true;
state_ON:=false;
end when;
when in_switchon.Signal then
state_OFF:=false;
state_ON:=true;
end when;
//send info to SW
if state_ON then
pc_state.Signal:=true;
else
pc_state.Signal:=false;
end if;
end Processor;
class Test
Port out_Proc_Off,out_Proc_On;
SW sw;
Processor pc;
equation
connect(out_Proc_Off, sw.in_Proc_Off);
connect(sw.out_switchoff, pc.in_switchoff);
connect(sw.pc_state, pc.pc_state);
connect(sw.out_switchon, pc.in_switchon);
connect(out_Proc_On, sw.in_Proc_On);
when time>=4 then
out_Proc_Off.Signal=true;
out_Proc_On.Signal=false;
elsewhen time>=1 then
out_Proc_Off.Signal=false;
out_Proc_On.Signal=true; //both SW and PC are already ON, just to be sure
end when;
end Test;
Thank you already for your help. I hope we can work this out!
- Index
- » Programming
- » Modelica Language
- » Execution Error due to loop of...