Example #1
0
        private double CodeToVoltage(int adc_code, double vref, Ltc2305ConfigBits uni_bipolar)
        {
            double voltage;
            double sign = 1;

            if (uni_bipolar == Ltc2305ConfigBits.UnipolarMode)
            {
                voltage = (adc_code >> 4) / (Math.Pow(2, 12) - 1);    //! 2) This calculates the input as a fraction of the reference voltage (dimensionless)
            }
            else
            {
                vref = vref / 2;
                if ((adc_code & 0x8000) == 0x8000)      //adc code is < 0
                {
                    adc_code = (adc_code ^ 0xFFFF) + 1; //! Convert ADC code from two's complement to binary
                    sign     = -1;
                }
                voltage = sign * (float)adc_code;
                voltage = voltage / (Math.Pow(2, 15) - 1); //! 2) This calculates the input as a fraction of the reference voltage (dimensionless)
            }
            voltage = voltage * vref;                      //! 3) Multiply fraction by Vref to get the actual voltage at the input (in volts)


            return(voltage);
        }
        private double CodeToVoltage(int adc_code, double vref, Ltc2305ConfigBits uni_bipolar)
        {
            double voltage;
            double sign = 1;

            if (uni_bipolar == Ltc2305ConfigBits.UnipolarMode)
            {
                voltage = (adc_code >> 4) / (Math.Pow(2, 12) - 1);    //! 2) This calculates the input as a fraction of the reference voltage (dimensionless)
            }
            else
            {
                vref = vref / 2;
                if ((adc_code & 0x8000) == 0x8000)	//adc code is < 0
                {
                    adc_code = (adc_code ^ 0xFFFF) + 1;                                    //! Convert ADC code from two's complement to binary
                    sign = -1;
                }
                voltage = sign * (float)adc_code;
                voltage = voltage / (Math.Pow(2, 15) - 1);    //! 2) This calculates the input as a fraction of the reference voltage (dimensionless)
            }
            voltage = voltage * vref;           //! 3) Multiply fraction by Vref to get the actual voltage at the input (in volts)


            return (voltage);
        }