Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 using namespace qucs;
37 
38 opamp::opamp () : circuit (3) {
39  type = CIR_OPAMP;
40  setVoltageSources (1);
41 }
42 
43 void opamp::initSP (void) {
44  allocMatrixS ();
45  setS (NODE_INP, NODE_INP, 1);
46  setS (NODE_INP, NODE_OUT, 0);
47  setS (NODE_INP, NODE_INM, 0);
48  setS (NODE_INM, NODE_INP, 0);
49  setS (NODE_INM, NODE_OUT, 0);
50  setS (NODE_INM, NODE_INM, 1);
51  setS (NODE_OUT, NODE_INP, +4 * gv);
52  setS (NODE_OUT, NODE_OUT, -1);
53  setS (NODE_OUT, NODE_INM, -4 * gv);
54 }
55 
56 void opamp::initDC (void) {
57  allocMatrixMNA ();
58  setB (NODE_INP, VSRC_1, 0);
59  setB (NODE_OUT, VSRC_1, 1);
60  setB (NODE_INM, VSRC_1, 0);
61  setC (VSRC_1, NODE_OUT, -1); setD (VSRC_1, VSRC_1, 0); setE (VSRC_1, 0);
62 }
63 
64 void opamp::calcDC (void) {
65  nr_double_t g = getPropertyDouble ("G");
66  nr_double_t uMax = getPropertyDouble ("Umax");
67  nr_double_t Uin = real (getV (NODE_INP) - getV (NODE_INM));
68  nr_double_t Uout = uMax * M_2_PI * qucs::atan (Uin * g * M_PI_2 / uMax);
69  gv = g / (1 + sqr (M_PI_2 / uMax * g * Uin)) + GMin;
70  setC (VSRC_1, NODE_INP, +gv);
71  setC (VSRC_1, NODE_INM, -gv);
72  setE (VSRC_1, Uin * gv - Uout);
73 }
74 
76  setOperatingPoint ("g", gv);
77 }
78 
79 void opamp::initAC (void) {
80  initDC ();
81  setC (VSRC_1, NODE_INP, +gv);
82  setC (VSRC_1, NODE_INM, -gv);
83 }
84 
85 void opamp::initTR (void) {
86  initDC ();
87 }
88 
89 void opamp::calcTR (nr_double_t) {
90  calcDC ();
91 }
92 
93 // properties
94 PROP_REQ [] = {
95  { "G", PROP_REAL, { 1e6, PROP_NO_STR }, PROP_MIN_VAL (1) },
96  PROP_NO_PROP };
97 PROP_OPT [] = {
98  { "Umax", PROP_REAL, { 15, PROP_NO_STR }, PROP_POS_RANGE },
99  PROP_NO_PROP };
100 struct define_t opamp::cirdef =
#define PROP_POS_RANGE
Definition: netdefs.h:129
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
void calcTR(nr_double_t)
Definition: opamp.cpp:89
#define PROP_DEF
Definition: netdefs.h:189
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
void setD(int, int, nr_complex_t)
Definition: circuit.cpp:373
#define PROP_REAL
Definition: netdefs.h:174
void initAC(void)
Definition: opamp.cpp:79
#define PROP_NO_PROP
Definition: netdefs.h:122
void calcOperatingPoints(void)
Definition: opamp.cpp:75
#define NODE_INP
Definition: opamp.cpp:33
nr_complex_t atan(const nr_complex_t z)
Compute complex arc tangent.
Definition: complex.cpp:117
#define NODE_INM
Definition: opamp.cpp:32
#define PROP_NO_STR
Definition: netdefs.h:125
void setB(int, int, nr_complex_t)
Definition: circuit.cpp:349
void allocMatrixS(void)
Definition: circuit.cpp:251
void initDC(void)
Definition: opamp.cpp:56
#define VSRC_1
Definition: circuit.h:40
nr_complex_t sqr(const nr_complex_t z)
Square of complex number.
Definition: complex.cpp:673
#define M_PI_2
Half of Archimedes' constant ( )
Definition: consts.h:51
Definition: opamp.cpp:100
#define PROP_COMPONENT
Definition: netdefs.h:116
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
#define M_2_PI
Definition: consts.h:63
PROP_REQ[]
Definition: opamp.cpp:94
type
Definition: parse_vcd.y:164
#define PROP_MIN_VAL(k)
Definition: netdefs.h:133
void calcDC(void)
Definition: opamp.cpp:64
void allocMatrixMNA(void)
Definition: circuit.cpp:267
#define GMin
Gmin.
Definition: constants.h:104
nr_double_t gv
Definition: opamp.h:41
nr_double_t getV(int, nr_double_t)
Definition: circuit.cpp:941
PROP_NONLINEAR
Definition: opamp.cpp:101
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: opamp.cpp:43
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void setOperatingPoint(const char *, nr_double_t)
Definition: circuit.cpp:533
void initTR(void)
Definition: opamp.cpp:85
void setC(int, int, nr_complex_t)
Definition: circuit.cpp:361
PROP_OPT[]
Definition: opamp.cpp:97
#define NODE_OUT
Definition: opamp.cpp:34
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118