My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opamp.cpp
Go to the documentation of this file.
1 /*
2  * opamp.cpp - operational amplifier class implementation
3  *
4  * Copyright (C) 2004, 2008 Stefan Jahn <stefan@lkcc.org>
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this package; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  * $Id: opamp.cpp 1825 2011-03-11 20:42:14Z ela $
22  *
23  */
24 
25 #if HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include "component.h"
30 #include "opamp.h"
31 
32 #define NODE_INM 0
33 #define NODE_INP 1
34 #define NODE_OUT 2
35 
36 opamp::opamp () : circuit (3) {
37  type = CIR_OPAMP;
38  setVoltageSources (1);
39 }
40 
41 void opamp::initSP (void) {
42  allocMatrixS ();
43  setS (NODE_INP, NODE_INP, 1);
44  setS (NODE_INP, NODE_OUT, 0);
45  setS (NODE_INP, NODE_INM, 0);
46  setS (NODE_INM, NODE_INP, 0);
47  setS (NODE_INM, NODE_OUT, 0);
48  setS (NODE_INM, NODE_INM, 1);
49  setS (NODE_OUT, NODE_INP, +4 * gv);
50  setS (NODE_OUT, NODE_OUT, -1);
51  setS (NODE_OUT, NODE_INM, -4 * gv);
52 }
53 
54 void opamp::initDC (void) {
55  allocMatrixMNA ();
56  setB (NODE_INP, VSRC_1, 0);
57  setB (NODE_OUT, VSRC_1, 1);
58  setB (NODE_INM, VSRC_1, 0);
59  setC (VSRC_1, NODE_OUT, -1); setD (VSRC_1, VSRC_1, 0); setE (VSRC_1, 0);
60 }
61 
62 void opamp::calcDC (void) {
63  nr_double_t g = getPropertyDouble ("G");
64  nr_double_t uMax = getPropertyDouble ("Umax");
65  nr_double_t Uin = real (getV (NODE_INP) - getV (NODE_INM));
66  nr_double_t Uout = uMax * M_2_PI * atan (Uin * g * M_PI_2 / uMax);
67  gv = g / (1 + sqr (M_PI_2 / uMax * g * Uin)) + GMin;
68  setC (VSRC_1, NODE_INP, +gv);
69  setC (VSRC_1, NODE_INM, -gv);
70  setE (VSRC_1, Uin * gv - Uout);
71 }
72 
74  setOperatingPoint ("g", gv);
75 }
76 
77 void opamp::initAC (void) {
78  initDC ();
79  setC (VSRC_1, NODE_INP, +gv);
80  setC (VSRC_1, NODE_INM, -gv);
81 }
82 
83 void opamp::initTR (void) {
84  initDC ();
85 }
86 
87 void opamp::calcTR (nr_double_t) {
88  calcDC ();
89 }
90 
91 // properties
92 PROP_REQ [] = {
93  { "G", PROP_REAL, { 1e6, PROP_NO_STR }, PROP_MIN_VAL (1) },
94  PROP_NO_PROP };
95 PROP_OPT [] = {
96  { "Umax", PROP_REAL, { 15, PROP_NO_STR }, PROP_POS_RANGE },
97  PROP_NO_PROP };
98 struct define_t opamp::cirdef =