Electronics & Circuits · Study deck

ADC and DAC: Conversion Calculations

An ADC turns a voltage into a digital count.

Voltage Vera is your guide for this deck.

analogdigitalesp32
Voltage Vera, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Calculate ADC Output: Compute digital values from analog voltage inputs using the ADC conversion formula
  • Select Reference Voltages: Evaluate and match Vref to sensor output ranges for maximum resolution
  • Quantify Quantization Error: Derive measurement precision limits across different ADC resolutions
  • Determine Nyquist Sampling Rates: Compute minimum and practical sampling frequencies for specific signal types
iotclass.org

Major section

Start Simple

The test engineer must show how one known input becomes both outputs without hiding a reference value, scale factor, unit change, or rounding choice.

  • Reverse the calculation to see whether the reported value can recover the original within the stated limit.
  • A distant chart may show the result, but it cannot restore resolution lost at conversion.
  • This opening does not cover every converter design.
iotclass.org

Major section

Phoebe's Field Notes: Where the Converter Numbers Come From

The mathematical gist: A 10-bit, 3.3 V ADC has q=Vref/210=3.22q=V_{ref}/2^{10}=3.22q=Vref​/210=3.22 mV.

  • At 1.65 V, the chapter's endpoint rule gives D=⌊(1.65/3.3)1023⌋=511D=\lfloor(1.65/3.3)1023\rfloor=511D=⌊(1.65/3.3)1023⌋=511, reconstructing 1.648 V within half an LSB.

The same bit depth sets an ideal 62.0 dB SNR, while 8 kHz sampling places Nyquist at 4 kHz and folds a 20 kHz tone to that band edge.

iotclass.org

Major section

ADC Conversion Formula

The visual is specifically about aDC conversion showing how continuous analog voltage is sampled and quantized into discrete digital steps.

  • These visible labels explain aDC conversion showing how continuous analog voltage is sampled and quantized into discrete digital steps.
  • They keep adc conversion formula tied to evidence that can be inspected on the schematic, part, or trace.
Temperature-versus-resistance graph plots a linear sensor response labeled T = R/140; it supplies a sensor relationship for the ADC worked example, not the conversion steps.
Temperature-versus-resistance graph plots a linear sensor response labeled T = R/140; it supplies a sensor relationship for the ADC worked example, not the conversion steps.
iotclass.org

Major section

Quantization Error Example

Quantization error is the inherent inaccuracy introduced when converting continuous analog signals to discrete digital values.

  • Where LSB (Least Significant Bit) is the smallest voltage change the ADC can detect.
  • Under the floor rule above, 1.650 V gives code 511, while 1.653 V gives code 512.
  • Effective bits increase by log2(N)/2.
iotclass.org

Major section

ESP32 Soil Moisture Example

Scenario: A smart irrigation system uses a capacitive soil moisture sensor that outputs 1.2V (dry) to 2.8V (saturated).

  • You need to determine optimal ADC configuration on an ESP32 to detect 1% moisture changes for water-efficient farming.
  • Key Insight: Proper attenuation selection is critical.
  • Using 0 dB attenuation (0-1.1V range) would clip the signal, while 11 dB provides headroom.
iotclass.org

Major section

Ultrasonic Distance Example

Scenario: An autonomous robot uses an HC-SR04 ultrasonic sensor for obstacle detection.

  • The echo pulse width (10us to 25 ms) must be measured accurately.
  • You need to determine if ADC-based measurement or timer-based capture is appropriate.
  • Key Insight: ADCs are for converting analog voltage levels to digital values.
iotclass.org

Major section

For Kids: Meet the Sensor Squad!

Math helps the Sensor Squad turn real-world measurements into exact numbers!

  • Temperature Terry was measuring the temperature of a fish tank. "It is 25 degrees Celsius!
  • ADC Andy looked at the signal. "Okay, I need to turn that into a number Max can understand.
  • One quarter of 1023 is about 255.

Key terms

So 0.250 volts
So 0.250 volts is one quarter of the way.
iotclass.org

Major section

For Kids: Meet the Sensor Squad! (continued)

the microcontroller was curious. "How do you figure out which step number matches 0.250 volts?".

  • So 0.250 volts is one quarter of the way.
  • So I tell Max: the reading is 255!".
  • the LED wanted to know more. "And how does Max turn 255 back into a temperature?".
iotclass.org

Major section

For Kids: Meet the Sensor Squad! (continued)

That gives me about 25 degrees -- exactly what Sammy measured!".

  • the battery chimed in. "But what if you only had 256 steps instead of 1024?".
  • Andy nodded. "Then each step would be a bigger jump -- about 0.4 degrees instead of 0.1 degrees.
  • I would be less precise.
iotclass.org

Major section

ADC Input Impedance Pitfall

The upper path connects a weak source directly; the lower path inserts a buffer.

  • The red cross marks the direct path, whose reading may be biased when the converter samples.
  • In the lower path the added amplifier drives the converter input so it can settle.
  • No 5–10% error can be inferred without acquisition timing.
iotclass.org

Major section

ADC Input Impedance Pitfall (continued)

