Ticket #2648: PulseSource.mo

File PulseSource.mo, 6.3 KB (added by Volker Waurich, 12 years ago)
Line 
1within ;
2model PulseSource "Simple inverter circuit"
3//--------------------------------------------------------------------------------------------------------------
4
5//--------------------------------------------------------------------------------------------------------------
6 extends Modelica.Icons.Example;
7
8encapsulated model V_pulse "Pulse voltage source"
9extends Modelica.Electrical.Analog.Interfaces.OnePort;
10 import Modelica;
11
12 parameter Modelica.SIunits.Voltage V1=0 "Initial value";
13 parameter Modelica.SIunits.Voltage V2=0 "Pulsed value";
14 parameter Modelica.SIunits.Time TD=0.0 "Delay time";
15 parameter Modelica.SIunits.Time TR(start=1) "Rise time";
16 parameter Modelica.SIunits.Time TF=TR "Fall time";
17 parameter Modelica.SIunits.Time PW=Modelica.Constants.inf "Pulse width";
18 parameter Modelica.SIunits.Time PER=Modelica.Constants.inf "Period";
19
20 protected
21 parameter Modelica.SIunits.Time Trising=TR
22 "End time of rising phase within one period";
23 parameter Modelica.SIunits.Time Twidth=Trising + PW
24 "End time of width phase within one period";
25 parameter Modelica.SIunits.Time Tfalling=Twidth + TF
26 "End time of falling phase within one period";
27 Modelica.SIunits.Time T0(final start=TD) "Start time of current period";
28 Integer counter(start=-1, fixed=true) "Period counter";
29 Integer counter2(start=-1, fixed=true);
30
31equation
32 when pre(counter2) <> 0 and sample(TD, PER) then
33 T0 = time;
34 counter2 = pre(counter);
35 counter = pre(counter) - (if pre(counter) > 0 then 1 else 0);
36 end when;
37 v = V1 + (if (time < TD or counter2 == 0 or time >= T0 +
38 Tfalling) then 0 else if (time < T0 + Trising) then (time - T0)*
39 (V2-V1)/Trising else if (time < T0 + Twidth) then V2-V1 else
40 (T0 + Tfalling - time)*(V2-V1)/(Tfalling - Twidth));
41
42 annotation (
43 Icon(coordinateSystem(
44 preserveAspectRatio=false,
45 extent={{-100,-100},{100,100}},
46 grid={1,1}), graphics={
47 Text(
48 extent={{-120,49},{-20,-1}},
49 lineColor={0,0,255},
50 textString="+"),
51 Text(
52 extent={{25,53},{125,3}},
53 lineColor={0,0,255},
54 textString="-"),
55 Text(
56 extent={{-157,-62},{143,-102}},
57 textString="%name",
58 lineColor={0,0,255}),
59 Ellipse(
60 extent={{-51,50},{49,-50}},
61 lineColor={0,0,255},
62 fillColor={255,255,255},
63 fillPattern=FillPattern.Solid),
64 Line(points={{-90,0},{50,0}}, color={0,0,255}),
65 Line(points={{50,0},{90,0}}, color={0,0,255}),
66 Line(points={{-86,-74},{-65,-74},{-35,66},{-4,66},{25,-74},{46,-74},
67 {75,66}}, color={192,192,192})}),
68 Diagram(coordinateSystem(
69 preserveAspectRatio=false,
70 extent={{-100,-100},{100,100}},
71 grid={1,1}), graphics),
72 Window(
73 x=0.21,
74 y=0.22,
75 width=0.6,
76 height=0.63),
77 Documentation(info="<html>
78<p>Periodic pulse source with not limited number of periods.</p>
79<p>A single pulse is described by the following table:</p>
80<table cellspacing=\"2\" cellpadding=\"0\" border=\"0\"><tr>
81<td><h4>time</h4></td>
82<td><h4>value</h4></td>
83</tr>
84<tr>
85<td><p>0</p></td>
86<td><p>V1</p></td>
87</tr>
88<tr>
89<td><p>TD</p></td>
90<td><p>V1</p></td>
91</tr>
92<tr>
93<td><p>TD+TR</p></td>
94<td><p>V2</p></td>
95</tr>
96<tr>
97<td><p>TD+TR+PW</p></td>
98<td><p>V2</p></td>
99</tr>
100<tr>
101<td><p>TD+TR+PW+TF</p></td>
102<td><p>V1</p></td>
103</tr>
104<tr>
105<td><p>TSTOP</p></td>
106<td><p>V1</p></td>
107</tr>
108</table>
109<p>Intermediate points are determined by linear interpolation.</p>
110<p>A pulse it looks like a saw tooth, use this parameters e.g.:</p>
111<table cellspacing=\"2\" cellpadding=\"2\" border=\"1\"><tr>
112<td><h4>Parameter</h4></td>
113<td><h4>Value</h4></td>
114</tr>
115<tr>
116<td><p>V1</p></td>
117<td><p>0</p></td>
118</tr>
119<tr>
120<td><p>V2</p></td>
121<td><p>1</p></td>
122</tr>
123<tr>
124<td><p>TD</p></td>
125<td><p>0</p></td>
126</tr>
127<tr>
128<td><p>TR</p></td>
129<td><p>1</p></td>
130</tr>
131<tr>
132<td><p>TF</p></td>
133<td><p>1</p></td>
134</tr>
135<tr>
136<td><p>PW</p></td>
137<td><p>2</p></td>
138</tr>
139<tr>
140<td><p>PER</p></td>
141<td><p>1</p></td>
142</tr>
143</table>
144<h4>Note:</h4>
145<ul>
146<li>All parameters of sources should be set explicitly.</li>
147<li>since TSTEP and TSTOP are not available for modeling in Modelica, differences to SPICE may occur if not all parameters are set.</li>
148</ul>
149</html>"),
150 uses(Modelica(version="3.2")));
151end V_pulse;
152
153 Modelica.Electrical.Spice3.Basic.Ground ground
154 annotation (Placement(transformation(extent={{-14,-60},{6,-40}})));
155 V_pulse vin(
156 V2=5,
157 TD=4e-12,
158 TR=0.1e-12,
159 TF=0.1e-12,
160 PW=1e-12,
161 PER=2e-12) annotation (Placement(transformation(
162 extent={{-10,-10},{10,10}},
163 rotation=270,
164 origin={-40,-16})));
165 Modelica.Electrical.Analog.Basic.Resistor resistor(R=1) annotation (Placement(
166 transformation(
167 extent={{-10,-10},{10,10}},
168 rotation=270,
169 origin={-4,-16})));
170equation
171 connect(vin.n, ground.p) annotation (Line(
172 points={{-40,-26},{-40,-40},{-4,-40}},
173 color={0,0,0},
174 smooth=Smooth.None));
175 connect(ground.p, resistor.n) annotation (Line(
176 points={{-4,-40},{-4,-26}},
177 color={0,0,255},
178 smooth=Smooth.None));
179 connect(vin.p, resistor.p) annotation (Line(
180 points={{-40,-6},{-4,-6}},
181 color={0,0,255},
182 smooth=Smooth.None));
183 annotation ( Diagram(
184 coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100,100}}),
185 graphics),
186 Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{
187 100,100}}), graphics),
188 experiment(
189 StopTime=1e-011,
190 NumberOfIntervals=2000,
191 Tolerance=1e-007),
192 Documentation(info="<html>
193<p>An inverter is an electrical circuit that consists of a PMOS and a NMOS transistor. Its task is to turn the input voltage from high potential to low potential or the other way round.</p>
194<p>Simulate until 1.e-11 s. Display the input voltage Vin.p.v as well as the output voltage mp.S.v. It shows that the input voltage is inverted.</p>
195</html>",
196 revisions="<html>
197<ul>
198<li><i>March 2009 </i>by Kristin Majetta initially implemented</li>
199</ul>
200</html>"),
201 uses(Modelica(version="3.2.1")),
202 __Dymola_experimentSetupOutput);
203end PulseSource;