Skip to content

Instantly share code, notes, and snippets.

@kasbah
Last active July 23, 2017 01:33
Show Gist options
  • Save kasbah/cedfcb65327c7efe1565eb68fed1c5b0 to your computer and use it in GitHub Desktop.
Save kasbah/cedfcb65327c7efe1565eb68fed1c5b0 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"from skidl import *\n",
"\n",
"default_circuit.mini_reset()\n",
"\n",
"gnd = Net('GND') # Ground reference.\n",
"vin = Net('VI') # Input voltage to the divider.\n",
"vout = Net('VO') # Output voltage from the divider.\n",
"r1, r2, r3 = 3 * Part('device', 'R', TEMPLATE) # Create two resistors.\n",
"r1.value, r1.footprint = '1k', 'Resistors_SMD:R_0805' # Set resistor values\n",
"r2.value, r2.footprint = '500R', 'Resistors_SMD:R_0805' # and footprints.\n",
"r3.value, r2.footprint = '2k', 'Resistors_SMD:R_0805'\n",
"r1[1] += vin # Connect the input to the first resistor.\n",
"r2[2] += gnd # Connect the second resistor to ground.\n",
"vin += r3[1]\n",
"r3[2] += vout\n",
"vout += r1[2], r2[1] # Output comes from the connection of the two resistors.\n",
"\n",
"generate_graph()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 1,
"svg": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.36.0 (20140111.2315)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
"<svg width=\"180pt\" height=\"286pt\"\n",
" viewBox=\"0.00 0.00 179.93 285.92\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 281.917)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-281.917 175.932,-281.917 175.932,4 -4,4\"/>\n",
"<!-- GND -->\n",
"<g id=\"node1\" class=\"node\"><title>GND</title>\n",
"<ellipse fill=\"black\" stroke=\"black\" cx=\"46.5813\" cy=\"-1.8\" rx=\"1.8\" ry=\"1.8\"/>\n",
"<text text-anchor=\"middle\" x=\"29.7813\" y=\"-7.4\" font-family=\"Times,serif\" font-size=\"14.00\">GND</text>\n",
"</g>\n",
"<!-- R2 -->\n",
"<g id=\"node2\" class=\"node\"><title>R2</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"96.0403,-89.156 42.0403,-89.156 42.0403,-53.156 96.0403,-53.156 96.0403,-89.156\"/>\n",
"<text text-anchor=\"middle\" x=\"69.0403\" y=\"-67.456\" font-family=\"Times,serif\" font-size=\"14.00\">R2</text>\n",
"<text text-anchor=\"middle\" x=\"27.0403\" y=\"-92.956\" font-family=\"Times,serif\" font-size=\"14.00\">500R</text>\n",
"</g>\n",
"<!-- R2&#45;&gt;GND -->\n",
"<g id=\"edge1\" class=\"edge\"><title>R2&#45;&gt;GND</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M63.1395,-52.9335C57.525,-35.5953 49.597,-11.1127 47.2566,-3.88512\"/>\n",
"</g>\n",
"<!-- VO -->\n",
"<g id=\"node6\" class=\"node\"><title>VO</title>\n",
"<ellipse fill=\"black\" stroke=\"black\" cx=\"82.0178\" cy=\"-145.351\" rx=\"1.8\" ry=\"1.8\"/>\n",
"<text text-anchor=\"middle\" x=\"70.2178\" y=\"-150.951\" font-family=\"Times,serif\" font-size=\"14.00\">VO</text>\n",
"</g>\n",
"<!-- R2&#45;&gt;VO -->\n",
"<g id=\"edge6\" class=\"edge\"><title>R2&#45;&gt;VO</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M72.2482,-89.4964C75.5508,-108.378 80.3922,-136.057 81.6885,-143.469\"/>\n",
"</g>\n",
"<!-- VI -->\n",
"<g id=\"node3\" class=\"node\"><title>VI</title>\n",
"<ellipse fill=\"black\" stroke=\"black\" cx=\"103.875\" cy=\"-261.117\" rx=\"1.8\" ry=\"1.8\"/>\n",
"<text text-anchor=\"middle\" x=\"94.5754\" y=\"-266.717\" font-family=\"Times,serif\" font-size=\"14.00\">VI</text>\n",
"</g>\n",
"<!-- R1 -->\n",
"<g id=\"node4\" class=\"node\"><title>R1</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"68,-231.229 14,-231.229 14,-195.229 68,-195.229 68,-231.229\"/>\n",
"<text text-anchor=\"middle\" x=\"41\" y=\"-209.529\" font-family=\"Times,serif\" font-size=\"14.00\">R1</text>\n",
"<text text-anchor=\"middle\" x=\"7\" y=\"-235.029\" font-family=\"Times,serif\" font-size=\"14.00\">1k</text>\n",
"</g>\n",
"<!-- R1&#45;&gt;VI -->\n",
"<g id=\"edge2\" class=\"edge\"><title>R1&#45;&gt;VI</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M64.7705,-231.334C79.7936,-242.776 97.3046,-256.113 102.41,-260.001\"/>\n",
"</g>\n",
"<!-- R1&#45;&gt;VO -->\n",
"<g id=\"edge5\" class=\"edge\"><title>R1&#45;&gt;VO</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M51.992,-195.039C62.4334,-177.76 77.1034,-153.484 81.0229,-146.998\"/>\n",
"</g>\n",
"<!-- R3 -->\n",
"<g id=\"node5\" class=\"node\"><title>R3</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"171.932,-211.531 117.932,-211.531 117.932,-175.531 171.932,-175.531 171.932,-211.531\"/>\n",
"<text text-anchor=\"middle\" x=\"144.932\" y=\"-189.831\" font-family=\"Times,serif\" font-size=\"14.00\">R3</text>\n",
"<text text-anchor=\"middle\" x=\"110.932\" y=\"-215.331\" font-family=\"Times,serif\" font-size=\"14.00\">2k</text>\n",
"</g>\n",
"<!-- R3&#45;&gt;VI -->\n",
"<g id=\"edge3\" class=\"edge\"><title>R3&#45;&gt;VI</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M133.93,-211.643C123.478,-228.847 108.794,-253.02 104.871,-259.478\"/>\n",
"</g>\n",
"<!-- R3&#45;&gt;VO -->\n",
"<g id=\"edge4\" class=\"edge\"><title>R3&#45;&gt;VO</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M121.147,-175.316C106.114,-163.804 88.5927,-150.386 83.4842,-146.474\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text": [
"<graphviz.dot.Digraph at 0x7f9c7e9e6f10>"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from skidl import *\n",
"\n",
"default_circuit.mini_reset()\n",
"# Define the voltage divider module.\n",
"@subcircuit\n",
"def vdiv(inp, outp):\n",
" \"\"\"Divide inp voltage by 3 and place it on outp net.\"\"\"\n",
" rup = Part('device', 'R', value='1K', footprint='Resistors_SMD:R_0805')\n",
" rlo = Part('device','R', value='500', footprint='Resistors_SMD:R_0805')\n",
" rup[1,2] += inp, outp\n",
" rlo[1,2] += outp, gnd\n",
"\n",
"@subcircuit\n",
"def multi_vdiv(repeat, inp, outp):\n",
" \"\"\"Divide inp voltage by 3 ** repeat and place it on outp net.\"\"\"\n",
" for _ in range(repeat):\n",
" out_net = Net() # Create an output net for the current stage.\n",
" vdiv(inp, out_net) # Instantiate a divider stage.\n",
" inp = out_net # The output net becomes the input net for the next stage.\n",
" outp += out_net # Connect the output from the last stage to the module output net.\n",
"\n",
"gnd = Net('GND') # GLobal ground net.\n",
"input_net = Net('IN') # Net with the voltage to be divided.\n",
"output_net = Net('OUT') # Net with the divided voltage.\n",
"multi_vdiv(3, input_net, output_net) # Run the input through 3 voltage dividers.\n",
"\n",
"generate_graph(engine='circo')\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 2,
"svg": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.36.0 (20140111.2315)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
"<svg width=\"507pt\" height=\"510pt\"\n",
" viewBox=\"0.00 0.00 506.78 509.97\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 505.971)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-505.971 502.782,-505.971 502.782,4 -4,4\"/>\n",
"<!-- GND -->\n",
"<g id=\"node1\" class=\"node\"><title>GND</title>\n",
"<ellipse fill=\"black\" stroke=\"black\" cx=\"116.7\" cy=\"-103.737\" rx=\"1.8\" ry=\"1.8\"/>\n",
"<text text-anchor=\"middle\" x=\"99.9\" y=\"-109.337\" font-family=\"Times,serif\" font-size=\"14.00\">GND</text>\n",
"</g>\n",
"<!-- R2 -->\n",
"<g id=\"node2\" class=\"node\"><title>R2</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"83.5394,-225.938 29.5394,-225.938 29.5394,-189.938 83.5394,-189.938 83.5394,-225.938\"/>\n",
"<text text-anchor=\"middle\" x=\"56.5394\" y=\"-204.238\" font-family=\"Times,serif\" font-size=\"14.00\">R2</text>\n",
"<text text-anchor=\"middle\" x=\"19.0394\" y=\"-229.738\" font-family=\"Times,serif\" font-size=\"14.00\">500</text>\n",
"</g>\n",
"<!-- R2&#45;&gt;GND -->\n",
"<g id=\"edge1\" class=\"edge\"><title>R2&#45;&gt;GND</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M67.0186,-189.787C82.3698,-163.198 109.785,-115.714 115.598,-105.645\"/>\n",
"</g>\n",
"<!-- N$1 -->\n",
"<g id=\"node7\" class=\"node\"><title>N$1</title>\n",
"<ellipse fill=\"black\" stroke=\"black\" cx=\"116.7\" cy=\"-312.139\" rx=\"1.8\" ry=\"1.8\"/>\n",
"</g>\n",
"<!-- R2&#45;&gt;N$1 -->\n",
"<g id=\"edge6\" class=\"edge\"><title>R2&#45;&gt;N$1</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M67.0186,-226.088C82.3698,-252.677 109.785,-300.161 115.598,-310.23\"/>\n",
"</g>\n",
"<!-- R4 -->\n",
"<g id=\"node3\" class=\"node\"><title>R4</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"264.021,-121.737 210.021,-121.737 210.021,-85.7365 264.021,-85.7365 264.021,-121.737\"/>\n",
"<text text-anchor=\"middle\" x=\"237.021\" y=\"-100.037\" font-family=\"Times,serif\" font-size=\"14.00\">R4</text>\n",
"<text text-anchor=\"middle\" x=\"199.521\" y=\"-125.537\" font-family=\"Times,serif\" font-size=\"14.00\">500</text>\n",
"</g>\n",
"<!-- R4&#45;&gt;GND -->\n",
"<g id=\"edge2\" class=\"edge\"><title>R4&#45;&gt;GND</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M210.019,-103.737C178.424,-103.737 129.086,-103.737 118.671,-103.737\"/>\n",
"</g>\n",
"<!-- N$2 -->\n",
"<g id=\"node9\" class=\"node\"><title>N$2</title>\n",
"<ellipse fill=\"black\" stroke=\"black\" cx=\"297.182\" cy=\"-207.938\" rx=\"1.8\" ry=\"1.8\"/>\n",
"</g>\n",
"<!-- R4&#45;&gt;N$2 -->\n",
"<g id=\"edge9\" class=\"edge\"><title>R4&#45;&gt;N$2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M247.5,-121.887C262.851,-148.476 290.266,-195.96 296.08,-206.029\"/>\n",
"</g>\n",
"<!-- R6 -->\n",
"<g id=\"node4\" class=\"node\"><title>R6</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"94.2,-36 40.2,-36 40.2,-0 94.2,-0 94.2,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"67.2\" y=\"-14.3\" font-family=\"Times,serif\" font-size=\"14.00\">R6</text>\n",
"<text text-anchor=\"middle\" x=\"29.7\" y=\"-39.8\" font-family=\"Times,serif\" font-size=\"14.00\">500</text>\n",
"</g>\n",
"<!-- R6&#45;&gt;GND -->\n",
"<g id=\"edge3\" class=\"edge\"><title>R6&#45;&gt;GND</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M77.6977,-36.1825C90.4117,-58.2038 110.737,-93.4089 115.62,-101.866\"/>\n",
"</g>\n",
"<!-- IN -->\n",
"<g id=\"node5\" class=\"node\"><title>IN</title>\n",
"<ellipse fill=\"black\" stroke=\"black\" cx=\"16.8\" cy=\"-485.171\" rx=\"1.8\" ry=\"1.8\"/>\n",
"<text text-anchor=\"middle\" x=\"7.5\" y=\"-490.771\" font-family=\"Times,serif\" font-size=\"14.00\">IN</text>\n",
"</g>\n",
"<!-- R1 -->\n",
"<g id=\"node6\" class=\"node\"><title>R1</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"94.2,-415.875 40.2,-415.875 40.2,-379.875 94.2,-379.875 94.2,-415.875\"/>\n",
"<text text-anchor=\"middle\" x=\"67.2\" y=\"-394.175\" font-family=\"Times,serif\" font-size=\"14.00\">R1</text>\n",
"<text text-anchor=\"middle\" x=\"31.7\" y=\"-419.675\" font-family=\"Times,serif\" font-size=\"14.00\">1K</text>\n",
"</g>\n",
"<!-- R1&#45;&gt;IN -->\n",
"<g id=\"edge4\" class=\"edge\"><title>R1&#45;&gt;IN</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M56.7571,-415.963C43.8399,-438.336 22.9357,-474.543 17.9114,-483.246\"/>\n",
"</g>\n",
"<!-- R1&#45;&gt;N$1 -->\n",
"<g id=\"edge5\" class=\"edge\"><title>R1&#45;&gt;N$1</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M77.6977,-379.693C90.4117,-357.672 110.737,-322.466 115.62,-314.009\"/>\n",
"</g>\n",
"<!-- R3 -->\n",
"<g id=\"node8\" class=\"node\"><title>R3</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"264.021,-330.139 210.021,-330.139 210.021,-294.139 264.021,-294.139 264.021,-330.139\"/>\n",
"<text text-anchor=\"middle\" x=\"237.021\" y=\"-308.439\" font-family=\"Times,serif\" font-size=\"14.00\">R3</text>\n",
"<text text-anchor=\"middle\" x=\"201.521\" y=\"-333.939\" font-family=\"Times,serif\" font-size=\"14.00\">1K</text>\n",
"</g>\n",
"<!-- R3&#45;&gt;N$1 -->\n",
"<g id=\"edge7\" class=\"edge\"><title>R3&#45;&gt;N$1</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M210.019,-312.139C178.424,-312.139 129.086,-312.139 118.671,-312.139\"/>\n",
"</g>\n",
"<!-- R3&#45;&gt;N$2 -->\n",
"<g id=\"edge8\" class=\"edge\"><title>R3&#45;&gt;N$2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M247.5,-293.988C262.851,-267.399 290.266,-219.916 296.08,-209.846\"/>\n",
"</g>\n",
"<!-- R5 -->\n",
"<g id=\"node10\" class=\"node\"><title>R5</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"423.182,-225.938 369.182,-225.938 369.182,-189.938 423.182,-189.938 423.182,-225.938\"/>\n",
"<text text-anchor=\"middle\" x=\"396.182\" y=\"-204.238\" font-family=\"Times,serif\" font-size=\"14.00\">R5</text>\n",
"<text text-anchor=\"middle\" x=\"360.682\" y=\"-229.738\" font-family=\"Times,serif\" font-size=\"14.00\">1K</text>\n",
"</g>\n",
"<!-- R5&#45;&gt;N$2 -->\n",
"<g id=\"edge10\" class=\"edge\"><title>R5&#45;&gt;N$2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M369.13,-207.938C343.481,-207.938 307.632,-207.938 299.071,-207.938\"/>\n",
"</g>\n",
"<!-- OUT -->\n",
"<g id=\"node11\" class=\"node\"><title>OUT</title>\n",
"<ellipse fill=\"black\" stroke=\"black\" cx=\"496.982\" cy=\"-207.938\" rx=\"1.8\" ry=\"1.8\"/>\n",
"<text text-anchor=\"middle\" x=\"481.182\" y=\"-213.538\" font-family=\"Times,serif\" font-size=\"14.00\">OUT</text>\n",
"</g>\n",
"<!-- R5&#45;&gt;OUT -->\n",
"<g id=\"edge11\" class=\"edge\"><title>R5&#45;&gt;OUT</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M423.194,-207.938C449.32,-207.938 486.219,-207.938 495.036,-207.938\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text": [
"<graphviz.dot.Digraph at 0x7f9c5ea65290>"
]
}
],
"prompt_number": 2
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment