summaryrefslogtreecommitdiff
path: root/Principles_Of_Electronic_Instrumentation/Pinciples_of_electronic_Instrumentation_Ch4.ipynb
blob: c07461efb6923ec40d7aecf8f5ffc6b587a60a8c (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 4 : Combinational And Sequential Logic Circuits"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4_1,pg 488"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# find output and carry\n",
      "# it is a half-adder circuit with the output 'a' and carry 'c' given by the boolean equations\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "b1   = 1                       #input-1\n",
      "b2   = 1                       #input-2\n",
      "\n",
      "#Calculations\n",
      "a=(b1 and (not b2))+((not b1) and b2)  #sum\n",
      "c=(b1 and b2)                   #carry\n",
      "\n",
      "#Result\n",
      "print(\"sum:\")\n",
      "print(\"a = %d\\n\"%a)\n",
      "print(\"carry:\")\n",
      "print(\"c = %.f\"%c) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "sum:\n",
        "a = 0\n",
        "\n",
        "carry:\n",
        "c = 1\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4_2,pg 489"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# find difference and borrow\n",
      "#the circuit is that of a half subtractor\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "b1   = 1                       #input-1, case-1\n",
      "B1   = 0                       #input-2  case-1\n",
      "b2   = 1                       #input-1, case 2\n",
      "B2   = 1                       #input-2, case 2\n",
      "\n",
      "\n",
      "\n",
      "#Calculations\n",
      "#case-1\n",
      "d1=(b1 and (not B1))+(B1 and (not b1)) #difference\n",
      "r1=(b1 and (not B1))                    #borrow\n",
      "\n",
      "#case-2\n",
      "d2=(b2 and (not B2))+(B2 and (not b2))\n",
      "r2=(b2 and (not B2))\n",
      "\n",
      "#Result\n",
      "print(\"difference case-1:\")\n",
      "print(\"d1 = %d\"%d1)\n",
      "print(\"borrow case-1:\")\n",
      "print(\"r1 = %.f\\n\"%r1)\n",
      "print(\"difference case-2:\")\n",
      "print(\"d2 = %.f\"%d2)\n",
      "print(\"borrow case-2:\")\n",
      "print(\"r2 = %.f\\n\"%r2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "difference case-1:\n",
        "d1 = 1\n",
        "borrow case-1:\n",
        "r1 = 1\n",
        "\n",
        "difference case-2:\n",
        "d2 = 0\n",
        "borrow case-2:\n",
        "r2 = 0\n",
        "\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4_3,pg 489"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# find final output\n",
      "\n",
      "import math \n",
      "#Variable declaration\n",
      "b=1                    #input-1\n",
      "B=0                    #input-2\n",
      "\n",
      "#Calculations\n",
      "y=(not((b or B)) or (b and B))\n",
      "\n",
      "#Result\n",
      "print(\"final output:\")\n",
      "print(\"y = %d\"%y)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "final output:\n",
        "y = 0\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4_4_a,pg 489"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# decoder output\n",
      "\n",
      "import math\n",
      "#VAriable declaration\n",
      "#initial conditions\n",
      "b  = 0                # input \n",
      "Bi = 0                # initial value\n",
      "Bf = 1                # final value\n",
      "\n",
      "#initial state of outputs\n",
      "\n",
      "y1i=not(b or Bi)\n",
      "\n",
      "y2i=not(b or (not Bi))\n",
      "\n",
      "y3i=not(Bi or (not(b)))\n",
      "\n",
      "y4i=not((not(Bi)) or (not(b)))\n",
      "\n",
      "#final state of outputs\n",
      "\n",
      "y1f=not(b or Bf)\n",
      "\n",
      "y2f=not(Bf or (not(b)))\n",
      "\n",
      "y3f=not(b or (not(Bf)))\n",
      "\n",
      "y4f=not((not(Bf)) or (not(b)))\n",
      "\n",
      "print(\"first: \")\n",
      "print(\"y1 = %.f \"%y1i)\n",
      "print(\"y2 = %.f \"%y2i)\n",
      "print(\"y3 = %.f \"%y3i)\n",
      "print(\"y4 = %.f\\n\"%y4i)\n",
      "print(\"next: \")\n",
      "print(\"y1 = %.f \"%y1f)\n",
      "print(\"y2 = %.f \"%y2f)\n",
      "print(\"y3 = %.f \"%y3f)\n",
      "print(\"y4 = %.f\"%y4f)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "first: \n",
        "y1 = 1 \n",
        "y2 = 0 \n",
        "y3 = 0 \n",
        "y4 = 0\n",
        "\n",
        "next: \n",
        "y1 = 0 \n",
        "y2 = 0 \n",
        "y3 = 1 \n",
        "y4 = 0\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4_4_b,pg 489"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# decoder output\n",
      "\n",
      "import math\n",
      "#VAriable declaration\n",
      "#initial conditions\n",
      "b  = 1                # input \n",
      "Bi = 0                # initial value\n",
      "Bf = 1                # final value\n",
      "\n",
      "#initial state of outputs\n",
      "\n",
      "y1i=not(b or Bi)\n",
      "\n",
      "y2i=not(Bi or (not(b)))\n",
      "\n",
      "y3i=not(b or (not Bi))\n",
      "\n",
      "y4i=not((not(Bi)) or (not(b)))\n",
      "\n",
      "#final state of outputs\n",
      "\n",
      "y1f=not(b or Bf)\n",
      "\n",
      "y2f=not(b or (not(Bf)))\n",
      "\n",
      "y3f=not(Bf or (not(b)))\n",
      "\n",
      "y4f=not((not(Bf)) or (not(b)))\n",
      "\n",
      "print(\"first: \")\n",
      "print(\"y1=%.f \"%y1i)\n",
      "print(\"y2=%.f \"%y2i)\n",
      "print(\"y3=%.f \"%y3i)\n",
      "print(\"y4=%.f\\n\"%y4i)\n",
      "print(\"next: \")\n",
      "print(\"y1=%.f \"%y1f)\n",
      "print(\"y2=%.f \"%y2f)\n",
      "print(\"y3=%.f \"%y3f)\n",
      "print(\"y4=%.f\"%y4f)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "first: \n",
        "y1=0 \n",
        "y2=1 \n",
        "y3=0 \n",
        "y4=0\n",
        "\n",
        "next: \n",
        "y1=0 \n",
        "y2=0 \n",
        "y3=0 \n",
        "y4=1\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4_5,pg 489"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# convert 8421 to 2421 code\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "#if A8,B8,C8,D8 is the binary in 8421 code, for 12 this would be 1100(DCBA)\n",
      "#in 8421-code\n",
      "A8 = 0\n",
      "B8 = 0\n",
      "C8 = 1\n",
      "D8 = 1\n",
      "\n",
      "#Calculations\n",
      "#in 2421-code\n",
      "D2 = D8\n",
      "C2 =(C8 or D8)\n",
      "B2 =(B8 or D8)\n",
      "A2=A8\n",
      "\n",
      "#Result\n",
      "print(\"2421-code for 12(1100) is:\")\n",
      "print(\"%d%d%d%d \"%(D2,C2,B2,A2))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "2421-code for 12(1100) is:\n",
        "1110 \n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4_6,pg 490"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Xcess 3 code\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "add = \"0011\"                 #binary-3 to be added\n",
      "x   = \"0010\"                 #binary-2\n",
      "y   = \"0100\"                 #binary-4\n",
      "z   = \"0111\"                 #binary-7\n",
      "\n",
      "#Calculations\n",
      "x   = int(x,2)\n",
      "add = int(add,2)\n",
      "XS31=x+add\n",
      "XS31=bin(XS31)[2:]\n",
      "y=int(y,2)\n",
      "XS32=y+add\n",
      "XS32=bin(XS32)[2:]\n",
      "z=int(z,2)\n",
      "XS33=z+add\n",
      "XS33=bin(XS33)[2:]\n",
      "\n",
      "#Result\n",
      "print(\"XS-3 for 2: %s\"%XS31)\n",
      "print(\"XS-3 for 4: %s\"%XS32)\n",
      "print(\"XS-3 for 7: %s\"%XS33)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "XS-3 for 2: 101\n",
        "XS-3 for 4: 111\n",
        "XS-3 for 7: 1010\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4_7,pg 490"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# 8 to 1 MUX\n",
      "\n",
      "# one can see from relations of AND gate outputs in terms of address bits and input bit \n",
      "# that there are possibilities depending on which input is low\n",
      "# if I7=0, by making all address bits s1,s2,s3 as 1 one can have the conditions satisfied\n",
      "\n",
      "#Result\n",
      "print(\"This requires all the outputs from AND gates should be low\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "This requires all the outputs from AND gates should be low\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4_8,pg 490"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# truth table of RS flip flop\n",
      "\n",
      "import math\n",
      "#Variable declaration\n",
      "#enter binary 1-bit values only\n",
      "\n",
      "S  = input(\"Enter value of S\\n\")\n",
      "R  = input(\"Enter value of R\\n\")\n",
      "Qn = input(\"Enter previous value of Q\\n\")\n",
      "En = input(\"Enter enable value\\n\")\n",
      "print(\"RS flip-flop truth table:\")\n",
      "if (En==0):\n",
      "    op=Qn\n",
      "    print(\"op = %d\"%op)\n",
      "elif(( S==0) and (R==0)): \n",
      "    op=Qn\n",
      "    print(\"op = %d\"%op)\n",
      "elif ((S==0) and (R==1)): \n",
      "     op=0\n",
      "     print(\"op = %d\"%op)\n",
      "elif((S==1) and (R==0)): \n",
      "     op=1\n",
      "     print(\"op = %d\"%op)\n",
      "elif ((S==1) and (R==1)): \n",
      "     print(\"output not determinable\")\n",
      "\n",
      "print(\"the relations are:\")\n",
      "print(\"Qn=(R+Qn*)*\")              #Q* = not(Q)\n",
      "print(\"Qn*=(S+Qn)*\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": "*"
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4_9,pg 491"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# JK fiip flop\n",
      "\n",
      "# Q=(Q*+Q.K)* and Q*=(Q+Q*.J)*\n",
      "# with J=K=0 Q=Q and Q*=Q*\n",
      "# Q* is not(Q)\n",
      "\n",
      "#Result\n",
      "print(\"operational equations:\\n\")\n",
      "print(\"Q=(Q*+Q.K)* and Q*=(Q+Q*.J)*\\n\")\n",
      "print(\"holds good where Q and Q* should be given appropriate values\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "operational equations:\n",
        "\n",
        "Q=(Q*+Q.K)* and Q*=(Q+Q*.J)*\n",
        "\n",
        "holds good where Q and Q* should be given appropriate values\n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4_10,pg 491"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# 3 bit binary counter\n",
      "\n",
      "print(\"It remains positive from the falling edge of pulse-2, then falling edge of 4th, 6th and 8th pulses and so on....\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "It remains positive from the falling edge of pulse-2, then falling edge of 4th, 6th and 8th pulses and so on....\n"
       ]
      }
     ],
     "prompt_number": 27
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4_11,pg 491"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# 6 modulo counter\n",
      "\n",
      "print(\"All modulo counters are basically scalars.A 6-modulo counter is a 6-scaler\")\n",
      "print(\"so that after 6-input pulses the content of counter becomes 000(reset)\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All modulo counters are basically scalars.A 6-modulo counter is a 6-scaler\n",
        "so that after 6-input pulses the content of counter becomes 000(reset)\n"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4_12,pg 491"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# 3 bit 5 modulo counter \n",
      "\n",
      "print(\"Normal count would be 2^3=8, while 5-modulo counter would limit it to 5, so that illegitimate states are 8-5=3\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Normal count would be 2^3=8, while 5-modulo counter would limit it to 5, so that illegitimate states are 8-5=3\n"
       ]
      }
     ],
     "prompt_number": 32
    }
   ],
   "metadata": {}
  }
 ]
}