jsl/circuits/Network¶
Package name: jsl/circuits/Network
Lump Circuit Networks
The concept of this code is to provide a means for defining a lumped circuit network tree. The idea is to provide a "DSL" for defining components that are used together to form a circuit network.
In this graph there are Elements and Nodes.
- Elements are the edges of the graph - the resistors, capacitors, etc.
- Nodes are the pins, ground, nets, etc of the circuit
We can think of the circuit network as a graph. We have the following operations to this graph for 2-pin elements
- Series (+) - string multiple elements in series
- Parallel (|) - put multiple elements in parallel
- Tap - For a particular node in the circuit graph, connect this node to an external port on the resultant network instantiable (pcb-module). The components are still connected on both sides in the network.
- ShuntTo - Connect a given node to a port through an element. This allows connecting a component that escapes the network. For example, this might be used connect a particular component or sub-network to ground.
- Invert (~) - Instead of connecting 1 -> 2 , connect 2 -> 1. reverses the orientation of the component. Useful for polarizing caps, diodes, etc.
Summary¶
Data Types¶
ShuntTo¶
Shunt to a Port on the Network
Tap¶
Tap on a port of an Circuit Element in the Network
CircuitElement¶
Circuit Element for a Circuit Network
Constructors¶
Function | Description |
---|---|
CircuitElement (+ 1) | Constructor for defstruct CircuitElement |
Invert¶
Invert Node for the Circuit Network
Series¶
Series Node in the Circuit Network
Functions¶
Function | Description |
---|---|
connect-series | Construct instances and net connectors for a series circuit |
Series |
ANT¶
Abstract Network Type
Functions¶
Function | Description |
---|---|
ShuntTo | |
Tap | |
to-instantiable | Construct an Instantiable given a Union of ANT or Instantiable |
Invert | |
Series | |
elaborate | Instantiate and Connect the elements of a Circuit Network |
Parallel | |
create-circuit | Construct an instantiable for the passed Network |
elaborate-all | Convert the network representation into instantiate components and nets |
Parallel¶
Parallel Node in the Circuit Network
Functions¶
Function | Description |
---|---|
connect-parallel | Instantiate and Connect all parallel elements |
Parallel |
General Definitions¶
Function | Description |
---|---|
set-shunted | |
is-shunted? |
Definitions¶
ShuntTo¶
Shunt to a Port on the Network
public defstruct ShuntTo <: ANT :
name: Symbol
name: Symbol
- Name for the shunt port on Network Instantiable This name is used to construct aport
on the resulting instantiable of the network. It must be a valid stanza symbol - otherwise, it will not be able to construct the instantiable.
This type is similar to Tap
except instead of having
the a continuous component connection in the network, the
shunted component only has one pin connected in the network.
The other pin is connected out to an external port on the
network circuit.
This type will not work with Series
- it is only
possible to use this in combination with the Parallel |
operator.
Example: This circuit:
A + (B | ShuntTo(C, `named-shunt-port))
Results in:
p[1] -> O--A--O--B--O -> p[2]
|
--C--O -> named-shunt-port
Note that p[2]
of C is connected to named-shunt-port
. To
flip the component see Invert
Functions¶
ShuntTo¶
public defn ShuntTo (a:ANT, name:Symbol) -> ShuntTo
- Returns
ShuntTo
ShuntTo¶
public defn ShuntTo (a:Instantiable, name:Symbol) -> ShuntTo
- Returns
ShuntTo
Tap¶
Tap on a port of an Circuit Element in the Network
public defstruct Tap <: ANT :
name: Symbol
port-id: Int
-
name: Symbol
- Symbol Name for the tap port on Network Instantiable This name is used to construct aport
on the resulting instantiable of the network. It must be a valid stanza symbol - otherwise, it will not be able to construct the instantiable. -
port-id: Int
- Port Id for a port on the element of the tap. Typically this will be1
or2
for two-pin components, The default value is 1
This is a method of accessing an internal node of the circuit element by creating a named port.
Example:
Given the following circuit
val circ = create-circuit(a + Tap(b, `divOut`))
It will create a module like this:
p[1] -> O -- a -- O -- b -- O -> p[2]
|
---> divOut
A and B are connected in series as normal and their intermediate node is extracted to a port.
Functions¶
Tap¶
public defn Tap (name:Symbol, a:ANT -- port-id:Int = ?) -> Tap
- Returns
Tap
Tap¶
public defn Tap (name:Symbol, a:Instantiable -- port-id:Int = ?) -> Tap
- Returns
Tap
CircuitElement¶
Circuit Element for a Circuit Network
public defstruct CircuitElement <: ANT :
elem-type: Instantiable
is-public?: True|False
name: Symbol
-
elem-type: Instantiable
- Element Instantiable to be created in the network This instantiable type needs to define either of the following ports:p[1]/p[2]
like a standard unpolarized 2-pinc/a
like a standard polarized 2-pin
When the component/module has more than just these ports - it is often convenient to mark it as
public
so that it can be accessed inside the module. -
is-public?: True|False
- Mark's this component instance as public This means that after the network is constructed - it will be accessible by the user using dot-notation. -
name: Symbol
- Alternative Instance Name for this Element By default the elements are namedelem
but this can be c confusing when constructing a complex network. This allows for the names to be more explicitly defined by the user.
This type typically includes an instantiable that will be instantiated in the resultant network definition.
Constructors¶
CircuitElement¶
Constructor for defstruct CircuitElement
public defn CircuitElement (elements:IndexedCollection<ANT>, elem-type:Instantiable, name:Symbol = ?, is-public?:True|False = ?)
CircuitElement¶
Constructor for defstruct CircuitElement
public defn CircuitElement ( -- elements:IndexedCollection<ANT> = ?, elem-type:Instantiable, name:Symbol = ?, is-public?:True|False = ?)
Functions¶
Elem¶
Short Helper Method for Creating CircuitElement
public defn Elem (i:Instantiable -- name:Symbol = ?, is-public?:True|False = ?) -> CircuitElement
- Returns
CircuitElement
Invert¶
Invert Node for the Circuit Network
public deftype Invert <: ANT
Invert causes an Element to be connected 2 -> 1
instead of 1 -> 2
Series¶
Series Node in the Circuit Network
public deftype Series <: ANT
The series node encodes a sequence of components connected in
series. This typically means N1.p[2] -> N2.p[1]
then N2.p[2] -> N3.p[1]
, etc
Functions¶
connect-series¶
Construct instances and net connectors for a series circuit
public defn connect-series (a:Series, taps:Vector<[Symbol, JITXObject]>) -> [JITXObject, JITXObject]
a: Series
- Series Network Elementtaps: Vector<[Symbol, JITXObject]>
- Accumulator for the external ports of the network.- Returns
[JITXObject, JITXObject]
- The[p1, p2]
tuple of the ports of the endpoints of the series network. This is typicallyp[1]
of element 0 andp[2]
of elementN-1
whereN
is the number of elements in series. - Throws
ValueError
- If any of the series components have been markedShuntTo
. TheShuntTo
mechanism is not handled in series connections.
Series¶
public defn Series (elems:Seqable<ANT> = ?) -> Series
- Returns
Series
ANT¶
Abstract Network Type
public deftype ANT
The circuit tree is composed of ANT
instances that form
a sequence of operations for the tree.
Multis¶
elements¶
Each ANT
instance contains a recursive set of ANT elements
public defmulti elements (a:ANT) -> IndexedCollection<ANT>
- Returns
IndexedCollection<ANT>
The elements of each ANT instance are interpreted by that node. Some may be empty, others may have a single instance, and others may have 1 or more instances.
Functions¶
ShuntTo¶
public defn ShuntTo (a:ANT, name:Symbol) -> ShuntTo
- Returns
ShuntTo
Tap¶
public defn Tap (name:Symbol, a:ANT -- port-id:Int = ?) -> Tap
- Returns
Tap
to-instantiable¶
Construct an Instantiable given a Union of ANT or Instantiable
public defn to-instantiable (x:ANT|Instantiable -- name?:Maybe<String> = ?) -> Instantiable
x: ANT|Instantiable
- Sub-Circuit to form into an Instantiablename?: Maybe<String>
- Optional name to apply to the create ANT sub-circuit. Ifx
is anInstantiable
- this argument is ignored.- Returns
Instantiable
Invert¶
public defn Invert (a:ANT) -> Invert
- Returns
Invert
Series¶
public defn Series (elems:Seqable<ANT> = ?) -> Series
- Returns
Series
elaborate¶
Instantiate and Connect the elements of a Circuit Network
public defn elaborate (a:ANT, taps:Vector<[Symbol, JITXObject]>) -> [JITXObject, JITXObject]
a: ANT
- Circuit network to elaboratetaps: Vector<[Symbol, JITXObject]>
- Accumulator for the external ports of the network.- Returns
[JITXObject, JITXObject]
- Tuple of[p1, p2]
that are the ports of the endpoints of the network.
This function is recursive.
Parallel¶
public defn Parallel (elems:Seqable<ANT> = ?) -> Parallel
- Returns
Parallel
create-circuit¶
Construct an instantiable for the passed Network
public defn create-circuit (a:ANT -- name?:Maybe<String> = ?) -> Instantiable
a: ANT
- Network definition that will be converted into apcb-module
.- Returns
Instantiable
p
- PortArray of 2 pins,p[1]
andp[2]
. These are the two end points of the network.
This function will create a pcb-module
based on the passed
network description. This network will have at least port p
with
two elements. It may optionally have one or more unique SinglePin
ports that are created dynamically by the Tap
and ShuntTo
types.
elaborate-all¶
Convert the network representation into instantiate components and nets
public defn elaborate-all (a:ANT, taps:Vector<[Symbol, JITXObject]>) -> Seq<[JITXObject, JITXObject]>
a: ANT
- Network to elaboratetaps: Vector<[Symbol, JITXObject]>
- Accumulator for the external ports of the network.- Returns
Seq<[JITXObject, JITXObject]>
- Sequence of[p1, p2]
for each element at the top level of the network. For Parallel - this sequence may be 2 or more tuples For others - this is typically only 1 tuple
This function is potentially recursive.
Operators¶
plus +
¶
public defn plus (a:ANT, b:ANT) -> ANT
- Returns
ANT
plus +
¶
public defn plus (a:ANT, b:Instantiable) -> ANT
- Returns
ANT
plus +
¶
public defn plus (a:Instantiable, b:ANT) -> ANT
- Returns
ANT
bit-or |
¶
public defn bit-or (a:ANT, b:ANT) -> ANT
- Returns
ANT
bit-or |
¶
public defn bit-or (a:ANT, b:Instantiable) -> ANT
- Returns
ANT
bit-or |
¶
public defn bit-or (a:Instantiable, b:ANT) -> ANT
- Returns
ANT
bit-not ~
¶
public defn bit-not (a:ANT) -> ANT
- Returns
ANT
bit-not ~
¶
public defn bit-not (a:Instantiable) -> ANT
- Returns
ANT
Parallel¶
Parallel Node in the Circuit Network
public deftype Parallel <: ANT
The parallel node encodes a set of components that are all connected in parallel.
Functions¶
connect-parallel¶
Instantiate and Connect all parallel elements
public defn connect-parallel (a:Parallel, taps:Vector<[Symbol, JITXObject]>) -> [JITXObject, JITXObject]
a: Parallel
- Parallel Network Elementtaps: Vector<[Symbol, JITXObject]>
- Accumulator for the external ports of the network.- Returns
[JITXObject, JITXObject]
- Tuple of[p1, p2]
which is typically the first parallel elements ports. All of the other element'sp1
andp2
are netted to the first parallel element, respectively.
ShuntTo
elements are handled differently. Typically, p1
port of the shunted sub-network is
connected to the p1
of all the other components in parallel. The p2
port of the shunted
sub-network is not connected to the other parallel components, and is instead connected to a
external port.
Parallel¶
public defn Parallel (elems:Seqable<ANT> = ?) -> Parallel
- Returns
Parallel
General Definitions¶
Related Packages¶
Forwarded by package: jsl/circuits