ADC tutorial (counting type)
ADC Math
0-5V Analog I/P (This is the maximum voltage we can give to PIC)
0-1023 Digital Count (The equailent digital count 2n n stands for number of bits example 28 = 2x2x2x2x2x2x2x2x2x2 = 1023)
Resolution = (5-0)/(1023-0) = 0.00489 V/Count (or) 5/1020(or) 2n -1
To measure the 5 volt using counting type ADC
I/P voltage = Va = 0.00489 (V/Count) * Digital Count (we know it takes 1023 count to convert 5 volt to equalent binary value from 0000000000 to 1111111111)
Consider the below example
In the above circuit we want to measure 20 volt but our PIC will handle maximum voltage of 5Volt. So we want to do some voltage divider network
Consider the above equation and find the resistance value here the roll of zener is it will ensure only the voltage is around 5.1 volt.
All the things are same except input voltage its 20V instead of 5V
so we want to do some mathematical equation in Va (Input voltage)
So Va (I/P voltage) = 4(to multiply to convert become 20)*Va = 4* Digital Count * 0.00489(resolution) = 0.01956 * Digital Count
10 bit ADC Binary and equailent analog count
0000000000 (binary minimum count) 0.00489 V/Count
0000000001 (binary minimum count) 0.00489 V/Count
0000000010 (binary minimum count) 0.00978 V/Count (0.00489+0.00489)
.
.
.
.
.
.
.
.
.
1111111111 (binary minimum count) 1023
Make the thing clear 0.00489 (V/Count) x 1023 = 5.0024 (app 5V)
To avoid floating point, use I/P voltage = 196*Digital Count. This number is a long integer.
Example, suppose
Vin = 13.6V. Then,
Va = 0.25*Vin = 3.4V
=> Digital Count = 3.4/0.00489 = 695
=> Calculated I/P Voltage = 196*695 = 136220 = 13.6V (First 3 digits of 6 digit product)
Sources of error
The above math looks pretty easy but when you implement it, you will not errors in output measurements because the above calculations are based on following ideal conditions:
Example, suppose
Vin = 13.6V. Then,
Va = 0.25*Vin = 3.4V
=> Digital Count = 3.4/0.00489 = 695
=> Calculated I/P Voltage = 196*695 = 136220 = 13.6V (First 3 digits of 6 digit product)
Sources of error
The above math looks pretty easy but when you implement it, you will not errors in output measurements because the above calculations are based on following ideal conditions:
- Vcc supply voltage to PIC12F683 is exactly 5V,
- R1 and R2 are exact 1.3K and 3.9K respectively
So, let's revise the math above with real figures. I measured the supply voltage to PIC and it is 5.02V. R1 and R2 are measured to be 1267 and 3890 Ohms. So this gives,
0 - 5.02 V Analog I/P ---> 0-1023 Digital Count
=> Resolution = (5.02-0)/(1023-0) = 0.004907 V/Count
Va = 1267*Vin/(1267+3890) = 0.2457*Vin
=> I/P voltage = 4.07*Va = 4.07* Digital Count * 0.004907
= 0.01997 * Digital Count
= 0.02*Digital Count (Approx.)
To avoid floating point, use I/P voltage = 2*Digital Count. No need for Long integer.
Example, suppose
Vin = 4.6V. Then,
Va = 0.2457*Vin = 1.13V
=> Digital Count = 1.13/0.004907 = 230
=> Calculated I/P Voltage = 2*230 = 0460 = 04.6V (First 3 digits of 4 digit product)
Supose u want to make a volt meter it's maximum range will be 5 Volt(as u say)
Ur ADC converter has 10 Bit resulotion it mean in it has maximum value in decimal 1023.
It means as u apply maximum voltage(as u say 5 volt) to ADC it will give u 1023 in decimal.
So the formula is
Ur ADC converter has 10 Bit resulotion it mean in it has maximum value in decimal 1023.
It means as u apply maximum voltage(as u say 5 volt) to ADC it will give u 1023 in decimal.
So the formula is
Voltage = Applied voltage * maximum range / ADC resulotion
Voltage > measured voltage (we don't know it's value)
Applied Voltage > This is our applied voltage which we apply on ADC leg it rage will be 0 ~ 1023.
Maximum range > for which range u want to scale it( as u say 5 volt)
ADC resulotion > 10 Bit it means it maximum value in binary = (1111111111) or in Decimal 1023.
Now we start,
u want to scale it for 5 Volt( it mean it's maximum reading will 5 volt)
The formula will be
Voltage = Applied voltage * 5 / 1023
for example u apply 5 volt to ADC.
then ADC will convert this value into binary so it will be (1111111111) or if we see it in decimal then it will be 1023
It means
then ADC will convert this value into binary so it will be (1111111111) or if we see it in decimal then it will be 1023
It means
Applied Voltage = 1023
So we put this value in our formula
Voltage = 1023 * 5 / 1023
So the answer will be
Voltage = 5
Now an other example
Supose u apply 2.5 volt to ADC
So it will conver it into binary (0111111111) or it will eqaul to 511 in decimal.
Applied Voltage = 511
So we put this value in our formula
Voltage = 511 * 5 / 1023
So the answer will be
Voltage = 2.497
No comments:
Post a Comment