13.4 ADC, DAC, and Sensor Interfacing
Temperature, pressure, light, and sound vary continuously, while a microprocessor stores finite binary numbers. An analog-to-digital converter (ADC) measures an input voltage and reports a code. A digital-to-analog converter (DAC) performs the opposite mapping, producing an analog level from a code. Neither device creates meaning by itself: circuits and software must relate voltage to the physical quantity.
See sampling, quantization, and aliasing
An -bit ADC has possible codes, from 0 through . For an ideal unipolar converter spanning 0 to reference voltage , a useful code-width estimate is
The ADC rounds each sampled voltage into one of these finite bins. This quantization makes the digital reconstruction stair-stepped even when the input changes smoothly. Increasing resolution reduces bin width, but it cannot repair an input that exceeds the reference range; such an input clips at an endpoint code.
An ADC also measures only at discrete times. A sample-and-hold circuit captures the input, conversion takes finite time, and an end-of-conversion or ready signal tells software when the code is valid. For a sine wave of frequency , a sampling rate above is the theoretical minimum needed to avoid one form of aliasing, where samples resemble a false lower-frequency signal. Practical systems sample faster and filter frequencies above the intended band before conversion.
The sampling scope exposes all three limits separately. Lower the resolution to enlarge the voltage steps, lower the sample rate until the plotted samples describe a false waveform, or lower the reference until peaks clip.
Calibrate a complete sensor-to-actuator chain
A sensor usually has gain and offset. Suppose a temperature sensor is intended to produce 10 mV per degree Celsius but also has a 40 mV offset. Treating voltage as temperature without calibration shifts every result. A two-point calibration measures two known physical inputs and fits
where is measured voltage and is the estimated physical quantity. Calibration can correct linear gain and offset error; it cannot recover information lost to clipping, insufficient resolution, excessive noise, or an inadequate sample rate.
A DAC maps a code back to a voltage. For an ideal -bit DAC whose maximum code reaches the reference,
Real ADC and DAC conventions can differ at the top endpoint, so a design must use the selected component's data sheet rather than mix denominators casually. The important observable chain is sensor quantity → voltage → ADC code → calibrated software value → control decision → DAC code → actuator voltage.
Interface design must also schedule conversions. Polling a ready flag is simple; an interrupt avoids waiting; DMA can collect a sample block with low CPU overhead. Those Chapter 12 and 13 mechanisms solve data movement, but the numeric result is trustworthy only when reference, range, resolution, timing, and calibration all agree.
The calibration studio lets you introduce sensor offset and noise, choose ADC resolution and reference, capture two calibration points, and drive a DAC-controlled fan. Incorrect configurations remain visible as clipping, quantization error, or a wrong physical estimate.
Chapter 13 connected time, bulk transfer, serial frames, and physical signals to the processor through explicit control, status, and data paths. Chapter 14 will integrate those paths with memory, interrupts, software, and verification into one complete system.