Library for the ADS1015 and ADS1115 ADCS
Fork of ADS1015 by
Diff: Adafruit_ADS1015.cpp
- Revision:
- 15:e659b715ed89
- Parent:
- 14:e8dd6dcf64e9
- Child:
- 18:4b4e3446cdd4
--- a/Adafruit_ADS1015.cpp Thu May 24 08:53:16 2018 +0000 +++ b/Adafruit_ADS1015.cpp Thu Jun 21 11:33:48 2018 +0000 @@ -251,6 +251,68 @@ return (int16_t)res; } } +int16_t * Adafruit_ADS1015::readADC_Differential_DoubleEnded(){ + + uint16_t temp_res; + static int16_t results[2]; + + uint16_t config = ADS1015_REG_CONFIG_CQUE_NONE | // Disable the comparator (default val) + ADS1015_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val) + ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val) + ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val) + ADS1015_REG_CONFIG_DR_3300SPS | // 1600(ADS1015) or 250(ADS1115) samples per second (default) + ADS1015_REG_CONFIG_MODE_SINGLE; // Single-shot mode (default) + + // Set PGA/voltage range + config |= m_gain; + + // Set channels + config |= ADS1015_REG_CONFIG_MUX_DIFF_0_3; // AIN0 = P, AIN1 = N + + // Set 'start single-conversion' bit + config |= ADS1015_REG_CONFIG_OS_SINGLE; + +// // Read the first +// temp_res = readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift; +// +// if (m_bitShift != 0) { +// // Shift 12-bit results right 4 bits for the ADS1015, +// // making sure we keep the sign bit intact +// if (temp_res > 0x07FF) { +// // negative number - extend the sign to 16th bit +// temp_res |= 0xF000; +// } +// } +// results[0] = temp_res; + + + // Write config register to the ADC + writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config); + + // Wait for the conversion to complete + wait_us(m_conversionDelay); + + // Read the conversion results + temp_res = readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift; + + if (m_bitShift != 0) { + // Shift 12-bit results right 4 bits for the ADS1015, + // making sure we keep the sign bit intact + if (temp_res > 0x07FF) { + // negative number - extend the sign to 16th bit + temp_res |= 0xF000; + } + } + results[1] |= (int16_t) temp_res; + + //config |= ADS1015_REG_CONFIG_MUX_DIFF_1_3; +// +// // Write config register to the ADC +// writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config); + + return results; +} + /**************************************************************************/ /*! @brief Sets up the comparator to operate in basic mode, causing the @@ -308,7 +370,7 @@ int16_t Adafruit_ADS1015::getLastConversionResults() { // Wait for the conversion to complete - wait_ms(m_conversionDelay); + wait_us(m_conversionDelay); // Read the conversion results uint16_t res = readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;