Opened 9 years ago
Last modified 3 years ago
#3771 closed defect
Wrong clock interval — at Version 3
Reported by: | Niklas Worschech | Owned by: | Lennart Ochel |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | Backend | Version: | |
Keywords: | Modelica_Synchronous, synchronous features, cpp runtime | Cc: | Rüdiger Franke, Bernhard Thiele, Volker Waurich |
Description (last modified by )
For the following example it appears the clock interval calculation is not correct
model TestClock Integer nextInterval(start=1); Clock c = Clock(nextInterval,210); equation when c then nextInterval = previous(nextInterval) + 1; end when; end TestClock;
For the next clock interval the following equation is generated:
_clockInterval[0] =(_$CLKPRE_P_nextInterval / 210.0) * 1.0 / 1.0;
I think to calculate the next clock interval, instead of the previous interval value the current interval value should be used.
In the cpp runtime the next clock interval is calculated after the evaluation of the corresponding clock equations
_$CLKPRE_P_nextInterval = _nextInterval;
nextInterval = (1 + _$CLKPRE_P_nextInterval);
_clockInterval[0] = (_$CLKPRE_P_nextInterval / 210.0) * 1.0 / 1.0;
At time=0 when the clock ticks for the first time, previous(interval)=1 but it should be interval = 2 to calculate the correct next clock interval.
Change History (3)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Maybe the problem is the order of the equations.
_$CLKPRE_P_nextInterval = _nextInterval;
nextInterval = (1 + _$CLKPRE_P_nextInterval);
_clockInterval[0] = (_$CLKPRE_P_nextInterval / 210.0) * 1.0 / 1.0;
or the way how the previous value of nextInterval is stored.
comment:3 by , 9 years ago
Description: | modified (diff) |
---|
See ModelicaSpec33, section 16.3 Clock Constructors:
"The clock starts at the start of the simulation tstart or when the controller is switched on. Here the next clock tick is scheduled at
interval1 = previous(intervalCounter)/resolution = interval.start/resolution.
At the second clock tick at time tstart+interval1, the next clock tick is scheduled at
interval2 = previous(intervalCounter)/resolution, and so on."