Ticket #6019: TDMclock2.mo

File TDMclock2.mo, 1.6 KB (added by Paul van der Hulst <p.van.der.hulst@…>, 5 years ago)
Line 
1model TDMclock2 "Digital clocked multiplexer index generator"
2 import SI = Modelica.SIunits;
3 parameter Integer nr_channels(final min=1) = 6;
4 parameter SI.Time period(
5 final min=Modelica.Constants.small)=0.09 "Time for one period";
6 Modelica.Blocks.Interfaces.IntegerOutput y( min=1,max=nr_channels, start = 1) "Connector of Digital output signal"
7 annotation (Placement(transformation(extent={{90,-10},{110,
8 10}})));
9 discrete Integer increment;
10 Clock cSample=Clock(period);
11equation
12 increment = sample(1,Clock(period));
13 y = if (time == 0 or previous(y)==nr_channels) then 1 else previous(y) + increment;
14 annotation (Documentation(info="<html>
15<p>
16The clock source generates an incrementing index number
17The number of periods is unlimited. The first pulse starts at startTime.
18</p>
19<p> The clock source is a special but often used variant of the pulse source.
20</p>
21</html>", revisions="<html>
22<dl>
23Based on 'Clock' library module by Andre Schneider
24<dt><em>June 9, 2020</em></dt>
25<dd>by Paul van der Hulst.</dd>
26</dl>
27</html>"),
28Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{
29 100,100}}), graphics={
30 Rectangle(
31 extent={{-50,100},{50,-100}},
32 lineThickness=0.5,
33 fillColor={213,255,170},
34 fillPattern=FillPattern.Solid),
35 Text(
36 extent={{152,-160},{-148,-100}},
37 lineColor={0,0,255},
38 textString="%name"),
39 Line(points={{50,0},{90,0}}, color={127,0,127}),
40 Line(points={{-36,80},{-30,80},{-30,40},{-18,40},{-18,50},{-6,50},{
41 -6,60},{6,60},{6,70},{18,70},{18,80},{30,80},{30,40},{36,40}})}));
42end TDMclock2;