Lecture: 19
Objective: To provide a working understanding of an analog to digital converter including: converter resolution, voltage references, and quantization error.

Analog to Digital Conversion

The PIC has an analog to digital converter (ADC) subsystem which takes an analog input between 0 and 3.3v and converts the analog voltage into number, called the converted value between 0 and 1023. The conversion from voltage to number is ratiometric, meaning that the output is directly proportional to the input.

Ratiometric

Ratiometric means that the ratio of the input voltage to 3.3v is the same as the ratio of the converted value to 1024. The leftmost graph below shows the input voltage vs. the converted value. In reality the graph is not a smooth line, but the orange staircase going upwards every α = 3.3v/1024. The first half step allows the transition from converted value 0b000 to 0b001 to occur at the half-way point between 0v and αv. The ideal transfer function shows how the input voltage is converted by an ADC with an infinite number of bits - every analog input voltage would have its own unique binary representation on the output.


Let's apply the definition of ratiometric to a pair of problems.

Converter resolution

When you work with other microcontrollers you will not doubt find that they have different number of bits. The number of bits produced in the converted value is called the resolution of the ADC. A count is a one unit change in the converted value. So a N-bit ADC has 2N counts in its full range.

Fundamentally, changing the resolution of the ADC changes the scale on the vertical axis of the ratiometric graph shown above. So all we need to do to determine converted values is to change the "210" in the graph with "2N", where N is the resolution of the ADC.
Let's start our exploration of this concept by examining a straight forward question.

Voltage references

We started this section by having the PIC converts voltages between 0v and 3.3v. The minimum and maximum voltage for an ADC are called the reference potentials. You can configure the PIC to use two pins Vref- (RA2) and Vref+ (RA3) as the A/D reference potentials and on our development board, these pins are connected to 10kΩ resistors to 3.3v through the two push buttons. If you did not press the push buttons, you could ties these two pins to other voltages to change the reference potentials on the PIC. You could do this in order to decrease the quantization error. Let's examine two examples that will help us better understand this concept.

Quantization error

This process of converting an analog voltage to a digital value is commonly called quantization. Related to the concept of quantization is quantization error. Quantization error is measured in terms of input volts and is the amount of rounding error, typically ½ of the least significant bit, or ½ count. You could also think about it as the worst case difference between an input voltage and the converted value's corresponding analog input voltage. A third way to think about quantization error is to ask, "how far off can the converted value be in representing the actual analog input?" Let's look at a numerical value to understand this definition better.

Say you are using an ADC with a 3-bit resolution with 3.3 V and 0 V reference voltages and apply an input of 0.4254 V. Looking at some of the previous work performed in this lecture, we see that a 0.4254 V input has a converted value of 1.25 which is rounded to 1. The difference between the true output of 1.25 and the actual output of 1.0, when represented in terms of the input voltage corresponds to 0.4254 V - 0.4125 V = 0.0129 V which is the quantization error for an input voltage of 0.4254. Different input voltages will have different quantization errors. An important value is the worst case quantization error; it is typically this value that is quoted when you read a quantization error specification for an ADC. In order to determined this worst-case quantization error you need to find the maximum rounding error in the converted value for an input voltage. To help with this, let's plot the data we created for the 3-bit ADC from a previous section.

Say you are using an ADC with a 3-bit resolutions and a 3.3 V and 0 V input voltage range, what analog input is associated with each of the following converted values? We found the answer to be:
Converted Value Analog Input
0 0 V
1 0.413 V
2 0.825 V
3 1.238 V
4 1.65 V
5 2.063 V
6 2.475 V
7 2.888 V
The following figure plots this data as red dots on a graph with the analog input voltage on the horizontal axis and the converted value on the vertical axis. The black lines on the graph represent the converted values rounded to the nearest integer. In order to better understand the black line, the analog input and converted values from a previous question are annotated on the graph.


Now this graph can help you to better understand quantization error. Quantization error is the maximum amount of rounding error in the converted value represented in terms of the input. Looking at this graph, the maximum rounding error occurs when the converted value jumps to a new value. For example an analog input of 0.6188 V generates a fractional converted value of 1.5 that is rounded to 2. The converted value misrepresents the true converted value by 0.5 "bits" Since quantization error is represented in terms of the input voltage, let's convert ask how much input voltage corresponds to half a bit using our familiar ratiometric equation.

   3.3v   x v
   ---- = ----		x = 0.5 * 3.3V / 8 = 0.20625 V
    2^3   0.5

So the quantization error of an 3-bit ADC with reference voltages 0 V and 3.3V is 0.20625 V.

Any way you look at it, the input analog voltage can change by at most the equivalent of ½LSB without a change in the converted value. This ½LSB equivalent on the input is the quantization error.

Test your understanding

You can find the solutions embedded in the "source code" for this web page by right mouse clicking on this web page and selecting "view source". The solutions are in HTML comments.
  1. Complete the following table.
    Analog voltage Converted Value Resolution VRH VRL
      212 8-bit 5 V 0 V
      212 8-bit 3 V 2 V
      212 12-bit 5 V 0 V
      212 12-bit 3 V 2 V
    2.6 V   8-bit 5 V 0 V
    2.6 V   8-bit 3 V 2 V
    2.6 V   12-bit 5 V 0 V
    2.6 V   12-bit 3 V 2 V
    0.244 V 100   5 V 0 V
    2.4 V 205   3 V 2 V
    2.79 V 102 8-bit   0 V
    2.79 V 101 8-bit   2 V
  2. Complete the following table.
    Resolution VRH VRL Quantization Error
    12-bit 5 V 3 V  
    11-bit 12 V   1.22 mV
    14-bit   2 V 120 uV
      5 V 2 V 1.46 mV