Chapter 5: ADC and DAC

Example5_1,pg 491

In [1]:
# output voltage

import math
# Variable declaration
Vref=12.0              #ref. voltage
n =4.0                 #no. of binary weighted resistors
n1=3.0                 #input-1
n2=1.0                 #input-2

#Calculations
Vo=-(Vref/2**n)*(2**n1+2**n2)

#Result 
print("output voltage:")
print("Vo = %.1f V"%Vo) 
output voltage:
Vo = -7.5 V

Example5_2,pg 491

In [3]:
# voltage division ratio and feedback resistor

import math
# Variabe declaration 
# serie arm resistance = 10k, since the divider arm resistance Rsh=2Rse 
# therefore for straight binary code, one should have section voltage ratio as Vos/Vis=0.5

#Vo/Vref=0.5
Rse=10*10**3        #series resistance(Rsh/2)

#Calculation
Rf=0.5*(16*Rse)/15 #feedback resistor

#Result
print("voltage section ratio = 0.5")
print("\nfeedback resistor:")
print("Rf = %.2f k-ohm"%(Rf/1000)) 
voltage section ratio = 0.5

feedback resistor:
Rf = 5.33 k-ohm

Example5_3,pg 492

In [4]:
# output voltage

import math
#Variable declaration
Rse = 1*10**3               #series resistance
Rsh = 2*10**3               #shunt resistance
Vref= 5.0                   #ref. voltage
n1  = 0                     #input-1
n2  = 3                     #input-2
Ro=0.22*10**3               #load resistance

#Calculations
Vo=(Vref*(2**n1+2**n2)/16)*(Ro/(Ro+Rsh))

#Result
print("output voltage:")
print("Vo = %.3f V"%(math.floor(Vo*1000)/1000)) 
output voltage:
Vo = 0.278 V

Example5_4,pg 492

In [5]:
# find count

import math
#Variable declaration
Vref=5.0               #ref. voltage
t=1*10**-3             #sawtooth wave time
f=100*10**3            #clock frequency
Vi=1                   #input voltage

#Calculations
N=((t*f*Vi)/Vref)      #count

#Result
print("count = %d"%N)
count = 20

Example5_5,pg 492

In [8]:
# find integrator output voltage

import math
#Variable declaration
Tu=1*10**-3                   #wave time
Vi=0.2                        #input voltage
t=4*10**-3                    #integration time constant(1/RC)


#Calculation
V1=((Vi*Tu)/t)                #integrator output voltage

#Result
print("integrator output voltage:")
print("V1 = %.2f V"%V1) 
integrator output voltage:
V1 = 0.05 V

Example5_6,pg 493

In [8]:
# find rise in output voltage and charging time

import math
#Variable declaration
Tz=0.6*10**-3                #discharge time
Vref=1                       #ref. voltage
t=4*10**-3                   #integrator time const.
Vi=0.2                       #input voltage
#Calculations
Vk=((Vref*Tz)/t)             #rise in output integrator
Tu=Vref*(Tz/Vi)              #charging time

#Result
print("Rise in integrator output:")
print("Vk = %.2f V\n"%Vk)
print("charging time:")
print("Tu = %.0f msec"%(Tu*1000))  
Rise in integrator output:
Vk = 0.15 V

charging time:
Tu = 3 msec

Example5_7,pg 493

In [10]:
# find count of counter

import math
#Variable declaration
Vref=1                 #ref. voltage
Vi=0.2                 #input voltage
n=15                   #no. of counts before reset(n+1)

#Calculations
N=((n+1)*Vi)/Vref     #no.of counts over charging time

print("No of counts over charging time:")
print("N = %.1f = %d(approx.) "%(N,N)) 
No of counts over charging time:
N = 3.2 = 3(approx.) 

Example5_8,pg 493

In [14]:
# find input voltage

import math
Nx=2**6             #6 bit counteer register
Vref=2.2            #ref. voltage
N=32.0              #SAR output

#Calculations
Vi=(N/(Nx+1)*Vref) #input voltage

#Result
print("Input Voltage:")
print("Vi = %.2f V"%Vi) 
Input Voltage:
Vi = 1.08 V

Example5_9,pg 493

In [15]:
# conversion number

import math
#Variable declaration
n=3                     #3-bit ADC
Vref=2.2                #ref.voltage
Vi=1                    #input voltage

#Calculations
N=(((2**n)-1)*Vi)/Vref  #SAR output

#Result
print("SAR conversion no.:")
print("N = %.2f "%N) 
SAR conversion no.:
N = 3.18 

Example5_10,pg 493

In [14]:
# signal to noise ratio

import math
#Variable declaaration
n = 3.0                                #3-bit ADC

#Calculations
SbyN=(((2**(n-1)*12**0.5)/2**0.5))     #S/N ratio

#Result
print("S/N ratio:")
print("SbyN = %.3f\n"%SbyN) 
print("This produces an error due to noise nearly 10%")
S/N ratio:
SbyN = 9.798

This produces an error due to noise nearly 10%