Skip to main content

Microcontrollers

Section 6.1 Principles of Operation

Analog values must be converted into digital values in order to work with the digital functionality of a microcontroller. This is accomplished with an analog to digital converter (ADC). A single-ended ADC will convert a single analog signal into a digital value. A differential ADC will convert the difference between two analog signals to a digital value. [16.19] This textbook will consider single-ended analog to digital conversion (ADC).
The resolution of an ADC relates to the number of bits of binary used to store the result. This value also relates to the number of possible voltage values that can be differentiated between. An \(n\)-bit ADC can differentiate between \(2^n\) different binary values. In this manner, the resolution of an ADC will define the step size (\(\Delta V\)), which is the minimum change in voltage required to change the output value. The step size is defined by (6.1.1).
\begin{equation} \Delta V = \frac{V_{ref}}{2^n}\tag{6.1.1} \end{equation}
To convert an analog voltage signal into digital values, the analog signal must be sampled, quantized, and encoded.

Subsection 6.1.1 Sampling

An infinite number of points canโ€™t be digitized by a microcontroller because it would require infinite processing power and infinite memory. Therefore, the analog signal must be sampled periodically. This sample rate is very important when doing signal processing (audio, video, etc.). It is inversely related to conversion accuracy. The fine details of sampling rate are beyond the scope of this course; you will very likely study the topic in a signals and systems electrical engineering course. Figureย 6.1.1 shows the analog signal from Figureย 6.0.1 sampled every millisecond. At each point in time, the sampled data is held in memory and then quantized and encoded.
A graph with time on the x-axis and voltage on the y-axis. The signal being graphed changes continuously along the time axis and takes on different voltage values between 0 and 5V. The exact signal is arbitrary and used to demonstrate the concept of an analog signal. A dot is placed along the signal every 1 millisecond to demonstrate the voltage value that is sampled at that instant in time.
Figure 6.1.1. An analog signal sampled every millisecond.

Subsection 6.1.2 Quantization

Because digital data cannot take on a continuum of values, the sampled analog data must be set equal to one of a number of discrete values. Figureย 6.1.2 shows an analog signal that has been quantized. At every sampled point in the signal, that value is rounded down to the nearest possible value of \(V_{ref} \div 2^n\text{,}\) where \(n\) refers to the number of bits of system resolution.
A graph with time on the x-axis and voltage on the y-axis. The signal being graphed changes continuously along the time axis and takes on different voltage values between 0 and 5V. The exact signal is arbitrary and used to demonstrate the concept of an analog signal. The nearest quantized voltage level is also graphed, indicating the quantized signal after going through a 3-bit analog to digital converter.
Figure 6.1.2. An analog signal sampled every 1 ms that has been quantized in a 3-bit system.
While low resolution data can suffer quantization error (described below), higher resolution does not always lead to better results. The higher the resolution of the ADC, the more memory is required to store converted data. Higher resolution ADCs also typically require a lower sampling rate. In circuits prone to noise, high resolution quantization may not provide accurate data in the least-significant bits of the result. It is therefore important to understand the limitations of circuit hardware when selecting the resolution of an ADC.
Quantization error refers to the difference between the actual and quantized voltage and is defined by (6.1.2).
\begin{equation} \textrm{error} = V_{quantized} - V_{actual}\tag{6.1.2} \end{equation}
Quantization error can be reduced by increasing the resolution of the ADC (as shown in Figureย 6.1.3), or by increasing the sample rate (not shown in Figureย 6.1.3).
Graphs depicting the signal voltage and quantization error for a 3-bit ADC (left) and 8-bit ADC (right). The quantization error decreases when the resolution of the ADC increases.
Figure 6.1.3. Quantized analog signals and associated quantization error for a 3-bit ADC (left) and an 8-bit ADC (right). The sample rate is 4โœ• per millisecond.
Other types of error are possible in analog to digital converters and may depend on the architecture of the ADC. These will typically be listed in an ADCโ€™s datasheet.

Subsection 6.1.3 Encoding

The encoding part of ADC comes when the sampled and quantized signal is then converted into a binary number. In hardware, this can be accomplished with a priority encoder.
The binary value stored by the ADC is given by (6.1.3), where \(V_{in}\) is the analog voltage input.
\begin{equation} \textrm{ADC result} = 2^n \times \left(\frac{V_{in}}{V_{ref}}\right)\tag{6.1.3} \end{equation}