Skip to main content
DD-CAT IDE logoDD-CAT IDE

Article · Tech Insights

ADC Code to Voltage: Remember the 1 LSB Formula for Error-Free Sensor Calibration

Favorite

Starting from raw ADC code values printed over a serial port, this article explains the code-to-voltage conversion formula and the meaning of 1 LSB, demonstrates a sensor calibration conversion with an online calculator, and summarizes common pitfalls such as using the wrong denominator or reference voltage.

ShareWeiboXLinkedIn

Key points

The core formula for converting an ADC code value to voltage is V = code / 2^n × V_ref, where n is the ADC bit count and 2^n is the number of quantization levels; the reverse formula is code = V / V_ref × 2^n. For a 12-bit ADC with a 3.3 V reference, 1 LSB ≈ 0.806 mV, and for 16-bit with a 2.5 V reference it is about 0.038 mV; everyday conversions should use 2^n as the denominator, not 2^n-1. Common mistakes include treating the power supply voltage as the reference voltage, using 2^n-1 as the denominator, and ignoring reference voltage drift; before calibration, confirm the ADC bit count, measure the actual reference voltage with a multimeter, and verify that 1 LSB is smaller than the smallest voltage change to be measured. DD-CAT's ADC code-to-voltage calculator accepts bit count, reference voltage, and either code or voltage, and returns the converted result and 1 LSB resolution.

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:

V=code2n×VrefV = \frac{code}{2^{n}} \times V_{ref}

To solve for code:

code=VVref×2ncode = \frac{V}{V_{ref}} \times 2^{n}

Where nn is the ADC bit count and 2n2^n is the number of quantization levels; for 12 bits it is 4096. For everyday conversion, use 2n2^n as the denominator, not 2n−12^n-1; the two differ by exactly one LSB.

The definition of 1 LSB:

1 LSB=Vref2n1\ \text{LSB} = \frac{V_{ref}}{2^{n}}

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 2n−12^n-1 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.

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.

Get new articles by email

Enter your email — we notify you about new articles and releases (unsubscribe anytime).

Related reading

Tech Insights

学习泡妞

学习这件事和泡妞是一回事:为什么不想学、学不会、记不住,蒙卦和逻辑学一句话就点破,一切科学简单到只剩一个「咔嗒」声。用一条条对比的方式,把自学讲成泡妞,看完就忘不掉。

Tech Insights

童话版偏置电路:从电阻分压到 ΔV/R 型,把放大器的「待命点」钉住

放大器的本事全看「待命点」钉在哪:钉得偏,信号一大就削顶;钉得飘,电源一抖就全歪。这篇用斜坡上的木桶讲清偏置是什么,再把六代做法一代代推出来:电阻分压 → 二极管接法当小电阻 → 恒流源当无穷大电阻 → 自偏置四管环(为什么必然「要么死要么不定」)→ 源极垫电阻的 ΔV/R 型 → 大电流的 V/R 型。全篇一套 1.8 V / μCox=200 µA/V² 的数字算到底,附四种结构的电源敏感性对照曲线、五个最容易踩的坑和一屏速记卡。

Tech Insights

童话版电流镜:12 种常用接法一次枚举(附公式、速记卡与选型树)

电流镜只有一句话——共用一个栅压,电流按宽长比被抄过去;但"怎么抄得更稳"有十二条常见路。这篇按"比例 / 叠管子 / 加反馈 / 自己造"四类把常用电流镜全部枚举:单管、源极退化、Widlar、共源共栅、高摆幅、多重共源共栅、威尔逊、改进型威尔逊、增益提升 RGC、β 倍乘、有源电流镜、BJT 版,每种都给 R_out、V_out,min、管数和一句"什么时候用它";再配三代摆幅对照、1.8 V·200 µA·±1% 的选型算例、失配与版图规矩、五个实战场景、七条踩坑和一屏速记卡。