Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
cc40a3c0
Commit
cc40a3c0
authored
Jan 27, 2012
by
cjt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated schematic tool files
parent
73622538
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
24 deletions
+43
-24
js/cktsim.js
+43
-24
js/schematic.js
+0
-0
No files found.
js/cktsim.js
View file @
cc40a3c0
...
@@ -44,6 +44,7 @@ cktsim = (function() {
...
@@ -44,6 +44,7 @@ cktsim = (function() {
this
.
devices
=
[];
// list of devices
this
.
devices
=
[];
// list of devices
this
.
device_map
=
new
Array
();
// map name -> device
this
.
device_map
=
new
Array
();
// map name -> device
this
.
voltage_sources
=
[];
// list of voltage sources
this
.
finalized
=
false
;
this
.
finalized
=
false
;
this
.
diddc
=
false
;
this
.
diddc
=
false
;
...
@@ -104,10 +105,14 @@ cktsim = (function() {
...
@@ -104,10 +105,14 @@ cktsim = (function() {
var
type
=
component
[
0
];
var
type
=
component
[
0
];
// ignore wires, ground connections, scope probes and view info
// ignore wires, ground connections, scope probes and view info
if
(
type
==
'view'
||
type
==
'w'
||
type
==
'g'
||
type
==
's'
||
type
==
'L'
)
continue
;
if
(
type
==
'view'
||
type
==
'w'
||
type
==
'g'
||
type
==
's'
||
type
==
'L'
)
{
continue
;
}
var
properties
=
component
[
2
];
var
properties
=
component
[
2
];
var
name
=
properties
[
'name'
];
var
name
=
properties
[
'name'
];
if
(
name
==
undefined
||
name
==
''
)
name
=
'_'
+
properties
[
'_json_'
].
toString
();
// convert node names to circuit indicies
// convert node names to circuit indicies
var
connections
=
component
[
3
];
var
connections
=
component
[
3
];
...
@@ -134,11 +139,9 @@ cktsim = (function() {
...
@@ -134,11 +139,9 @@ cktsim = (function() {
else
if
(
type
==
'o'
)
// op amp
else
if
(
type
==
'o'
)
// op amp
this
.
opamp
(
connections
[
0
],
connections
[
1
],
connections
[
2
],
properties
[
'A'
],
name
);
this
.
opamp
(
connections
[
0
],
connections
[
1
],
connections
[
2
],
properties
[
'A'
],
name
);
else
if
(
type
==
'n'
)
// n fet
else
if
(
type
==
'n'
)
// n fet
this
.
n
(
connections
[
0
],
connections
[
1
],
connections
[
2
],
this
.
n
(
connections
[
0
],
connections
[
1
],
connections
[
2
],
properties
[
'W/L'
],
name
);
properties
[
'W/L'
],
name
);
else
if
(
type
==
'p'
)
// p fet
else
if
(
type
==
'p'
)
// p fet
this
.
p
(
connections
[
0
],
connections
[
1
],
connections
[
2
],
this
.
p
(
connections
[
0
],
connections
[
1
],
connections
[
2
],
properties
[
'W/L'
],
name
);
properties
[
'W/L'
],
name
);
}
}
}
}
...
@@ -214,10 +217,16 @@ cktsim = (function() {
...
@@ -214,10 +217,16 @@ cktsim = (function() {
this
.
diddc
=
true
;
this
.
diddc
=
true
;
// create solution dictionary
// create solution dictionary
var
result
=
new
Array
();
var
result
=
new
Array
();
// capture node voltages
for
(
var
name
in
this
.
node_map
)
{
for
(
var
name
in
this
.
node_map
)
{
var
index
=
this
.
node_map
[
name
];
var
index
=
this
.
node_map
[
name
];
result
[
name
]
=
(
index
==
-
1
)
?
0
:
this
.
solution
[
index
];
result
[
name
]
=
(
index
==
-
1
)
?
0
:
this
.
solution
[
index
];
}
}
// capture branch currents from voltage sources
for
(
var
i
=
this
.
voltage_sources
.
length
-
1
;
i
>=
0
;
--
i
)
{
var
v
=
this
.
voltage_sources
[
i
];
result
[
'I('
+
v
.
name
+
')'
]
=
this
.
solution
[
v
.
branch
];
}
return
result
;
return
result
;
}
}
}
}
...
@@ -457,6 +466,12 @@ cktsim = (function() {
...
@@ -457,6 +466,12 @@ cktsim = (function() {
var
index
=
this
.
node_map
[
name
];
var
index
=
this
.
node_map
[
name
];
result
[
name
]
=
(
index
==
-
1
)
?
0
:
response
[
index
];
result
[
name
]
=
(
index
==
-
1
)
?
0
:
response
[
index
];
}
}
// capture branch currents from voltage sources
for
(
var
i
=
this
.
voltage_sources
.
length
-
1
;
i
>=
0
;
--
i
)
{
var
v
=
this
.
voltage_sources
[
i
];
result
[
'I('
+
v
.
name
+
')'
]
=
response
[
v
.
branch
];
}
result
[
'time'
]
=
response
[
this
.
N
];
result
[
'time'
]
=
response
[
this
.
N
];
return
result
;
return
result
;
}
}
...
@@ -537,6 +552,7 @@ cktsim = (function() {
...
@@ -537,6 +552,7 @@ cktsim = (function() {
Circuit
.
prototype
.
add_device
=
function
(
d
,
name
)
{
Circuit
.
prototype
.
add_device
=
function
(
d
,
name
)
{
// Add device to list of devices and to device map
// Add device to list of devices and to device map
this
.
devices
.
push
(
d
);
this
.
devices
.
push
(
d
);
d
.
name
=
name
;
if
(
name
)
{
if
(
name
)
{
if
(
this
.
device_map
[
name
]
===
undefined
)
if
(
this
.
device_map
[
name
]
===
undefined
)
this
.
device_map
[
name
]
=
d
;
this
.
device_map
[
name
]
=
d
;
...
@@ -599,6 +615,7 @@ cktsim = (function() {
...
@@ -599,6 +615,7 @@ cktsim = (function() {
Circuit
.
prototype
.
v
=
function
(
n1
,
n2
,
v
,
name
)
{
Circuit
.
prototype
.
v
=
function
(
n1
,
n2
,
v
,
name
)
{
var
branch
=
this
.
node
(
undefined
,
T_CURRENT
);
var
branch
=
this
.
node
(
undefined
,
T_CURRENT
);
var
d
=
new
VSource
(
n1
,
n2
,
branch
,
v
);
var
d
=
new
VSource
(
n1
,
n2
,
branch
,
v
);
this
.
voltage_sources
.
push
(
d
);
return
this
.
add_device
(
d
,
name
);
return
this
.
add_device
(
d
,
name
);
}
}
...
@@ -1029,9 +1046,11 @@ cktsim = (function() {
...
@@ -1029,9 +1046,11 @@ cktsim = (function() {
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// argument is a string describing the source's value (see comments for details)
// argument is a string describing the source's value (see comments for details)
// source types: dc,step,square,triangle,sin,pulse,pwl,pwl
r
// source types: dc,step,square,triangle,sin,pulse,pwl,pwl
_repeating
// returns an object with the following attributes:
// returns an object with the following attributes:
// fun -- name of source function
// args -- list of argument values
// value(t) -- compute source value at time t
// value(t) -- compute source value at time t
// inflection_point(t) -- compute time after t when a time point is needed
// inflection_point(t) -- compute time after t when a time point is needed
// dc -- value at time 0
// dc -- value at time 0
...
@@ -1071,32 +1090,35 @@ cktsim = (function() {
...
@@ -1071,32 +1090,35 @@ cktsim = (function() {
// post-processing for constant sources
// post-processing for constant sources
// dc(v)
// dc(v)
if
(
src
.
fun
==
'dc'
)
{
if
(
src
.
fun
==
'dc'
)
{
var
v
alue
=
src
.
args
[
0
]
;
var
v
=
arg_value
(
src
.
args
,
0
,
0
)
;
if
(
value
===
undefined
)
value
=
0
;
src
.
args
=
[
v
]
;
src
.
value
=
function
(
t
)
{
return
v
alue
;
}
// closure
src
.
value
=
function
(
t
)
{
return
v
;
}
// closure
}
}
// post-processing for step sources
// post-processing for step sources
// step(v_init,v_plateau,t_delay,t_rise
,t_fall
)
// step(v_init,v_plateau,t_delay,t_rise)
else
if
(
src
.
fun
==
'step'
)
{
else
if
(
src
.
fun
==
'step'
)
{
var
v1
=
arg_value
(
src
.
args
,
0
,
0
);
// default init value: 0V
var
v1
=
arg_value
(
src
.
args
,
0
,
0
);
// default init value: 0V
var
v2
=
arg_value
(
src
.
args
,
1
,
1
);
// default plateau value: 1V
var
v2
=
arg_value
(
src
.
args
,
1
,
1
);
// default plateau value: 1V
var
td
=
Math
.
max
(
0
,
arg_value
(
src
.
args
,
2
,
0
));
// time step starts
var
td
=
Math
.
max
(
0
,
arg_value
(
src
.
args
,
2
,
0
));
// time step starts
var
tr
=
Math
.
abs
(
arg_value
(
src
.
args
,
3
,
1
e
-
9
));
// default rise time: 1ns
var
tr
=
Math
.
abs
(
arg_value
(
src
.
args
,
3
,
1
e
-
9
));
// default rise time: 1ns
src
.
args
=
[
v1
,
v2
,
td
,
tr
];
// remember any defaulted values
pwl_source
(
src
,[
td
,
v1
,
td
+
tr
,
v2
],
false
);
pwl_source
(
src
,[
td
,
v1
,
td
+
tr
,
v2
],
false
);
}
}
// post-processing for square wave
// post-processing for square wave
// square(v_init,v_plateau,
t_period
)
// square(v_init,v_plateau,
freq
)
else
if
(
src
.
fun
==
'square'
)
{
else
if
(
src
.
fun
==
'square'
)
{
var
v1
=
arg_value
(
src
.
args
,
0
,
0
);
// default init value: 0V
var
v1
=
arg_value
(
src
.
args
,
0
,
0
);
// default init value: 0V
var
v2
=
arg_value
(
src
.
args
,
1
,
1
);
// default plateau value: 1V
var
v2
=
arg_value
(
src
.
args
,
1
,
1
);
// default plateau value: 1V
var
freq
=
Math
.
abs
(
arg_value
(
src
.
args
,
2
,
1
));
// default frequency: 1s
var
freq
=
Math
.
abs
(
arg_value
(
src
.
args
,
2
,
1
));
// default frequency: 1Hz
src
.
args
=
[
v1
,
v2
,
freq
];
// remember any defaulted values
var
per
=
freq
==
0
?
Infinity
:
1
/
freq
;
var
per
=
freq
==
0
?
Infinity
:
1
/
freq
;
var
t_change
=
0.01
*
per
;
// rise and fall time
var
t_change
=
0.01
*
per
;
// rise and fall time
var
t_pw
=
0.49
*
per
;
// half the cycle minus rise and fall time
var
t_pw
=
0.49
*
per
;
// half the cycle minus rise and fall time
pwl_source
(
src
,[
0
,
v1
,
t_change
,
v2
,
t_change
+
t_pw
,
v2
,
t_change
+
t_pw
+
t_change
,
v1
,
per
,
v1
],
true
);
pwl_source
(
src
,[
0
,
v1
,
t_change
,
v2
,
t_change
+
t_pw
,
v2
,
t_change
+
t_pw
+
t_change
,
v1
,
per
,
v1
],
true
);
}
}
// post-processing for triangle
// post-processing for triangle
...
@@ -1105,6 +1127,7 @@ cktsim = (function() {
...
@@ -1105,6 +1127,7 @@ cktsim = (function() {
var
v1
=
arg_value
(
src
.
args
,
0
,
0
);
// default init value: 0V
var
v1
=
arg_value
(
src
.
args
,
0
,
0
);
// default init value: 0V
var
v2
=
arg_value
(
src
.
args
,
1
,
1
);
// default plateau value: 1V
var
v2
=
arg_value
(
src
.
args
,
1
,
1
);
// default plateau value: 1V
var
freq
=
Math
.
abs
(
arg_value
(
src
.
args
,
2
,
1
));
// default frequency: 1s
var
freq
=
Math
.
abs
(
arg_value
(
src
.
args
,
2
,
1
));
// default frequency: 1s
src
.
args
=
[
v1
,
v2
,
freq
];
// remember any defaulted values
var
per
=
freq
==
0
?
Infinity
:
1
/
freq
;
var
per
=
freq
==
0
?
Infinity
:
1
/
freq
;
pwl_source
(
src
,[
0
,
v1
,
per
/
2
,
v2
,
per
,
v1
],
true
);
pwl_source
(
src
,[
0
,
v1
,
per
/
2
,
v2
,
per
,
v1
],
true
);
...
@@ -1112,8 +1135,8 @@ cktsim = (function() {
...
@@ -1112,8 +1135,8 @@ cktsim = (function() {
// post-processing for pwl and pwlr sources
// post-processing for pwl and pwlr sources
// pwl[r](t1,v1,t2,v2,...)
// pwl[r](t1,v1,t2,v2,...)
else
if
(
src
.
fun
==
'pwl'
||
src
.
fun
==
'pwl
r
'
)
{
else
if
(
src
.
fun
==
'pwl'
||
src
.
fun
==
'pwl
_repeating
'
)
{
pwl_source
(
src
,
src
.
args
,
src
.
fun
==
'pwl
r
'
);
pwl_source
(
src
,
src
.
args
,
src
.
fun
==
'pwl
_repeating
'
);
}
}
// post-processing for pulsed sources
// post-processing for pulsed sources
...
@@ -1122,18 +1145,18 @@ cktsim = (function() {
...
@@ -1122,18 +1145,18 @@ cktsim = (function() {
var
v1
=
arg_value
(
src
.
args
,
0
,
0
);
// default init value: 0V
var
v1
=
arg_value
(
src
.
args
,
0
,
0
);
// default init value: 0V
var
v2
=
arg_value
(
src
.
args
,
1
,
1
);
// default plateau value: 1V
var
v2
=
arg_value
(
src
.
args
,
1
,
1
);
// default plateau value: 1V
var
td
=
Math
.
max
(
0
,
arg_value
(
src
.
args
,
2
,
0
));
// time pulse starts
var
td
=
Math
.
max
(
0
,
arg_value
(
src
.
args
,
2
,
0
));
// time pulse starts
var
tr
=
Math
.
abs
(
arg_value
(
src
.
args
,
3
,
1
e
-
9
));
// default rise time: 1ns
var
tr
=
Math
.
abs
(
arg_value
(
src
.
args
,
3
,
1
e
-
9
));
// default rise time: 1ns
var
tf
=
Math
.
abs
(
arg_value
(
src
.
args
,
4
,
1
e
-
9
));
// default rise time: 1ns
var
tf
=
Math
.
abs
(
arg_value
(
src
.
args
,
4
,
1
e
-
9
));
// default rise time: 1ns
var
pw
=
Math
.
abs
(
arg_value
(
src
.
args
,
5
,
1
e9
));
// default pulse width: "infinite"
var
pw
=
Math
.
abs
(
arg_value
(
src
.
args
,
5
,
1
e9
));
// default pulse width: "infinite"
var
per
=
Math
.
abs
(
arg_value
(
src
.
args
,
6
,
1
e9
));
// default period: "infinite"
var
per
=
Math
.
abs
(
arg_value
(
src
.
args
,
6
,
1
e9
));
// default period: "infinite"
src
.
args
=
[
v1
,
v2
,
td
,
tr
,
tf
,
pw
,
per
];
var
t1
=
td
;
// time when v1 -> v2 transition starts
var
t1
=
td
;
// time when v1 -> v2 transition starts
var
t2
=
t1
+
tr
;
// time when v1 -> v2 transition ends
var
t2
=
t1
+
tr
;
// time when v1 -> v2 transition ends
var
t3
=
t2
+
pw
;
// time when v2 -> v1 transition starts
var
t3
=
t2
+
pw
;
// time when v2 -> v1 transition starts
var
t4
=
t3
+
tf
;
// time when v2 -> v1 transition ends
var
t4
=
t3
+
tf
;
// time when v2 -> v1 transition ends
pwl_source
(
src
,[
t1
,
v1
,
t2
,
v2
,
t3
,
v2
,
t4
,
v1
,
per
,
v1
],
true
);
pwl_source
(
src
,[
t1
,
v1
,
t2
,
v2
,
t3
,
v2
,
t4
,
v1
,
per
,
v1
],
true
);
}
}
// post-processing for sinusoidal sources
// post-processing for sinusoidal sources
...
@@ -1144,16 +1167,14 @@ cktsim = (function() {
...
@@ -1144,16 +1167,14 @@ cktsim = (function() {
var
freq
=
Math
.
abs
(
arg_value
(
src
.
args
,
2
,
1
));
// default frequency: 1Hz
var
freq
=
Math
.
abs
(
arg_value
(
src
.
args
,
2
,
1
));
// default frequency: 1Hz
var
td
=
Math
.
max
(
0
,
arg_value
(
src
.
args
,
3
,
0
));
// default time delay: 0sec
var
td
=
Math
.
max
(
0
,
arg_value
(
src
.
args
,
3
,
0
));
// default time delay: 0sec
var
phase
=
arg_value
(
src
.
args
,
4
,
0
);
// default phase offset: 0 degrees
var
phase
=
arg_value
(
src
.
args
,
4
,
0
);
// default phase offset: 0 degrees
src
.
args
=
[
voffset
,
va
,
freq
,
td
,
phase
];
phase
/=
360.0
;
phase
/=
360.0
;
// return value of source at time t
// return value of source at time t
src
.
value
=
function
(
t
)
{
// closure
src
.
value
=
function
(
t
)
{
// closure
if
(
t
<
td
)
return
voffset
+
va
*
Math
.
sin
(
2
*
Math
.
PI
*
phase
);
if
(
t
<
td
)
return
voffset
+
va
*
Math
.
sin
(
2
*
Math
.
PI
*
phase
);
else
{
else
return
voffset
+
va
*
Math
.
sin
(
2
*
Math
.
PI
*
(
freq
*
(
t
-
td
)
+
phase
));
var
val
=
voffset
+
va
*
Math
.
sin
(
2
*
Math
.
PI
*
(
freq
*
(
t
-
td
)
+
phase
));
return
val
;
}
}
}
// return time of next inflection point after time t
// return time of next inflection point after time t
...
@@ -1163,9 +1184,6 @@ cktsim = (function() {
...
@@ -1163,9 +1184,6 @@ cktsim = (function() {
}
}
}
}
// to do:
// post-processing for piece-wise linear sources
// object has all the necessary info to compute the source value and inflection points
// object has all the necessary info to compute the source value and inflection points
src
.
dc
=
src
.
value
(
0
);
// DC value is value at time 0
src
.
dc
=
src
.
value
(
0
);
// DC value is value at time 0
return
src
;
return
src
;
...
@@ -1531,6 +1549,7 @@ cktsim = (function() {
...
@@ -1531,6 +1549,7 @@ cktsim = (function() {
var
module
=
{
var
module
=
{
'Circuit'
:
Circuit
,
'Circuit'
:
Circuit
,
'parse_number'
:
parse_number
,
'parse_number'
:
parse_number
,
'parse_source'
:
parse_source
,
}
}
return
module
;
return
module
;
}());
}());
js/schematic.js
View file @
cc40a3c0
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment