Analog-Digital: Conversion Examples

Suppose we had a digital resolution of 2 (n=2), a Vref+ of 4V, and a Vref- of 0V. What analog values would correspond to each digital input value? Let’s start by finding our digital and analog ranges. Since our digital resolution is 2, then n = 2 and thus our digital range is 2^2 = 4, keeping in mind that our lowest possible digital value is 0. As for the analog range, our upper bound is 4V and our lower bound is 0V, thus the analog range is 4 - 0 = 4. The LSB voltage, 1LSB, is the analog range divided by the digital range, which is 4/ 4 = 1. Now we can figure out the corresponding values between digital inputs and their analog outputs by using the digital-to-analog formula for different values of D. The below images show the conversion for the above scenario for both analog-to-digital and digital-to-analog conversion. 

1LSB  = (Vref+ - Vref-)/ (2^n) 

1LSB = (4 - 0)/ (2^2) = 4/4 = 1


D = (Rounded, ceiling or floor of ) ((Vanalog - Vref-)/ 1LSB)

D = (Rounded, ceiling or floor) ((Vanalog - 0)/ 1)

D = (Rounded, ceiling or floor of ) (Vanalog)

In this example: 

D = floor(Vanalog)

The output saturates when Vanalog > 3V




Vanalog = D * 1LSB + Vrerf-

Vanalog = D * 1 + 0

Vanalog = D

The below images show the conversions for Vref- = -3V, Vref+ = 3V and n=5.

1LSB  = (Vref+ - Vref-)/ (2^n) 

1LSB = (3 - -3)/ (2^5) = 6/32 


D = (Rounded, ceiling or floor of ) ((Vanalog - Vref-)/ 1LSB)

In this example:

D = floor ((Vanalog +3) * 32 / 6)

D = floor((Vanalog +3)/ 32)

The output saturates when the Vanalog > (3-6/32)






Vanalog = D * 1LSB + Vrerf-

Vanalog = D * 6/32 - 3


We created these images using a Matlab script. You can find the script at this link. If you do not have Matlab installed, you can create an account on https://octave-online.net/ . You can copy-paste the script, change vrefp, vrefn, and n and Run the script to see a variety of conversions.