Skip to content

Commit

Permalink
Add example for shiftSample. (modelica#3233)
Browse files Browse the repository at this point in the history
* Add example for shiftSample.
Closes modelica#3040
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
  • Loading branch information
HansOlsson committed Sep 9, 2022
1 parent 987fd43 commit d33adc1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions chapters/synchronous.tex
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,22 @@ \subsection{Sub-Clock Conversion Operators}\label{sub-clock-conversion-operators
Clock y1 = shiftSample(u, 2); // ticks: 2.0, 3.0, $\ldots$
Clock y2 = shiftSample(u, 2, 3); // error (resolution must be 1)
\end{lstlisting}
Additional example showing the full form:
\begin{lstlisting}[language=modelica]
Integer intervalCnt(start=2);
Integer cnt(start=0);
Clock u = Clock(intervalCnt,1);
Clock s1 = shiftSample(u, 3, 2);
equation
when u then
cnt = previous(cnt) + 1;
intervalCnt = if (cnt>=2) then 1 else previous(intervalCnt);
end when;
\end{lstlisting}
Here \lstinline!u! ticks at 0, 2, 3, 4, 5, 6.
First you \lstinline!superSample! to split each sampling interval in two equal parts leading to the ticks 0.0, 1.0, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0.
Then the simple \lstinline!shiftSample! removes the first three ticks giving 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0.
And finally every other point is removed by \lstinline!subSample!, and \lstinline!s1! ticks at 2.5, 3.5, 4.5, 5.5.
\end{nonnormative}
\end{semantics}
\end{operatordefinition}
Expand Down

0 comments on commit d33adc1

Please sign in to comment.