summaryrefslogtreecommitdiff
path: root/readme.org
blob: b193b88646436dbff16e2df04bde467f3debce49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
* Overview

Extends org-babel capabilities to support spice simulations using
ngspice. Simulations are executed using an interactive ngspice process
running in emacs. The running ngspice process can be used to
manipulate the simulation results directly or spread a simulation into
multiple src blocks.

Spice source blocks are interpreted as circuit descriptions until an
'.end' line is encountered. After that a control part may follow
(surrounded by '.control' and '.endc' lines). *If there is no '.end'*
*line all of the src block is interpreted as a control block!*

* Use cases
*** Just load some circuit for later simulation:
#+BEGIN_SRC spice :results output
,* RC
r1 1 0 10k
c1 1 0 1p
.IC V(1)=1
.tran 1n 0.1u
.end
#+END_SRC
#+RESULTS:
: Circuit: * rc

*** Execute some stuff
#+BEGIN_SRC spice
echo "Hello world"
#+END_SRC
#+RESULTS:
: Hello world

#+BEGIN_SRC spice
echo "0,1,2,3"
#+END_SRC
#+RESULTS:
| 0 | 1 | 2 | 3 |

*** Plot some voltages and return png
#+BEGIN_SRC spice :var file="/tmp/xzy" :results file
,*RC circuit
r1 1 0 10k
c1 1 0 1p

.IC V(1)=1
.tran 1n 0.1u
.end

.control
run
set gnuplot_terminal=png
gnuplot $file v(1)
.endc
#+END_SRC

#+RESULTS:
[[file:/tmp/xzy.png]]

*** Do measurements and return results
#+BEGIN_SRC spice :session spicetest :results value
,*Time Constant Measurement
r1 1 0 10k
c1 1 0 1p

.IC V(1)=1
.tran 1n 0.1u
.print tran v(1)
.end

.control
run
meas tran value_at_tau find V(1) at=1e-8
meas tran value_at_five_tau find V(1) at=5e-8
echo $&value_at_tau ,$&value_at_five_tau
.endc
#+END_SRC

#+RESULTS:
| 0.36798 | 0.00671732 |

*** write simulation data to file and return file name
#+BEGIN_SRC spice :var file="/tmp/xyz" :post plot_stuff(data=*this*) :results file
,*RC circuit
r1 1 0 10k
c1 1 0 1p
.IC V(1)=1
.tran 1n 0.1u
.end
.control
run
wrdata $file v(1)
.endc
#+END_SRC

#+RESULTS:
[[file:/tmp/xyz_plot.png]]

#+NAME: plot_stuff
#+BEGIN_SRC gnuplot :var data="x" :file "/tmp/xyz_plot.png" :results silent
plot data u 1:2 w l ls 1
#+END_SRC

* Flags
** :netlist / :circuit
Name of a src block to include for netlist/circuit descriptions.
** :dir
Working directory to run the src block in. Default is the value of `default-directory'.
** :file?

** :gnuplot
Name of gnuplot block or .plt file: handle plotting instead of gnuplot
lines
** :results
Available result options are `value' which returns the output of the
 last expression, `output' which returns all output and `smart' which
 tries to only display echos and plot filenames.
** :batch / :no-interactive
use batch mode