Chapter 06 : Digital Circuits

Example 6.1, Page No 165

In [12]:
import math
#initialisation of variables

R1=15.0      #in K
R2=100.0       #in K
#R1 and R2 are voltages at base which acts as potential divider
Rc=2.2            #voltage at collector in K
hfe=30.0



#Calculations
#For vi=0
Vb = (R1/(R1+R2))*(-12)       #Voltage at base in V

print("Vb= %.2f V " %Vb)
#A bias of 0V is required to cut off a silicon emitter junction transistor   given in table
Vo = 0        #in V
print("Vo = %.2f V " %Vo)

#For vi=12
vi=12            #in V
#Few standard values for silicon transistor
Vbesat=0.8       #in V
Vcesat=0.2       #in V

#Assumption: Q is in saturation region
Ic = (vi-Vcesat)/Rc       #Collector Current
print("Ic=%.2f v " %Ic)
Ibmin=(Ic/hfe)              #Mininmum current at the base
print("Ibmin=%.2f mA" %Ibmin)
I1=(vi-Vbesat)/R1             #Current in R1
I2=(Vbesat-(-12))/100         #Current in R2
Ib = I1-I2                    #Base current
print("Ib = %.2f mA " %Ib)

#Results
if Ib>Ibmin :
    print('Since Ib>Ibmin , The transistor is in saturation region and drop is Vcesat')
    vo=Vcesat
    print("vo = %.2f V " %vo)
Vb= -1.57 V 
Vo = 0.00 V 
Ic=5.36 v 
Ibmin=0.18 mA
Ib = 0.62 mA 
Since Ib>Ibmin , The transistor is in saturation region and drop is Vcesat
vo = 0.20 V 

Example 6.2, Page No 167

In [13]:
import math

#initialisation of variables
#Caption: To verify given equation

print('NOTE: We will write A with a bar on its top as   a ')
print('To verify')
print(' A + aB = A + B')

print('We know that   B + 1 = 1  and  A1 = A')
print('A + aB = A(B+1) + aB = AB + A + aB =')
print('(A + a)B + A = B + A')
print('which is equal to RHS')
NOTE: We will write A with a bar on its top as   a 
To verify
 A + aB = A + B
We know that   B + 1 = 1  and  A1 = A
A + aB = A(B+1) + aB = AB + A + aB =
(A + a)B + A = B + A
which is equal to RHS

Example 6.3a Page No 167

In [14]:
import math

#initialisation of variables

R=15.0  #in K
R1=15.0     #in K
R2=100.0       #in K
R3=2.2        #in K
V0=0         #in V
V1=12.0    #in V
Vcc=12.0   #in V

#If input is at V0=0V
Vb = -Vcc*(R1/(R1+R2))         #The base voltage of the transistor

#Calculations
print("The base voltage of transistor Vb= %.2f v " %Vb)
if Vb<0 :
    print('Q is cutoff and Y is at 12V')
    print('The result confirms the first three rows of truth table')


#If input is at V1 = 12V
#Assumption:All the diodes are reversed biased and transistor is in saturation
#If Q is in saturation
Vbe=0         #in V
Vp = V1*(R/(R+R1))        #voltage at point P in front of all diodes
print("All diodes are reversed biased by %.2f V " %Vp)
Iq = (V1/(R+R1)-(V1/R2))            #The base current of Q
Ic=V1/R3                            #Current in the collector junction
print("Ic= %.2f mA " %Ic)
hFEmin = Ic/Iq

#Results
print("hFEmin=%.2f  " %hFEmin)
print("When hFE > %.2f " %hFEmin)
print('Under these condition the output is at ground and this satisfies the first three rows of truth table')
The base voltage of transistor Vb= -1.57 v 
Q is cutoff and Y is at 12V
The result confirms the first three rows of truth table
All diodes are reversed biased by 6.00 V 
Ic= 5.45 mA 
hFEmin=19.48  
When hFE > 19.48 
Under these condition the output is at ground and this satisfies the first three rows of truth table

Example 6.3b, Page No 167

In [15]:
import math
#initialisation of variables

R=15.0    #in K
R1=15.0   #in K
R2=100.0  #in K
R3=2.2        #in K
V0=0        #in V
V1=12.0     #in V
Vcc=12.0   #in V

#Calculations
#If input is at V0=0V
Vb = -Vcc*(R1/(R1+R2))       #Base Current in V

#Finding thevenin equivallent fom P to ground
Rd = 1.0  #in K
Vd=0.7      #in v
Vr=1.0      #in K
#Thevenin Equivallent Voltage and resistance from P to ground
v = (Vcc*(Rd/(Rd+R)))+(Vd*(R/(R+Rd)))
rs = Rd*(R/(R+Rd))
#Open Circuit Voltage at base of the transistor
Vb1 = (-Vcc*((R1+rs)/(R1+R2+rs))) + (v*(R2/(R1+R2+rs)))

