~ubuntu-branches/ubuntu/maverick/ktechlab/maverick

« back to all changes in this revision

Viewing changes to src/electronics/components/ec555.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Georges Khaznadar
  • Date: 2009-02-09 00:28:49 UTC
  • mfrom: (5.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090209002849-9o8eqqiczqo4vat3
Tags: 0.3.6-4
modified debian/rules so it does not invoke make if there is no 
Makefile
Closes: #514552

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
LibraryItem* EC555::libraryItem()
28
28
{
29
29
        return new LibraryItem(
30
 
                QString::QString("ec/555"),
 
30
                "ec/555",
31
31
                i18n("555"),
32
32
                i18n("Integrated Circuits"),
33
33
                "ic1.png",
34
34
                LibraryItem::lit_component,
35
 
                EC555::construct
36
 
                        );
 
35
                EC555::construct );
37
36
}
38
37
 
39
38
EC555::EC555( ICNDocument *icnDocument, bool newItem, const char *id )
40
39
        : Component( icnDocument, newItem, (id) ? id : "555" )
41
40
{
42
41
        m_name = i18n("555");
43
 
        m_desc = i18n("Common timer IC");
44
42
//      m_pins = QStringList::split( ',', "Gnd,Trg,Out,Res,CV,Th,Dis,Vcc" );
45
43
//      m_pins = QStringList::split( ',', "Dis,Th,Trg,Gnd,CV,Out,Res,Vcc" );
46
44
        
49
47
        old_q = false;
50
48
        
51
49
        setSize( -32, -32, 64, 64 );
52
 
        
53
 
        
 
50
 
54
51
        // Pins down left
55
52
        
56
53
        // Pin 7
64
61
        // Pin 2
65
62
        trigger = createPin( -40, 16, 0, "Trg" )->pin();
66
63
        addDisplayText( "trg", QRect( -32, 8, 24, 16 ), "Trg" );
67
 
        
68
 
        
69
 
        
 
64
 
70
65
        // Top two
71
66
        
72
67
        // Pin 8
77
72
        reset = createPin( 16, -40, 90, "Res" )->pin();
78
73
        addDisplayText( "res", QRect( 8, -28, 16, 16 ), "Res" );
79
74
        
80
 
        
81
 
        
82
75
        // Bottom two
83
76
        
84
77
        // Pin 1
89
82
        control = createPin( 16, 40, 270, "CV" )->pin();
90
83
        addDisplayText( "cv", QRect( 8, 12, 16, 16 ), "CV" );
91
84
        
92
 
        
93
 
        
94
85
        // Output on right
95
86
        
96
87
        // Pin 3
97
88
        output = createPin( 40, 0, 180, "Out" )->pin();
98
89
        addDisplayText( "out", QRect( 8, -8, 16, 16 ), "Out" );
99
90
        
100
 
        
101
 
        
102
91
        m_r1 = createResistance( vcc, control, 5e3 );
103
92
        m_r23 = createResistance( control, ground, 1e4 );
104
93
        m_po_sink = createResistance( output, ground, 0. );
107
96
        m_r_discharge = createResistance( discharge, ground, 0. );
108
97
}
109
98
 
110
 
 
111
99
EC555::~EC555()
112
100
{
113
101
}
114
102
 
 
103
// TODO: This is simulation code not UI code, so it shouldn't be here.
 
104
// Would it be better to simulate the appropriate elements, ie comparator, voltage divider,
 
105
// and flip-flop instead of all this hand-wavy logic?
 
106
 
115
107
void EC555::stepNonLogic()
116
108
{
117
109
        double v_threshold = threshold->voltage();
120
112
        double v_trigger = trigger->voltage();
121
113
        double v_reset = reset->voltage();
122
114
        double v_vcc = vcc->voltage();
123
 
        
124
115
        double v_r = (v_control+v_ground)/2;
125
116
        
126
 
        bool com1 = ( v_threshold == v_control ) ? old_com1 : ( v_threshold < v_control );
127
 
        bool com2 = ( v_r == v_trigger ) ? old_com2 : ( v_r > v_trigger );
128
 
        bool reset = ( v_reset >= (v_control-v_ground)/2 + v_ground );
 
117
        bool com1 = (v_threshold == v_control ) ? old_com1 : ( v_threshold < v_control );
 
118
        bool com2 = (v_r == v_trigger )         ? old_com2 : ( v_r > v_trigger );
 
119
        bool reset = v_reset >= (v_control - v_ground) / 2 + v_ground;
 
120
 
129
121
        old_com1 = com1;
130
122
        old_com2 = com2;
131
123
        
132
 
        bool r = ( !reset || !com1 );
 
124
        bool r = !(reset && com1);
133
125
        bool s = com2;
134
 
        
135
126
        bool q = old_q;
136
 
        if ( v_vcc - v_ground >= 2.5 )
137
 
        {
138
 
                if ( s && !r )
139
 
                {
 
127
 
 
128
        if ( v_vcc - v_ground >= 2.5 ) {
 
129
                if ( s && !r ) {
140
130
                        q = true;
141
 
                }
142
 
                else if ( r && !s )
143
 
                {
 
131
                } else if ( r && !s ) {
144
132
                        q = false;
145
133
                }
146
 
        }
147
 
        else
148
 
        {
 
134
        } else {
149
135
                q = false;
150
136
        }
 
137
 
151
138
        old_q = q;
152
 
        
153
 
        
154
139
        m_r_discharge->setConductance(0.);
155
140
        
156
 
        if (q)
157
 
        {
 
141
        if (q) {
158
142
                m_po_source->setResistance(10.);
159
143
                m_po_sink->setConductance(0.);
160
 
        }
161
 
        else
162
 
        {
 
144
        } else {
163
145
                m_po_source->setConductance(0.);
164
146
                m_po_sink->setResistance(10.);
165
 
                if ( v_ground+0.7 <= v_vcc )
166
 
                {
 
147
 
 
148
                if ( v_ground+0.7 <= v_vcc ) {
167
149
                        m_r_discharge->setResistance(10.);
168
150
                }
169
151
        }
170
152
}
171
153
 
172