My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
digisource.cpp
Go to the documentation of this file.
1 /*
2  * digisource.cpp - digital source class implementation
3  *
4  * Copyright (C) 2005, 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: digisource.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 "digisource.h"
31 
32 digisource::digisource () : circuit (1) {
34  setVSource (true);
36 }
37 
38 void digisource::initSP (void) {
39  allocMatrixS ();
40  setS (NODE_1, NODE_1, -1.0);
41 }
42 
43 void digisource::initDC (void) {
44  char * init = getPropertyString ("init");
45  nr_double_t v = getPropertyDouble ("V");
46  bool lo = !strcmp (init, "low");
47  allocMatrixMNA ();
48  setC (VSRC_1, NODE_1, 1.0);
49  setB (NODE_1, VSRC_1, 1.0);
50  setD (VSRC_1, VSRC_1, 0.0);
51  setE (VSRC_1, lo ? 0 : v);
52 }
53 
54 void digisource::initAC (void) {
55  initDC ();
56  setE (VSRC_1, 0);
57 }
58 
59 void digisource::initTR (void) {
60  vector * values = getPropertyVector ("times");
61  T = real (sum (*values));
62  initDC ();
63 }
64 
65 void digisource::calcTR (nr_double_t t) {
66  char * init = getPropertyString ("init");
67  nr_double_t v = getPropertyDouble ("V");
68  vector * values = getPropertyVector ("times");
69  bool lo = !strcmp (init, "low");
70  nr_double_t ti = 0;
71 
72  t = t - T * floor (t / T);
73  for (int i = 0; i < values->getSize (); i++) {
74  ti += real (values->get (i));
75  if (t >= ti) lo = !lo; else break;
76  }
77 
78  setE (VSRC_1, lo ? 0 : v);
79 }
80 
81 // properties
82 PROP_REQ [] = {
83  { "init", PROP_STR, { PROP_NO_VAL, "low" }, PROP_RNG_STR2 ("low", "high") },
84  { "times", PROP_LIST, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
85  PROP_NO_PROP };
86 PROP_OPT [] = {
87  { "V", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGE }, PROP_NO_PROP };
88 struct define_t digisource::cirdef =
89  { "DigiSource",