How does a microcontroller, which operates exclusively with discrete digital values (1s and 0s), measure a continuous, real-world analog signal like the temperature from a sensor?
The bridge between the analog real world and the digital world of a microcontroller is a crucial mixed-signal circuit called an Analog-to-Digital Converter (ADC). Virtually all modern microcontrollers have one or more ADCs built directly into the chip as a key peripheral.
The process involves three main concepts: Sampling, Quantization, and Encoding.
1. The Fundamental Problem: Analog vs. Digital
2. The Solution: The Analog-to-Digital Converter (ADC)
The ADC's job is to convert the analog voltage from the sensor into a digital number that the microcontroller can read and process. Here’s how it works:
Step 1: Sampling
The ADC doesn't look at the analog signal continuously. Instead, it takes instantaneous "snapshots" of the voltage at regular, very fast intervals. This is called sampling. For a slow-changing signal like temperature, this is more than adequate to get an accurate reading.
Step 2: Quantization (The Core of the Conversion)
This is the most important step. The ADC maps the sampled analog voltage to a discrete integer value. To do this, it uses two key parameters:
The ADC compares the input analog voltage to these steps and finds the closest one.
Example:
Imagine a common microcontroller (like an Arduino Uno) with a 10-bit ADC and a Reference Voltage (Vref) of 5V.
5V / 1024 steps ≈ 4.88 mV/step
.Digital Value = (Input Voltage / Vref) × (Number of Steps)
Digital Value = (2.5V / 5.0V) × 1024 = 512
Step 3: Encoding
The resulting integer (512 in our example) is then encoded into its binary representation (1000000000
in binary) and stored in a special memory location inside the microcontroller called an ADC Data Register.
3. The Microcontroller Application: Putting It All Together
Now the microcontroller's software takes over:
Voltage = (Digital Value / 1024) × Vref
Voltage = (512 / 1024) × 5V = 2.5V
Temperature = Voltage / 0.010 V/°C = 2.5V / 0.010 = 250°C
(This is just an example formula).In summary: The ADC acts as a translator. It takes a continuous analog voltage, measures it against a known reference, assigns it the closest discrete digital number based on its resolution, and hands that number to the microcontroller's CPU. The CPU then uses software to turn that raw number into a meaningful measurement like temperature, allowing a purely digital device to sense and react to the analog world.