1. Why Raw Serial Code Values Kept Making Me Miscalculate
When calibrating sensors, the most time-consuming part for me is usually not acquiring data, but mentally converting the raw ADC code values printed over serial every time I see them. With a 12-bit ADC and a 3.3 V reference, reading 2047 gives 2047 / 4096 × 3.3 ≈ 1.65 V, and that is not hard; what makes it difficult is that field parameters keep changing: ADCs may be 8-bit, 10-bit, 12-bit, or 16-bit, and the reference voltage may be 2.5 V, 3.3 V, or 5 V, sometimes an internal reference. The moment I get busy, I would remember the denominator as 4095, or treat the 5 V power supply as the reference voltage, and the calibration result would drift.
2. Two Formulas and 1 LSB
The core formula is just one:
To solve for code:
Where is the ADC bit count and is the number of quantization levels; for 12 bits it is 4096. For everyday conversion, use as the denominator, not ; the two differ by exactly one LSB.
The definition of 1 LSB:
For a 12-bit ADC with a 3.3 V reference, 1 LSB ≈ 0.806 mV; for a 16-bit ADC with a 2.5 V reference, 1 LSB ≈ 0.038 mV. When evaluating sensor noise, I multiply the noise code value by 1 LSB to convert it to voltage, then compare it with the noise density in the datasheet; that is much more intuitive than reading raw code values directly.
3. Run a Conversion with the Online Calculator
Manual calculation is good for verification, but for daily conversions I use DD-CAT's ADC code-to-voltage calculator. Enter three values—ADC bit count, reference voltage, and code value (or voltage)—and it gives both the converted result and the 1 LSB resolution.
Here is a recent calibration example: the STM32's built-in 12-bit ADC, VREF measured as 3.29 V with a multimeter, and the serial output showed code = 2500. In the tool, select 12-bit, enter a 3.29 V reference, and input 2500 as the code value; it returns about 2.009 V with 1 LSB ≈ 0.803 mV. Then I align the sensor's 2.0 V calibration point, collect two more points for linear fitting, and any zero or gain deviation becomes obvious immediately.
4. Selection Takeaways and Common Mistakes
I have hit three pitfalls, and I am writing them down as reminders:
- Treating the power supply voltage as the reference voltage: the MCU is powered from 5 V, but the ADC uses an internal 2.5 V reference, so calculating with 5 V doubles the result.
- Using as the denominator: for 12 bits, using 4095 creates a one-LSB error; in small-signal scenarios, this error is comparable to the sensor's resolution and cannot be ignored.
- The reference voltage itself drifts: an LDO rated at 3.3 V may actually output only 3.28 V; a 1% deviation at 12 bits amounts to dozens of LSBs.
My selection conclusion is: for common combinations such as 8/10/12-bit ADCs with a 3.3 V reference, mental math or lookup tables are sufficient; for 16-bit and higher, or when the reference is not a round number, letting a tool handle the conversion is more reliable. In terms of workflow, first confirm the ADC bit count, then measure the reference voltage with a multimeter (do not trust the nominal value), and finally verify that 1 LSB is smaller than the smallest voltage change you need to measure. Only proceed with calibration after that condition is met.
5. Related Tools
An ADC front end is rarely isolated: before sampling, I usually pass the signal through an RC low-pass filter (the site's RC low-pass calculator) to suppress glitches and reduce code-value jitter. If the signal amplitude exceeds the reference range, I add a resistor divider or op-amp attenuation ahead of the ADC. In this attenuate/filter first, then quantize chain, working out each step separately before combining them makes troubleshooting much faster later. Now that code conversion and filter parameters can all be handled by the site's own tools, I deleted the pile of Excel formula sheets I used to keep.