Convert Raw value into voltage in an ADC

Hi,

An ADC (ADS1015 with n=12 bit resolution) is connected to 5V DC power supply. So its V_ref=5V.
However, if I set gain=16, then full-scale-range = +/-0.256V i.e peak to peak voltage= V_pp=2*0.256=0.512V (as given in data sheet Pg 10, Table 3: Reference https://cdn-shop.adafruit.com/datasheets/ads1015.pdf )

In such a scenario, which formula out of the two mentioned below should be used to convert raw data from ADC into equivalent voltage:

(1) V_in = (Raw data from ADC) * (V_ref/2^n) = (Raw data from ADC) * (5/4096)

(2) V_in = (Raw data from ADC) * (V_pp/2^n) = (Raw data from ADC) * (0.512/4096)

Also, in the above two formula, where do we substitute "gain=16" factor?

If somebody could please explain this I would be very much appreciative.

When you say equivalent voltage are you looking at the RMS equivalent of an alternating signal ?
I’m unsure what your formulas mean , but the gain factor is incorporated in the formulas as the the .512 or 5 representing the full scale value of the A/D. Your A/d will provide instantaneous values of the input waveform , you need to be sampling at a high enough rate to be able to have captured a good representation of the input waveform so you can calculate the “ rms” value from the individual samples .( finding pk to pk if it’s a sine wave)

If the signal is a undistorted sine wave then you can relate the peak voltage to the rms voltage .
http://www.learningaboutelectronics.com/Articles/Voltage-rms-calculator.php

It might help to state what you project is to do , to use a 12bit a/d and get good results your input signal conditioning needs to be of similar precision.

First, the datasheet you linked to (from the Adafruit site) is an old issue. Here’s a more recent one, I think the latest, direct from TI.

The gain is just a mode setting for the device - you don’t need to factor the 16 in anywhere. With that setting, the input range is +/- 0.256V (i.e. a span of 0.512V). This is measured using the 12 bits of the ADC, so each bit is “worth” (0.512 / 212) = (0.512/4096) = 0.125mV.

The number out of the device is in twos-compliment format. The maximum positive output number will be 2047, when AINp is greater than AINn by (2047 * 0.000125) = (0.256 - 0.000125)V. The maximum negative output is -2048, when AINp is less than AINn by 0.256V.

Note that neither AINp nor AINn should go below GND (7.3 Recommended Operating Conditions - in datasheet, p8) .