| Tutorial:
Counting type ADCs
Analog to Digital Converts
By Ibrahim Kamal
Last update:
28/2/08
Note:
You can find the schematic
of a very simple 3-bit Flash ADC here
|
Overview
In this article, we will discuss a very common type of digital
to analog converters called the counting type ADC.
Based on our previous
simple tutorial about DACs (digital
to analog converters), this article presents a technique
of building ADCs that you can use to learn and master the
process of analog to digital conversion, but also use it
in many of you projects, adding an incredible feature to
basic microcontrollers like the 8051 that don't have integrated
ADCs.. |
|
The
principle of operation
While there are many ways of building and implementing a
counting type ADC, they all rely on the same basic idea. I am
going to use a micro-controller by default to perform all the
required logical operations, because in most cases, where an ADC
is found, a micro-controller is also
present.
As you can see in figure 1A, the counting type ADC
is based on Digital to analog converter (DAC). An R/2R
DAC is very suitable for this task, and it can offer
more precision by adding more branches to the R/2R network,
consequently adding more bit depth to the converter, or
you may call it "more resolution".
To understand how an analog input is converted to digital
data, you have to think in the reverse direction, because
that's what really happens, the microcontroller tries
to mimic the analog input by producing the closest analog
input through the DAC. More precisely, The
|