#Results
print("Vb1 = %.2f v " %Vb1)

if Vb1>Vb :
    print('The voltage is adequate to reverse bias Q')
Vb1 = -0.44 v 
The voltage is adequate to reverse bias Q

Example 6.3c Page No 168

In [16]:
import math
#initialisation of variables
R=15.0    #in K
R1=15.0  #in K
R2=100.0         #in K
R3=2.2        #in K
V0=0       #in V
V1=12.0   #in V
Vcc=12.0   #in V

#Calculations
#To find wether with given conditions NANAD gate is satisfied
#Finding thevenin equivallent from P to ground
Rd = 1        #in K
Vd=0.7       #in v
Vr=1.0     #in K
v = (Vcc*(Rd/(Rd+R)))+(Vd*(R/(R+Rd)))
rs = Rd*(R/(R+Rd))

#If the inputs are high

Vcesat = 0.2      #in V
Vb2 = (-Vcc*(R1/(R1+R2)) + ((Vd+Vcesat)*R2/(R1+R2)))

#Results
print("Vb2= %.2f V " %Vb2)
print('It cuts off Q Y=1 ')
Vb2= -0.78 V 
It cuts off Q Y=1 

Example 6.4 Page No 169

In [17]:
import math

#initialisation of variables
#Caption: To verify that AND-OR topology is equivallent to NAND-NAND system

print('In digital electronics we have to come across situations where we need to use an inpout with a bar but here we will denote as')
print('X with a bar = Xb and X with two bars = Xbb')

#Solution
print('We know that X =Xbb')
print('For AND OR logic the output of AND and simultaneously neglecting the input to following OR does not change the logic')
print('We have also neglected the output of the OR gate and at the same time have added an INVERTER so that logic is once again unaffected')
print('AN OR gate neglected at each terminal is an an AND circuit')
print('Since AND followed by an inverter is NAND ')
print('Hencee the NAND NAND is equivallent to AND OR')
In digital electronics we have to come across situations where we need to use an inpout with a bar but here we will denote as
X with a bar = Xb and X with two bars = Xbb
We know that X =Xbb
For AND OR logic the output of AND and simultaneously neglecting the input to following OR does not change the logic
We have also neglected the output of the OR gate and at the same time have added an INVERTER so that logic is once again unaffected
AN OR gate neglected at each terminal is an an AND circuit
Since AND followed by an inverter is NAND 
Hencee the NAND NAND is equivallent to AND OR

Example 6.5a, Page No 179

In [18]:
import math
#initialisation of variables
#Caption:To find hFEmin
#Given Data
#For transistor
Vbesat=0.8#Vgamma of diode in V
Vy=0.5#in V
Vcesat=0.2#in V
R = 5#in K
Rc = 2.2#in K

#For diode
Vyd=0.6#in V
Vdrop=0.7#in V

#Calculations
#The logic levels are Vcesato=0.2V for 0 state
Vcesato=0.2#in V
#The logic levels are Vcc=5V for 1 state
Vcc=5#in V
print('If atleast one input is in 0 state')
Vp = Vcesato + Vy#Potential at point P
print("Vp= %.2f V " %Vp)
#For diodes D1 and D2 to be conducting
v = 2*Vdrop
print('For diodes D1 and D2 to be conducting')
print("required voltage = %.2f V " %v)
#These diodes cutoff
Vbe = 0
if Vbe<Vy :
    print('Q is OFF')
    print('Output rises to 5V and Y = 1')
    print('This confirms first 3 rows of NAND truth table')
#if all inputs are at V(1)=5V , we shall assume all input diodes OFF and D1 and D2 conduct and Q is in saturation
print('When inputs are at 5V')
Vp = Vdrop + Vdrop + Vbesat
print('V',Vp,'Vp=')
print("Vp= %.2f V " %Vp)
print("The voltage across all input diode = %.2f v " %(Vcc-Vp))
#For finding hFEmin
I1 = (Vcc-Vp)/R
I2 = Vbesat/R
Ib = I1-I2
Ic = (Vcc-Vcesat)/Rc
hFEmin = Ic/Ib

#Results
print("hFEmin= %.2f " %hFEmin)
If atleast one input is in 0 state
Vp= 0.70 V 
For diodes D1 and D2 to be conducting
required voltage = 1.40 V 
Q is OFF
Output rises to 5V and Y = 1
This confirms first 3 rows of NAND truth table
When inputs are at 5V
('V', 2.2, 'Vp=')
Vp= 2.20 V 
The voltage across all input diode = 2.80 v 
hFEmin= 5.45 

