# 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)
# 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))
# 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))
# 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)
# 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)
# 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))
# 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))
# 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)
# 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)
# 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%")