summaryrefslogtreecommitdiffstatshomepage
path: root/nl_examples
diff options
context:
space:
mode:
author Couriersud <couriersud@users.noreply.github.com>2014-02-13 00:28:18 +0000
committer Couriersud <couriersud@users.noreply.github.com>2014-02-13 00:28:18 +0000
commit686d540bada22b1a92af1e9690aed916d344586c (patch)
treef9c7f25ab72a4640aa5e501f9ceb0f11f5cf8896 /nl_examples
parentc99b5bf4aa327f7b8dcf7e5b232346c282a7b20a (diff)
Netlist can now be included as sub-circuits. That's the same approach SPICE uses.
The implementation also supports nesting. Opamp emulation now is as easy as /* Opamp wired as impedance changer */ SUBMODEL(op, opamp) NET_C(op.GND, GND) NET_C(op.PLUS, clk) NET_C(op.MINUS, op.OUT) The missing bit now is a central submodel repository. I'll start a discussion soon on the list. nl_examples/opamp.c is an example of a impedance changer stage followed by a 1:2 amplifier stage. System size (= number of voltage levels to be calculated) is between 20 - 30. Using a simple, yet better opamp model than usually implemented in the old discrete core, I get ./nltool -f nl_examples/opamp.c -t 30 startup time ==> 0.002 runnning ... 30.000000 seconds emulation took 0.438599 real time ==> 6839.96% Which leaves quite some buffer to emulate even complex mixing and filtering stages in real-time :-)
Diffstat (limited to 'nl_examples')
-rw-r--r--nl_examples/opamp.c65
1 files changed, 45 insertions, 20 deletions
diff --git a/nl_examples/opamp.c b/nl_examples/opamp.c
index 57daf960e9c..07d7df47135 100644
--- a/nl_examples/opamp.c
+++ b/nl_examples/opamp.c
@@ -6,6 +6,45 @@
#include "netlist/devices/net_lib.h"
+NETLIST_START(main)
+
+ /* Standard stuff */
+
+ CLOCK(clk, 1000) // 1000 Hz
+ SOLVER(Solver, 48000)
+ //PARAM(Solver.ACCURACY, 1e-3)
+ //PARAM(Solver.CONVERG, 1.0)
+ //PARAM(Solver.RESCHED_LOOPS, 30)
+
+ /* Opamp wired as impedance changer */
+ SUBMODEL(op, opamp)
+
+ NET_C(op.GND, GND)
+ NET_C(op.PLUS, clk)
+ NET_C(op.MINUS, op.OUT)
+
+ SUBMODEL(op1, opamp)
+ /* Wired as inverting amplifier connected to output of first opamp */
+
+ RES(R1, 100000)
+ RES(R2, 200000)
+
+ NET_C(op1.GND, GND)
+ NET_C(op1.PLUS, GND)
+ NET_C(op1.MINUS, R2.2)
+ NET_C(op1.MINUS, R1.2)
+
+ NET_C(op.OUT, R1.1)
+ NET_C(op1.OUT, R2.1)
+
+ RES(RL, 1000)
+ NET_C(RL.2, GND)
+ NET_C(RL.1, op1.OUT)
+
+ //LOG(logX, op1.OUT)
+ //LOG(logY, clk)
+NETLIST_END()
+
NETLIST_START(opamp)
/* Opamp model from
@@ -14,19 +53,15 @@ NETLIST_START(opamp)
*
* Bandwidth 10Mhz
*
- * This one is connected as a impedance changer
*/
- /* Standard stuff */
-
- CLOCK(clk, 1000) // 1000 Hz
- SOLVER(Solver, 48000)
- PARAM(Solver.ACCURACY, 1e-6)
+ /* Terminal definitions for calling netlists */
- /* Wiring up the opamp */
+ ALIAS(PLUS, G1.IP) // Positive input
+ ALIAS(MINUS, G1.IN) // Negative input
+ ALIAS(OUT, EBUF.OP) // Opamp output ...
- NET_C(PLUS, clk)
- NET_C(MINUS, OUT)
+ ALIAS(GND, EBUF.ON) // GND terminal
/* The opamp model */
@@ -38,11 +73,7 @@ NETLIST_START(opamp)
PARAM(EBUF.RO, 50)
PARAM(EBUF.G, 1)
- ALIAS(PLUS, G1.IP) // Positive input
- ALIAS(MINUS, G1.IN) // Negative input
- ALIAS(OUT, EBUF.OP) // Opamp output ...
-
- NET_C(EBUF.ON, GND)
+// NET_C(EBUF.ON, GND)
NET_C(G1.ON, GND)
NET_C(RP1.2, GND)
@@ -53,10 +84,4 @@ NETLIST_START(opamp)
NET_C(CP1.1, RP1.1)
NET_C(EBUF.IP, RP1.1)
- RES(RL, 1000)
- NET_C(RL.2, GND)
- NET_C(RL.1, OUT)
-
- //LOG(logX, OUT)
- //LOG(logY, clk)
NETLIST_END()