The high-resistance source may give an inaccurate reading if the ADC input does not settle during acquisition.

  • The divider example below shows why source resistance matters even when the steady voltage looks right.
  • The ESP32 ADC has an internal sample-and-hold capacitor that draws charging current during conversion.
  • Acts as local charge reservoir.
iotclass.org

Major section

ADC Input Impedance Pitfall (continued)

A 2 kΩ upper / 1 kΩ lower divider gives about 1.67 V from 5 V and 667 Ω source resistance.

  • The Error: You use a 200 kΩ upper and 100 kΩ lower divider to bring a 5 V sensor output to about 1.67 V for an ESP32 ADC.
  • High-impedance sources (like voltage dividers with large resistors) may not settle in the available acquisition time, biasing the reading toward a prior sample voltage when acquisition is too short.
  • Dependence on the previous sample or acquisition time can reveal settling error; a consistently low value alone does not identify its cause.
iotclass.org

Deck summary

Key takeaways

The test engineer must show how one known input becomes both outputs without hiding a reference value, scale factor, unit change, or rounding choice.

  • The mathematical gist: A 10-bit, 3.3 V ADC has q=Vref/210=3.22q=V_{ref}/2^{10}=3.22q=Vref​/210=3.22 mV.
  • The visual is specifically about aDC conversion showing how continuous analog voltage is sampled and quantized into discrete digital steps.
  • Quantization error is the inherent inaccuracy introduced when converting continuous analog signals to discrete digital values.
  • Scenario: A smart irrigation system uses a capacitive soil moisture sensor that outputs 1.2V (dry) to 2.8V (saturated).
iotclass.org

Retrieval practice

Recall check 1 of 5

Voltage Vera says: answer from memory, then check your reasoning.

Q1A 10-bit ADC has a 5V reference voltage. What is the voltage resolution (step size)?

AAbout 4.88 mV for each of 1,024 possible ADC steps
BAbout 0.5 mV for each of 1,024 possible ADC steps
CAbout 10 mV for each of 1,024 possible ADC steps
DAbout 50 mV for each of 1,024 possible ADC steps
Show answer

Answer: A The ideal code step is V_ref / 2^bits = 5V / 1024 = 0.00488V = 4.88mV. Actual detectable changes also depend on input noise and converter error.

iotclass.org

Retrieval practice

Recall check 2 of 5

Voltage Vera says: answer from memory, then check your reasoning.

Q2A sensor signal reaches three kilohertz. What is the theoretical minimum sample rate before allowing filter margin?

AThree kilohertz, equal to the signal's highest frequency
BSix kilohertz, twice the highest signal frequency
CFour kilohertz, below twice the highest signal frequency
DTwelve kilohertz, with extra filter margin as the minimum
Show answer

Answer: B Sampling must be at least twice the highest signal frequency.

iotclass.org

Retrieval practice

Recall check 3 of 5

Voltage Vera says: answer from memory, then check your reasoning.

Q3A dimmer should look evenly spaced to a person. How should its lookup table map desired brightness to output code?

AReverse the table so higher brightness gets a lower code.
BKeep one fixed output code for all settings.
CApply a gamma curve before storing each output code.
DCopy each desired percentage directly into a linear code.
Show answer

Answer: C The curve compensates for nonlinear brightness perception.

iotclass.org

Retrieval practice

Recall check 4 of 5

Voltage Vera says: answer from memory, then check your reasoning.

Q4A 12-bit ADC with Vref = 3.3V measures 2.0V. What is the digital output?

A2000
B1241
C606
D2481
Show answer

Answer: D Output = floor((2.0V / 3.3V) x (2^12 - 1)) = floor((2.0 / 3.3) x 4095) = floor(2481.8) = 2481. The 12-bit ADC divides the 0-3.3V range into 4096 steps (0-4095).

iotclass.org

Retrieval practice

Recall check 5 of 5

Voltage Vera says: answer from memory, then check your reasoning.

Q5An 8-bit DAC with Vref = 3.3V receives digital input 192. What is the output voltage?

A1.65 V
B3.10 V
C2.95 V
D2.48 V
Show answer

Answer: D V_out = V_ref x (Digital_Input / (2^bits - 1)) = 3.3V x (192 / 255) = 3.3V x 0.753 = 2.48V. The 8-bit DAC can output 256 discrete voltage levels (0-255), and we scale the digital value proportionally.

iotclass.org

Print reference

Answers 1 of 2

Answer key.

  1. A · The ideal code step is V_ref / 2^bits = 5V / 1024 = 0.00488V = 4.88mV. Actual detectable changes also depend on input noise and converter error.
  2. B · Sampling must be at least twice the highest signal frequency.
  3. C · The curve compensates for nonlinear brightness perception.
  4. D · Output = floor((2.0V / 3.3V) x (2^12 - 1)) = floor((2.0 / 3.3) x 4095) = floor(2481.8) = 2481. The 12-bit ADC divides the 0-3.3V range into 4096 steps (0-4095).
iotclass.org

Print reference

Answers 2 of 2

Answer key.

  1. D · V_out = V_ref x (Digital_Input / (2^bits - 1)) = 3.3V x (192 / 255) = 3.3V x 0.753 = 2.48V. The 8-bit DAC can output 256 discrete voltage levels (0-255), and we scale the digital value proportionally.
iotclass.org