A programming way to design schematics.
Project description
PCB Design Language
A programming way to design schematics.
Installing
sudo apt-get install python3 python3-pip python3-pygments
sudo pip3 install pcbdl
Interactive terminal
A good way to try various features without having to write a file separately.
python3 -i -c "from pcbdl import *"
Language
PCBDL's goal is to allow designing schematics via Code. Similar to how VHDL or Verilog are ways to represent Logic Diagrams in code form, PCBDL the analogous of that but for EDA schematics.
To start one should define a couple of nets:
>>> vcc, gnd = Net("vcc"), Net("gnd")
>>> vin = Net("vin")
>>> base = Net("base")
We then can connect various components between those nets with the <<
operator and the to=
argument (for the other side):
>>> base << C("1000u", to=vin)
>>> base << (
R("1k", to=vcc),
R("1k", to=gnd),
)
2 pin devices (aka JellyBean in pcbdl) like capacitors and resistors are one of the easiest things to connect. Internally they have a primary (connected with >>
) and secondary, other side, pin (connected with to=
).
Let's try to get more complicated by defining a transistor and connect some of its pins.
>>> class Transistor(Part):
REFDES_PREFIX = "Q"
PINS = ["B", "C", "E"]
...
>>> q = Transistor()
>>> base << q.B
Nets can also be created anonymously if started from a part's pins:
>>> q.E << (
R("100", to=gnd),
C("1u", to=gnd),
)
Let's finish our class A amplifier (note how we created the "vout" net in place, and how we gave a name ("Rc") to one of our resistors):
>>> q.C << (
C("100u", to=Net("vout")),
R("100", "Rc", to=vcc),
)
Note: One can find a completed version of this amplifier in examples/class_a.py
:
python3 -i examples/class_a.py
One can now give automatic consecutive reference designators to components that haven't been named manually already:
>>> global_context.autoname()
Then one can explore the circuit:
>>> global_context.parts_list
[R1, R2, R3, Rc, C10, C11, Q1, C12]
>>> global_context.parts_list[0].refdes
'R1'
>>> global_context.parts_list[0].value
'1kΩ'
>>> global_context.parts_list[0].pins
(R1.P1, R1.P2)
>>> global_context.parts_list[0].pins[1].net
VCC(connected to R1.P2, R2.P2)
>>> nets
OrderedDict([('VCC', VCC(connected to R1.P2, R2.P2)), ('GND', GND(connected to R3.P2, Rc.P2, C10.-)), ('VIN', VIN(connected to C11.-)), ('VOUT', VOUT(connected to C12.-))])
>>> nets["GND"]
GND(connected to R3.P2, Rc.P2, C10.-)
Examples
Found in the examples/
folder. Another way to make sure the environment is sane.
One can just "run" any example schematic with python, add -i to do more analysis operations on the schematic.
voltage_divider.py
: Very simple voltage dividerclass_a.py
: Class A transistor amplifier, a good example to how a complicatedish analog circuit would look like.servo_micro.py
: Servo micro schematics, reimplementation in pcbdl, originally an 8 page pdf schematic.
Exporting
Netlists
The main goal of this language is to aid in creating PCBs. The intermediate file format that layout programs (where one designs physical boards) is called a netlist. We must support outputting to that (or several of such formats).
For now we have a minimum viable example of an exporter for the Allegro Cadence netlists (found in netlist.py
):
>>> generate_netlist("/tmp/some_export_location")
HTML
This produces a standalone html page with everything cross-linked:
- List of nets with links to the parts and pins on each
- List of parts with the part properties and a list of pins linking to the nets connected
- Highlighted source code, with every variable and object linked to the previous 2 lists
Here's an example of such a html output for servo micro.
Schematics / Graphical representation of the circuit
In order for schematics to be more easily parsable, we want to graphically display them. The netlistsvg project has been proven to be an excellent tool to solve the hard problems of this. See pcbdl/netlistsvg.py
for the implementation.
-
Convert a pcbdl schematic back into a traditional schematic
generate_svg('svg_filename')
Here's the svg output for the servo_micro example.
-
Isolated schematics for how a particular thing is hooked up:
- I2C map, (servo_micro's)
generate_svg('svg_filename', net_regex='.*(SDA|SCL).*', airwires=0)
- Power connections (servo_micro's)
generate_svg('svg_filename', net_regex='.*(PP|GND|VIN|VBUS).*')
-
Block diagrams of the overall system
- This depends on how the schematics is declared, if it's not hierarchical enough, it won't have many "blocks" to display
- This task is dependent on allowing hierarchies in pcbdl
BOM
Bill of Materials would be a trivial thing to implement in pcbdl.
ERC
Electrical Rule Checking. How to unit test a schematic?
This is a big TODO item. The basic idea is that the pins will get annotated more heavily than normal EDA software.
Pins will have beyond just simple input/output/open drain/power properties, but will go into detail with things like:
- Power well for both inputs and outputs
- ViH, ViL
- Output voltages
With this information it should be possible to make isolated spice circuits to check for current leaks. For every net, for every combination of output pins on that net, are all the input pins receiving proper voltages?
Importing from traditional EDA schematics
Given that graphical exporting might be impossible, and in lieu of the language being slightly more unreadable than normal schematics, perhaps we should just use pcbdl as an intermediate data format or a library.
The way one would use it would be to import a kicad schematic, annotate it with a few more classes (for BOM and ERC purposes, unless we can find a way to put all metadata in the kicad schematics). Then all exporting and analysis features of pcbdl can still be used.
A kicad importer should be pretty trivial to implement. TODO
Support
This is not an officially supported Google product.
The language itself is still in flux, things might change. A lot of the syntax was added as a demo of what could be possible, might still need polishing. Please don't use this language without expecting some tinkering to keep your schematics up to date to the language.
Credits / Thanks
- CBOLD for the idea
- netlistsvg for svg output support
- Chrome OS Hardware Design Team for feedback
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pcbdl-0.1.1.tar.gz
.
File metadata
- Download URL: pcbdl-0.1.1.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 214a419cd2a11e4f53d15f03e9cf95fbd2d4a0270bd6545aa9ad77650c21486f |
|
MD5 | 96f2fd8e66ca982c507bd6721275c639 |
|
BLAKE2b-256 | 36ba1b2b09d3dfaddde6ebf2eed700078695aff2f9ecdded48e9b8b88dd5a6a6 |
File details
Details for the file pcbdl-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pcbdl-0.1.1-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 617159d5f36f6155f1632519087759743655f26c154c2f94a1234923465dc0c1 |
|
MD5 | 62968f9614bd5e98c13fb647b360db84 |
|
BLAKE2b-256 | 47309e141dc33e0135274f4b5713ed84e090baf3e6b9225585581947369b1002 |