Concepts
Here are the important concepts to understand about Circuitscript.
Circuits as graphs
All components and their pins are nodes in a graph. The commands defined in Circuitscript help to describe the connectivity (edges) between component pins. However, instead of just listing the edges directly, the commands provide the designer a way to describe the circuit and build up the reasoning behind the circuit.
The traditional netlist focused on the connectivity, but adds complexity as the designer has to manage the node numbers. With a graph based approach, the relationship between components are defined and there is no need for designers to manage these node numbers.
Components and pins
A component is a node in the circuit graph. This component is created from a component definition and has a fixed number of pins.
For example: my_res = res(10k) creates a component using the function res and assigns it to the variable my_res. The res function returns a component that has 2 pins and represents a resistor component. The standard library std.cst includes other components (capacitors, inductors, etc.) that are commonly used in schematics.
from "std" import *
my_res = res(10k)
at my_res
Nets
A net consists of a group of connected component pins. In an ideal world, without lossy interconnects, these pins are electrically tied and have the same voltage.
Wires
Wires between component pins are manually specified and are used to connect component pins to the same net. This provides greater control in how the graphical schematics are displayed.
Example:
from "std" import *
res1 = res(10k)
res2 = res(20k)
at res1 pin 2
wire right 100 # <-- wire
to res2 pin 1
Execution cursor and state
Circuits are built programmatically by adding and connecting different pins of components and wires. The execution cursor is the current point for executing commands and is defined as the current (component, pin) location.
Example
from "std" import *
at v5 = supply("5V") # add a 5V supply
wire down 100 right 100
add res(10k) # add a 10k resistor
wire right 100
add res(20k) # add a 20k resistor
wire right 100
to dgnd() # add gnd component
Explanation of each line, with the cursor:
| Line | Description | Final cursor |
|---|---|---|
from "std" import * | Imports standard library | |
at v5 = supply("5V") | Adds supply component with net name of "5V" | Pin 1 of supply component |
wire down 100 right 100 | Adds a wire | End point of wire (right 100) |
add res(10k) | Adds a 10k resistor to end of wire. Cursor automatically jumps to next pin of component (pin 2) | Pin 2 of added resistor |
wire right 100 | Adds a wire | End point of wire (right 100) |
add res(20k) | Adds a 20k resistor to end of wire. Cursor automatically jumps to next pin of component (pin 2) | Pin 2 of added resistor |
wire right 100 | Adds a wire | End point of wire (right 100) |
to dgnd() | Adds a gnd component to the end of wire | Pin 1 of the gnd component |