Example 6.5b Page No 179

In [19]:
import math 

#initialisation of variables
#Caption:When atleast one input is at V(0) in NAND gate
#Given Data
#For transistor
Vbesat=0.8#in V
Vy=0.5#in V
Vcesat=0.2#in V
R = 5#in K
Rc = 2.2#in K


#Calculations
#For diode
Vyd=0.6#Vgamma in V
Vdrop=0.7#in V

#The logic levels are Vcesato=0.2V for 0 state
Vcesato=0.2#in V

print('If atleast one input is in 0 state')
Vp = Vcesato + Vdrop #Voltage at point P
print("Vp= %.2f v " %Vp)
Vbe = Vp-Vyd#Voltage at base emitter

#Results
print("Vbe = %.2f v " %Vbe)
if Vbe<Vy :
    print('Q is cutoff')

if Vbe>Vy :
    print('Q is ON')
If atleast one input is in 0 state
Vp= 0.90 v 
Vbe = 0.30 v 
Q is cutoff

Example 6.5c Page No 179

In [20]:
import math
#initialisation of variables

Vbesat=0.8#in V
Vy=0.5#in V
R = 5#in K
Rc = 2.2#in K

#Calculations
#For diode
Vyd=0.6#in V
Vdrop=0.7#in V

#Calculations
#The logic levels are Vcesato=0.2V for 0 state
Vcesato=0.2#in V
Vp = Vdrop + Vdrop + Vbesat#Voltage at point P

#Results
print("Vp= %.2f v " %Vp)
print("Each diode is reversed biased by %.2f v " %(Vcc-Vp))
print("A diode starts to conduct when it is forward bias by %.2f v " %Vyd)
vn = (Vcc-Vp) + Vyd #Noise Spike which will cause the malfunction
print("A noise spike which will cause malfunction is %.2f v " %vn)
Vp= 2.20 v 
Each diode is reversed biased by 2.80 v 
A diode starts to conduct when it is forward bias by 0.60 v 
A noise spike which will cause malfunction is 3.40 v 

Example 6.5d Page No 180

In [21]:
import math

#initialisation of variables

#For transistor
Vbesat=0.8#in V
Vy=0.5#in V
R = 5#in K
Rc = 2.2#in K

#The logic levels are Vcesato=0.2V for 0 state
Vcesato=0.2#in V
#For diode

#Calculations
Vyd=0.6#in V
Vdrop=0.7#in V

Vp = Vcesato + Vdrop#Voltage at point P
print("Vp= %.2f v " %Vp)
Vbe = Vy#Voltage at base emitter will be same as Vgamma
vp = Vbe + Vyd +Vyd#The level to which vp should increase
Vn = vp - Vp#Noise Margin

#Results
print("Noise Margin = %.2f v " %Vn)
Vp= 0.90 v 
Noise Margin = 0.80 v 

Example 6.6, Page No 92

In [22]:
import math

#initialisation of variables

hFE=30
Vbe1active=0.7#in V
Vd2=0.7#in V
Vbe2sat=0.8#in V
Vcc=5#in V
R1=1.75#in K
R2=2#in K
R3=2.2#in K
R4=5#in K


#Calculations
Vp = Vbe1active + Vd2 + Vbe2sat#Voltage at point P
#The current in 2K resistor is Ib1
#In active region
#Ic1=hFE*Ib1
#I1 = Ib1+Ic1=(1+hFE)*Ib1.... Now applying KVL between Vcc and Vp
#Vcc-Vp = R1*(1+hFE)*Ib1 + 2*Ib1
Ib1 = (Vcc-Vp)/(R1*(1+hFE)+2)#Base current in transistor 1
print("Ib1= %.2f mA " %Ib1)
Ic1=hFE*Ib1#Collector Current in transistor 1
print("Ic1= %.2f mA " %Ic1)
I1 = Ib1 + Ic1#in mA
I2=Vbe2sat/R4#in mA
Ib2 = I1-I2#Base Current in Transistor 2
#The unloaded current of Q2
Iq2=(Vcc-0.2)/R3
#For each gate which it drive ,Q2 must sink a standard load of
I=(Vcc-Vd2-0.2)/(R1+R2)
#To Calculate the FAN OUT
#The maximum current is hFE*Ib2
#hFE*Ib2 = (I*N) + Iq2
N=((hFE*Ib2)-Iq2)/I#FAN OUT

#Results
print("N = %.2f v " %N)
Ib1= 0.05 mA 
Ic1= 1.49 mA 
N = 35.96 v