Fig.
1A:
Principle of operation of a counting type ADC
|
microcontroller generates a digital ramp (a signal
increasing from 0 to max scale) on the input of the DAC, which
in case of an 8-bit DAC with a 5V maximum output voltage, would
be a counting from 0 to 255, generating an increasing analog voltage
(0v to 5V) at the output of the DAC, which is then fed to a comparator
to be compared with analog input signal being converted.
While the analog output voltage from
the DAC is smaller than the measured input, the comparator
will output a logic 0. Once the DAC output a voltage
that is slightly bigger than the analog input, the comparator
will output a logic 1 indicating the end of the conversion
(refereed to as EOC). The job of the microcontroller
is to monitor the output of the comparator, and record
the value of the data that was sent to the DAC just
before, or just after the comparator' output flipped
form 0 to 1.
Figure 1B may help you to imagine the relation between
the 3 major signals: The analog input being measured,
the Analog output from the DAC and the EOC signal.
|
Fig.
1B:
Principle of operation of a counting type ADC
|
The resolution - which is the smallest change
in the input that can be detected - depend on the number of data
line 'n'. That means that you can build your own ADC with any
precision you may need. That becomes interesting sometimes when
you need very low or very high precision ADCs.
The
Electronic circuit
Any Experienced reader may have
noticed that the hardware for such a device is very simple (with
disregard to the microcontroller). Indeed, you only need to slightly
change the design of the DAC explained in
this early tutorial. The components on the left part
of the schematic are standard in most of the projects, which are
the capacitors (C1 and C2), the crystal oscillator (X1), the reset
switch (SW1) with the debouncing capacitor (C3) and resistor (R12),
and the connector (J1) for ISP programming.
The resistor R13 to R32 and LM358 comparator are responsible of
converting Digital signals to Analog signals with 10 bits resolution,
and adding to that a micro-controller, we get an ADC.
As mentioned before, the purpose of a micro-controller
in this application is to generate the analog signals to be compared
with the measured input voltage (Vin). The LM358 comparator will
give a change of logic level (from 0 to 1) indicating that the
simulated analog voltage reached the measured voltage, thus indicating
the end of conversion.
The
Software
The software to be loaded on a microcontroller to perform the task of converting analog signals to
digital ones is very simple; The pins P3.0 and P3.1 are both set
to Logic 0, and the value of port 2 (which is connected to the
first 8 bits of the DAC) is gradually incremented. After each
increment the pin P3.7 is checked. Whenever P3.7 is low (logic
0) that means that the generated Analog signal corresponds (with
one bit accuracy) to the measured analog signal, and consequently
corresponds to the last counted digital value in the micro-controller.
In order to extend the resolution from 8 bits to 10 bits, the
value of the pins P3.0 and P3.1 is increased each time Port 2
overflows. This way, the precision of this converter is 5
/ 1024 = 0.005V, and you can freely increase the precision
by increasing the number of bits.
Here is an example C code for the 8051 micro-controller to read
the voltage from the above schematic.
While
(1){
done = 0;
P3_0 = 0;
P3_1 = 0;
P3_7 = 1; //set
P3_7 as input
P2 = 0; //Start
counting from 0
delay(100);
while (P2 < 255){
P2++;
delay(100); //Slow
down the process, to be compatible with
if (P3_7 == 1){ //the
response time of the Op-Amp.
done = 1;
break;
}
}
if
(done == 0){
P3_0 = 1;
P3_1 = 0;
P3_7 = 1;
P2 = 0;
while (P2 < 255){
P2++;
delay(100);
if (P3_7 == 1){
done =
1;
break;
}
}
}
if
(done == 0){
P3_0 = 0;
P3_1 = 1;
P3_7 = 1;
P2 = 0;
while (P2 < 255){
P2++;
delay(100);
if (P3_7 == 1){
done =
1;
break;
}
}
}
if
(done == 0){
P3_0 = 1;
P3_1 = 1;
P3_7 = 1;
P2 = 0;
while (P2 < 255){
P2++;
delay(100);
if (P3_7 == 1){
done =
1;
break;
}
}
}
if (done == 1){
bit8 = P3_0;
bit9 = P3_1;
voltage = ((P2 + (bit8 * 256) + (bit9 * 512))*conversion_factor);
}
|
The variable 'conversion_factor' in the code represent a factor
that relates the counted value to the corresponding voltage, and
is easily obtained using some trials and errors. Noting that the
relation between the counted value and the corresponding voltage
is linear, it's easy to find this factor based on only 2 readings.
Join the Mailing List |
| Let us get in
touch with you when we upload new interresting content.
|
Preview of the last 15
messages discussing this page. Messages are sorted from the newest to
the oldest. |
Posted
by:
ikalogic
on:
29 Jun 2010 |
Re: ISP |
|
 |
| Quoting kennysax: what is the meaning of the ISP (JACK) u said in the circuit |
this is the In System Programming port. as the name implies, it's used to program the micro controller with any ATMEL ISP programmer.
|
|
|
|
Posted
by:
kennysax
on:
29 Jun 2010 |
ISP |
|
 |
what is the meaning of the ISP (JACK) u said in the circuit
|
|
|
|
Posted
by:
ikalogic
on:
26 Dec 2009 |
Re: Counting type ADCs |
|
 |
I agree, you know it have been years since i made those articles.
the site needs a good overhaul.. I'lve learned a lot since those articles, finished my master studies.. worked in a big electronics firm..
|
|
|
|
Posted
by:
nura100
on:
26 Dec 2009 |
Counting type ADCs |
|
 |
Hello IKa, Merry Christmas!
i strongly feel that using op-amp LM358 is incorrect, what your application needs is a Voltage Comparator like LM393, use of op-amp for a comparing job is not advisable.because they are slow and they don't give out clear digital High(1) or LOW(0). Many people confuse between an Op-amp and Voltage Comparator, Comparator is basically an Op-Amp which is fine tuned for a Comparing job and not for amplification.
Arun
|
|
|
|
Posted
by:
huayuliang
on:
27 Sep 2009 |
Counting type ADCs |
|
 |
the op amp working on a opened loop mode, it has very high gain, a little change on input can cause output pin generate very large change. so, in this case , you can use the op amp as a comparetor. or say, you can see it as a compareter...sorry for may bad english.
|
|
|
|
Posted
by:
harsh
on:
28 Nov 2008 |
Counting type ADCs |
|
 |
hi i am working on analog input tomicrocntroller , for that i uses a 12 bit adc(3201) , but it's counts are vary up to 10 to 15count, please help me how i avoid this variation in counts.
|
|
|
|
Posted
by:
asher081
on:
12 Nov 2008 |
Counting type ADCs |
|
 |
hiiiiiiiii ibrahim i want the circuit for sample and hold for flash type ADC first we have to give vin to the sample and hold and then we have to compare it with vref
|
|
|
|
Posted
by:
mark
on:
02 Nov 2008 |
Re: Counting type ADCs |
|
 |
94 ghz frequency is where a lot of modern energy medicine is devloped. Thats why I was hoping 8 to 16 bit rate would be enough to download analog to digital 94 ghz electromagnetic energy into a computer using millimeter wave analysis of passive signiture software. I would be using a w-band quassi optical antenna.
|
|
|
|
Posted
by:
ikalogic
on:
02 Nov 2008 |
Re: Counting type ADCs |
|
 |
| Quoting mark: Will the ADC or DAC in these tutorials handle 94 ghz or do I need a higher bit rate. |
GHZ!!! not at all.. why do you need such bit rates???
|
|
|
|
Posted
by:
mark
on:
02 Nov 2008 |
Counting type ADCs |
|
 |
Will the ADC or DAC in these tutorials handle 94 ghz or do I need a higher bit rate.
|
|
|
|
Posted
by:
ikalogic
on:
03 May 2008 |
Re: Counting type ADCs |
|
 |
| Quoting kompile: Hai Ibrahim. how about adc0809 ? do you have schematic for adc0809. |
Hello,
Unfortunately no. but i guess the net is full of it...
And they are getting old since most new uC have built-in ADCs...
|
|
|
|
Posted
by:
ikalogic
on:
29 Apr 2008 |
Re: Counting type ADCs |
|
 |
Quoting bittusrk: Can I use an LM339 instead of the LM358 for all the projects you have on this site? If not, in what ways is the latter superior over the former? |
The LM358 is an OLD, outdated, very standard operational amplifier. Most, if not all Op-amps are superior to it. (but not the 741! which is realy very old)
The LM358, being standard, can be replaced by any pin compatible op-amp.
I didn't study the LM339, but i am quite sure that you can use it for the projects on this site
|
|
|
|
Posted
by:
bittusrk
on:
29 Apr 2008 |
Counting type ADCs |
|
 |
Can I use an LM339 instead of the LM358 for all the projects you have on this site? If not, in what ways is the latter superior over the former?
|
|
|
|
You have
to be a member to post replies. |
|
|
|