Nets and power symbols
A net consist of a group of connected component pins. In an ideal world, without lossy interconnects, these pins are electrically tied and have the same voltage.
Net components
In the standard library, the supply function creates a supply component in the schematic.
from "std" import *
gnd = dgnd()
at v5v = supply("5V")
wire down 100
add cap(100n)
wire down 100
to gnd
A net component has a special property, whenever it is referenced it will create a duplicate of itself. In the following example, the v5v net component is duplicated when it is referenced.
The gnd component is also a net component, and similary duplicated when referenced.
Normal non-net components do not have this property and will not duplicate themselves when referenced.
from "std" import *
v5v = supply("5V")
gnd = dgnd()
at v5v
wire down 100
add cap(100n)
wire down 100
to gnd
at v5v
wire down 100
add res(10k)
wire down 100
to gnd
Creating net components
The standard library provides the supply and net functions that create net components. Most of the time, calling these 2 functions are enough for most circuits.
To create a net component, create a component with the following parameters:
typeset tonetcopyset totrue- this will duplicate the component automatically if it is referenced.net_nameinparams
from "std" import *
my_gnd = create component:
pins: 1
copy: true
type: "net"
params:
net_name: "my_gnd"
my_net = create component:
pins: 1
copy: true
type: "net"
params:
net_name: "hello"
at my_net
wire down 100
add res(10k)
wire down 100
to my_gnd
at my_net
wire down 100
add cap(100n)
wire down 100
to my_gnd
Net component parameters
The following parameters are important for net components:
net_name: name that is assigned to the netnet_priority: when two nets with differentnet_nameare connected, the net with the higher priority will be used. The other net will be merged into the higher priority net. All pins within the other net will have thenet_nameof the higher priority net.
Net labels
A net label is created using the label function from the standard library:
label(value, arrow="", anchor="right", priority=5)
value: the string identifier (net name) of the label.arrow: the arrow style drawn on the label. One of""(no arrow, default),"in","out"or"io"(bidirectional).anchor: the text anchor of the label text, for example"left","center"or"right"(default).priority: the net name priority (default5). Seenet_priorityin Net component parameters.font_size: font size of the label text (default50).color: color of the label text. The default""keeps the theme-aware label color. See Text size and color.
The three arrow styles:
from "std" import *
at label("IN", arrow="in")
wire right 200
add res(1k)
at label("OUT", arrow="out")
wire right 200
add res(1k)
at label("BIDIR", arrow="io")
wire right 200
add res(1k)
Any two nets that share the same label name are considered electrically connected, even if they are not physically wired together in the schematic. This makes net labels a powerful tool for organizing complex circuits.
from "std" import *
v5 = supply("5V")
gnd = dgnd()
at v5
wire down 100
add res(10k)
wire down 100
branch:
wire right 200
branch:
wire down 100
add cap(100n)
wire down 100
to gnd
wire right 300
add label("midpt", anchor="right")
..net.color = "red"
..net.highlight = "red"
..net.highlight_width = 20
wire down 100
add res(10k)
wire down 100
to gnd
Namespaces
A namespace decorator is written before a function call, starting with @. It can scope the nets created inside that call under a net namespace, give the components created by the call a component namespace, or both. This is useful when the same function is called several times and each call should get its own set of nets and refdes, rather than all calls sharing (or colliding on) the same names.
The forms below are shown with a stand-in sub() function, not real syntax to copy directly:
@/"lit0" sub() # net namespace from a string literal
@/("ch" + i) sub() # net namespace from a computed expression
@/chname sub() # net namespace from a variable holding a string
@/scope1 sub() # bare identifier is used as the namespace text itself
@/ sub() # global net namespace
@+/deeper sub() # relative net namespace, appended to the current one
@/ch1@ sub() # net namespace "ch1" plus a component namespace
@ sub() # component namespace only, nets are not scoped
@/<name>sets the net namespace. A bare@/with no name means the global namespace.@+/<name>appendsnameto the namespace already in effect at the call site, rather than replacing it. This matters when namespaced calls are nested: if an outer call is running under theouter_nsnamespace and it makes an inner call prefixed with@+/deeper, the inner call ends up underouter_ns/deeper, whereas prefixing it with@/deeper(no+) would have replaced the namespace entirely, droppingouter_ns. At the top level, with no outer namespace in effect,@+/nameand@/namebehave the same.- A trailing
@(for example@/ch1@) also creates a component namespace, and a bare@creates only a component namespace. Component namespaces are added in front of the refdes of the components created by the call, see Component namespaces.
The same decorator can be used inside add, for example add @/ label("global_name") places a label in the global net namespace from inside a namespaced call.
Before Circuitscript 0.13, net namespaces were written without the @, for example /scope1 sub() and +/inner sub(). That syntax is no longer accepted; add @ in front.
The following example calls the same sub() function twice, once under the "lit0" namespace and once under a namespace held in the chname variable. Each call creates its own SIG net, and the two calls produce distinct nets: lit0/SIG and var0/SIG. The second call also has a component namespace, so its resistor is annotated with an A1 prefix.
from "std" import *
anchor = net("ANCHOR")
def sub():
wire down 100 right 100
add res(10k)
wire right 100 up 100
add net("SIG")
at anchor
branch:
@/"lit0" sub()
chname = "var0"
at anchor
branch:
@/chname@ sub()
Net visual parameters
The following parameters can be set on the .net object within the net component to modify the visual properties of the net.
| Name | Description |
|---|---|
color | Color of net wires |
line_width | Line width of the net wires |
highlight | Highlight color of net wires |
highlight_width | Highlight width of the net wires |
Examples:
from "std" import *
gnd = dgnd()
v5 = supply("5V")
v5.net.color = "red"
v5.net.line_width = 10
v5.net.highlight = "red"
v5.net.highlight_width = 10
at v5
wire down 100
branch:
wire down 100
add cap(100n)
wire down 100
to gnd
wire right 300 down 100
add cap(100n)
wire down 100
to gnd
Alternatively, the double dot syntax can also be used to avoid the need to reference v5 repeatedly.
from "std" import *
gnd = dgnd()
v5 = supply("5V")
at v5
..net.color = "red"
..net.line_width = 10
..net.highlight = "red"
..net.highlight_width = 10
wire down 100
branch:
wire down 100
add cap(100n)
wire down 100
to gnd
wire right 300 down 100
add cap(100n)
wire down 100
to gnd
Text size and color
net, supply and label accept font_size (default 50) and color (default "") parameters that control the text drawn on the symbol. An empty color keeps the default theme-aware color. The standard library text function also accepts color. These can be set when the symbol is created or changed afterwards as component parameters.
from "std" import *
v5 = supply("5V", font_size=70, color="red")
gnd = dgnd()
at v5
wire down 100
add res(10k)
wire down 100
add label("SENSE", font_size=40, color="blue", anchor="left")
at text("Note", color="green")
Net classes
Net classes let you define a reusable set of visual properties under a name, then assign that class to multiple nets. This reduces repetition and keeps schematics visually consistent. Individual net.* overrides still take precedence over class defaults.
Creating a net class
Use the create netclass: block to define a class:
power_class = create netclass:
name: "power"
color: "red"
line_width: 20
highlight: "red"
highlight_width: 10
Supported parameters:
| Name | Description |
|---|---|
name | Required. String identifier for the class |
color | Wire color |
line_width | Wire thickness |
highlight | Highlight color |
highlight_width | Highlight thickness |
highlight_opacity | Highlight opacity (0–1) |
Assigning a net class to a net
Assign a class using ..class = my_class either at creation time or inside an at block:
# at creation time
v5 = supply("5V")
..class = power_class
# or inside an at block
at v3v3
..class = power_class
A per-net override (..net.color, etc.) always takes precedence over the class value.
from "std" import *
power_class = create netclass:
name: "power"
color: "red"
line_width: 20
highlight: "red"
highlight_width: 10
gnd = dgnd()
v5 = supply("5V")
..class = power_class
v3v3 = supply("3V3")
..class = power_class
..net.color = "blue"
at v5
wire down 100 right 100
add res(10k)
wire right 100 down 100
to gnd
at v3v3
wire down 100 right 100
add res(1k)
wire right 100 down 100
to gnd
Power symbols
The standard library std.cst provides the supply function. This can be used to create power symbols with the name of the power net.
from "std" import *
v5v = supply("5V") # creates 5V net
v3v3 = supply("3V3") # creates 3.3V net
gnd = dgnd() # creates GND net
at v5v
wire down 100 right 100
add res(300)
wire right 100
add led("red") pin 2
wire right 100 down 100
to gnd
at v3v3
wire down 100 right 100
add res(200)
wire right 100
add led("green") pin 2
wire right 100 down 100
to gnd