This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS1115: Single ended input

Part Number: ADS1115


Tool/software:

Hi,

is the way converting the adc value to adc_voltage value is correct using single ended input configuration for ads1115 ?. 

if(mux == 0x60) //AIN2 for gas flow rate sensor

{

uint8_t zero_output = 1; //Sensor zero output voltage

uint8_t fs_output = 5; //Sensor full scale output voltage

uint16_t sensor_fs = 1000; //Sensor full scale measurement range (sccm)

float pga = 6.144; //PGA gain setting

float sccm = 0;

//Convert adc_result to voltage equivalent

float adc_voltage;

adc_voltage = (adc_result*pga)/((1<<16)/2);

//Convert uint16_t adc_results to uint8_t sd_data[] array

sd_data[29] = (adc_result>>8) & 0xFF; //MSB

sd_data[30] = adc_result & 0xFF; //LSB

//Calculate flow rate

sccm = (((float)(adc_voltage - zero_output) / (fs_output - zero_output))*sensor_fs);

plot_data[11] = sccm;

 

return sccm;

}

Regards,

Harris

  • Hi Harris,

    The PGA setting represents the input voltage range, not the gain necessarily. I would refer to 6.144 as the full-scale range instead. 

    adc_voltage = (adc_result*pga)/((1<<16)/2);

    Here, I would avoid using shifts. I'm not exactly sure how it will be treated. You could add a definition above equal to 32680.0 (float), to ensure the end result is treated as a float. Also type casting everything to float explicitly is best.

    Occasionally, you might get negative values due to offset error, so it would be good to include cases for the negative values as well, say when the output of the sensor is close to ground.

    Regards,
    Joel