summaryrefslogtreecommitdiffstatshomepage
path: root/nl_examples/LM3900_test.cpp
blob: 0498b4d2f0bcf5ba27ec234f16b4988e74c674b9 (plain) (blame)
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
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
 * Script to analyze opamp amplification as a function of frequency.
 *
 * ./nltool -t 0.5 -f nl_examples/LM9000_test.cpp
 *
 * t=0.0: 10 Hz
 * t=0.1: 100 Hz
 * t=0.2: 1000 Hz
 * t=0.3: 10000 Hz
 * t=0.4: 100000 Hz
 * ....
 *
 * ./plot_nl.sh --db Y Z
 */


#include "netlist/devices/net_lib.h"

NETLIST_START(main)

    /* Standard stuff */

    //VARCLOCK(clk, "0.5 / pow(10, 1 + T * 4)")
    //CLOCK(clk, 1000)
    SOLVER(Solver, 48000)
    PARAM(Solver.ACCURACY, 1e-10)
    PARAM(Solver.NR_LOOPS, 300)
    PARAM(Solver.DYNAMIC_TS, 1)
	PARAM(Solver.DYNAMIC_MIN_TIMESTEP, 1e-7)

	VS(vs, 0)
	/*
	 * Having f(t)=sin(g(t)*t) the derivative becomes
	 *
	 * f'(t) = d/dt(g(t)*t) * cos(g(t)*t)
	 *
	 * w(t) = d/dt(g(t)*t) = 2*pi*freq(t)  is the angular frequency at time t
	 *
	 * choosing freq(t) = pow(10, a+b*t) and integrating we get
	 *
	 * g(t)*t = 2 * pi /(b*ln(10)) * (pow(10, a+b*t)-pow(10,a))
	 */

	PARAM(vs.FUNC, "0.001 * sin(0.2728752708 * (pow(10, 1 + 10*T) - 10))")

	/*
	 * Stepwise ... same as above
	 */
	//PARAM(vs.FUNC, "0.001 * sin(6.28 * pow(10, trunc((1 + T * 10)*10)/10) * T)")

	/*
	 * Fixed Frequency:
	 * PARAM(vs.FUNC, "1.001 * sin(6.28 * 100 * T)")
	 */
	PARAM(vs.R, 0.1)
	ALIAS(clk, vs.1)
	NET_C(vs.2, GND)
    ANALOG_INPUT(V9, 9)
    ANALOG_INPUT(V12, 12)
    ANALOG_INPUT(VM12, -12)

    //OPAMP(op, OPAMP_TEST)
	LM3900(op)

    NET_C(op.GND, VM12)
    NET_C(op.VCC, V12)

    /* Opamp B wired as inverting amplifier connected to output of first opamp */

    RES(R1, 50)
    RES(RP, 500000) // Set to R2 * 2 if VPlus == VCC (see datasheet)
    RES(R2, 500000)

    NET_C(op.PLUS, RP.1)

	//NET_C(RP.2, V9)
	NET_C(RP.2, GND)
	//NET_C(RP.2, V12)

    NET_C(op.MINUS, R2.2)
    NET_C(op.MINUS, R1.2)

	CAP(C, 10e-6)

	NET_C(clk, C.1)
 	NET_C(C.2, R1.1)
    NET_C(op.OUT, R2.1)

	CAP(CL, 10.0e-6)
    RES(RL, 2000)
    NET_C(RL.2, GND)
    NET_C(RL.1, CL.2)
	NET_C(CL.1, op.OUT)

	AFUNC(f, 1, "A0 * 1000")
	NET_C(f.A0, RL.1)
#if 1
    LOG(log_Y, R1.1)
    LOG(log_Z, f)
#endif
NETLIST_END()