readADC_Differential_0_1()のconfigの値の設定を readADC_Differential_2_3()のconfigの値と同じにしました

Fork of ads1115_test by Gaku Matsumoto

Committer:
PQUTO
Date:
Wed Feb 22 18:22:42 2017 +0000
Revision:
2:68c4863a39cd
Parent:
1:2e07c1aa1375
readADC_Differential_0_1()?config??????readADC_Differential_2_3()?config?????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gaku0606 0:387c3e3b28f1 1 /**************************************************************************/
Gaku0606 0:387c3e3b28f1 2 /*!
Gaku0606 0:387c3e3b28f1 3 @file Adafruit_ADS1015.h
Gaku0606 0:387c3e3b28f1 4 @author K. Townsend (Adafruit Industries)
Gaku0606 0:387c3e3b28f1 5 @license BSD (see LICENSE.txt)
Gaku0606 0:387c3e3b28f1 6
Gaku0606 0:387c3e3b28f1 7 Ported to mbed by Arve Seljebu - arve0.github.io
Gaku0606 0:387c3e3b28f1 8
Gaku0606 0:387c3e3b28f1 9 This is a library for the Adafruit ADS1015 breakout board
Gaku0606 0:387c3e3b28f1 10 ----> https://www.adafruit.com/products/1083
Gaku0606 0:387c3e3b28f1 11
Gaku0606 0:387c3e3b28f1 12 Adafruit invests time and resources providing this open source code,
Gaku0606 0:387c3e3b28f1 13 please support Adafruit and open-source hardware by purchasing
Gaku0606 0:387c3e3b28f1 14 products from Adafruit!
Gaku0606 0:387c3e3b28f1 15
Gaku0606 0:387c3e3b28f1 16 @section HISTORY
Gaku0606 0:387c3e3b28f1 17
Gaku0606 0:387c3e3b28f1 18 v1.0 - First release
Gaku0606 0:387c3e3b28f1 19 v1.1 - Added ADS1115 support - W. Earl
Gaku0606 0:387c3e3b28f1 20 v1.1.1 - Ported to mbed - Arve Seljebu
Gaku0606 0:387c3e3b28f1 21 */
Gaku0606 0:387c3e3b28f1 22 /**************************************************************************/
Gaku0606 0:387c3e3b28f1 23
Gaku0606 0:387c3e3b28f1 24 #include <mbed.h>
Gaku0606 0:387c3e3b28f1 25
Gaku0606 0:387c3e3b28f1 26 /*=========================================================================
Gaku0606 0:387c3e3b28f1 27 I2C ADDRESS/BITS
Gaku0606 0:387c3e3b28f1 28 -----------------------------------------------------------------------*/
Gaku0606 0:387c3e3b28f1 29 #define ADS1015_ADDRESS (0x48) // 1001 000 (ADDR = GND)
Gaku0606 0:387c3e3b28f1 30 /*=========================================================================*/
Gaku0606 0:387c3e3b28f1 31
Gaku0606 0:387c3e3b28f1 32 /*=========================================================================
Gaku0606 0:387c3e3b28f1 33 CONVERSION DELAY (in mS)
Gaku0606 0:387c3e3b28f1 34 -----------------------------------------------------------------------*/
Gaku0606 0:387c3e3b28f1 35 #define ADS1015_CONVERSIONDELAY (1)
Gaku0606 1:2e07c1aa1375 36 #define ADS1115_CONVERSIONDELAY (1)
Gaku0606 0:387c3e3b28f1 37 /*=========================================================================*/
Gaku0606 0:387c3e3b28f1 38
Gaku0606 0:387c3e3b28f1 39 /*=========================================================================
Gaku0606 0:387c3e3b28f1 40 POINTER REGISTER
Gaku0606 0:387c3e3b28f1 41 -----------------------------------------------------------------------*/
Gaku0606 0:387c3e3b28f1 42 #define ADS1015_REG_POINTER_MASK (0x03)
Gaku0606 0:387c3e3b28f1 43 #define ADS1015_REG_POINTER_CONVERT (0x00)
Gaku0606 0:387c3e3b28f1 44 #define ADS1015_REG_POINTER_CONFIG (0x01)
Gaku0606 0:387c3e3b28f1 45 #define ADS1015_REG_POINTER_LOWTHRESH (0x02)
Gaku0606 0:387c3e3b28f1 46 #define ADS1015_REG_POINTER_HITHRESH (0x03)
Gaku0606 0:387c3e3b28f1 47 /*=========================================================================*/
Gaku0606 0:387c3e3b28f1 48
Gaku0606 0:387c3e3b28f1 49 /*=========================================================================
Gaku0606 0:387c3e3b28f1 50 CONFIG REGISTER
Gaku0606 0:387c3e3b28f1 51 -----------------------------------------------------------------------*/
Gaku0606 0:387c3e3b28f1 52 #define ADS1015_REG_CONFIG_OS_MASK (0x8000)
Gaku0606 0:387c3e3b28f1 53 #define ADS1015_REG_CONFIG_OS_SINGLE (0x8000) // Write: Set to start a single-conversion
Gaku0606 0:387c3e3b28f1 54 #define ADS1015_REG_CONFIG_OS_BUSY (0x0000) // Read: Bit = 0 when conversion is in progress
Gaku0606 0:387c3e3b28f1 55 #define ADS1015_REG_CONFIG_OS_NOTBUSY (0x8000) // Read: Bit = 1 when device is not performing a conversion
Gaku0606 0:387c3e3b28f1 56
Gaku0606 0:387c3e3b28f1 57 #define ADS1015_REG_CONFIG_MUX_MASK (0x7000)
Gaku0606 0:387c3e3b28f1 58 #define ADS1015_REG_CONFIG_MUX_DIFF_0_1 (0x0000) // Differential P = AIN0, N = AIN1 (default)
Gaku0606 0:387c3e3b28f1 59 #define ADS1015_REG_CONFIG_MUX_DIFF_0_3 (0x1000) // Differential P = AIN0, N = AIN3
Gaku0606 0:387c3e3b28f1 60 #define ADS1015_REG_CONFIG_MUX_DIFF_1_3 (0x2000) // Differential P = AIN1, N = AIN3
Gaku0606 0:387c3e3b28f1 61 #define ADS1015_REG_CONFIG_MUX_DIFF_2_3 (0x3000) // Differential P = AIN2, N = AIN3
Gaku0606 0:387c3e3b28f1 62 #define ADS1015_REG_CONFIG_MUX_SINGLE_0 (0x4000) // Single-ended AIN0
Gaku0606 0:387c3e3b28f1 63 #define ADS1015_REG_CONFIG_MUX_SINGLE_1 (0x5000) // Single-ended AIN1
Gaku0606 0:387c3e3b28f1 64 #define ADS1015_REG_CONFIG_MUX_SINGLE_2 (0x6000) // Single-ended AIN2
Gaku0606 0:387c3e3b28f1 65 #define ADS1015_REG_CONFIG_MUX_SINGLE_3 (0x7000) // Single-ended AIN3
Gaku0606 0:387c3e3b28f1 66
Gaku0606 0:387c3e3b28f1 67 #define ADS1015_REG_CONFIG_PGA_MASK (0x0E00)
Gaku0606 0:387c3e3b28f1 68 #define ADS1015_REG_CONFIG_PGA_6_144V (0x0000) // +/-6.144V range = Gain 2/3
Gaku0606 0:387c3e3b28f1 69 #define ADS1015_REG_CONFIG_PGA_4_096V (0x0200) // +/-4.096V range = Gain 1
Gaku0606 0:387c3e3b28f1 70 #define ADS1015_REG_CONFIG_PGA_2_048V (0x0400) // +/-2.048V range = Gain 2 (default)
Gaku0606 0:387c3e3b28f1 71 #define ADS1015_REG_CONFIG_PGA_1_024V (0x0600) // +/-1.024V range = Gain 4
Gaku0606 0:387c3e3b28f1 72 #define ADS1015_REG_CONFIG_PGA_0_512V (0x0800) // +/-0.512V range = Gain 8
Gaku0606 0:387c3e3b28f1 73 #define ADS1015_REG_CONFIG_PGA_0_256V (0x0A00) // +/-0.256V range = Gain 16
Gaku0606 0:387c3e3b28f1 74
Gaku0606 0:387c3e3b28f1 75 #define ADS1015_REG_CONFIG_MODE_MASK (0x0100)
Gaku0606 0:387c3e3b28f1 76 #define ADS1015_REG_CONFIG_MODE_CONTIN (0x0000) // Continuous conversion mode
Gaku0606 0:387c3e3b28f1 77 #define ADS1015_REG_CONFIG_MODE_SINGLE (0x0100) // Power-down single-shot mode (default)
Gaku0606 0:387c3e3b28f1 78
Gaku0606 0:387c3e3b28f1 79 #define ADS1015_REG_CONFIG_DR_MASK (0x00E0)
Gaku0606 0:387c3e3b28f1 80 #define ADS1015_REG_CONFIG_DR_128SPS (0x0000) // 128 samples per second - ADS1115 8SPS
Gaku0606 0:387c3e3b28f1 81 #define ADS1015_REG_CONFIG_DR_250SPS (0x0020) // 250 samples per second - ADS1115 16SPS
Gaku0606 0:387c3e3b28f1 82 #define ADS1015_REG_CONFIG_DR_490SPS (0x0040) // 490 samples per second - ADS1115 32SPS
Gaku0606 0:387c3e3b28f1 83 #define ADS1015_REG_CONFIG_DR_920SPS (0x0060) // 920 samples per second - ADS1115 64SPS
Gaku0606 0:387c3e3b28f1 84 #define ADS1015_REG_CONFIG_DR_1600SPS (0x0080) // 1600 samples per second - ADS1115 250SPS (default)
Gaku0606 0:387c3e3b28f1 85 #define ADS1015_REG_CONFIG_DR_2400SPS (0x00A0) // 2400 samples per second - ADS1115 475SPS
Gaku0606 0:387c3e3b28f1 86 #define ADS1015_REG_CONFIG_DR_3300SPS (0x00C0) // 3300 samples per second - ADS1115 860SPS
Gaku0606 0:387c3e3b28f1 87
Gaku0606 0:387c3e3b28f1 88 #define ADS1015_REG_CONFIG_CMODE_MASK (0x0010)
Gaku0606 0:387c3e3b28f1 89 #define ADS1015_REG_CONFIG_CMODE_TRAD (0x0000) // Traditional comparator with hysteresis (default)
Gaku0606 0:387c3e3b28f1 90 #define ADS1015_REG_CONFIG_CMODE_WINDOW (0x0010) // Window comparator
Gaku0606 0:387c3e3b28f1 91
Gaku0606 0:387c3e3b28f1 92 #define ADS1015_REG_CONFIG_CPOL_MASK (0x0008)
Gaku0606 0:387c3e3b28f1 93 #define ADS1015_REG_CONFIG_CPOL_ACTVLOW (0x0000) // ALERT/RDY pin is low when active (default)
Gaku0606 0:387c3e3b28f1 94 #define ADS1015_REG_CONFIG_CPOL_ACTVHI (0x0008) // ALERT/RDY pin is high when active
Gaku0606 0:387c3e3b28f1 95
Gaku0606 0:387c3e3b28f1 96 #define ADS1015_REG_CONFIG_CLAT_MASK (0x0004) // Determines if ALERT/RDY pin latches once asserted
Gaku0606 0:387c3e3b28f1 97 #define ADS1015_REG_CONFIG_CLAT_NONLAT (0x0000) // Non-latching comparator (default)
Gaku0606 0:387c3e3b28f1 98 #define ADS1015_REG_CONFIG_CLAT_LATCH (0x0004) // Latching comparator
Gaku0606 0:387c3e3b28f1 99
Gaku0606 0:387c3e3b28f1 100 #define ADS1015_REG_CONFIG_CQUE_MASK (0x0003)
Gaku0606 0:387c3e3b28f1 101 #define ADS1015_REG_CONFIG_CQUE_1CONV (0x0000) // Assert ALERT/RDY after one conversions
Gaku0606 0:387c3e3b28f1 102 #define ADS1015_REG_CONFIG_CQUE_2CONV (0x0001) // Assert ALERT/RDY after two conversions
Gaku0606 0:387c3e3b28f1 103 #define ADS1015_REG_CONFIG_CQUE_4CONV (0x0002) // Assert ALERT/RDY after four conversions
Gaku0606 0:387c3e3b28f1 104 #define ADS1015_REG_CONFIG_CQUE_NONE (0x0003) // Disable the comparator and put ALERT/RDY in high state (default)
Gaku0606 0:387c3e3b28f1 105
Gaku0606 0:387c3e3b28f1 106 #define COMP_QUE (0b0000000000000011)
Gaku0606 0:387c3e3b28f1 107 #define COMP_LAT (0b0000000000000100)
Gaku0606 0:387c3e3b28f1 108 #define COMP_POL (0b0000000000001000)
Gaku0606 0:387c3e3b28f1 109 #define COMP_MODE (0b0000000000000000)
Gaku0606 0:387c3e3b28f1 110 #define DR (0b0000000011100000)//860sps
Gaku0606 0:387c3e3b28f1 111 #define MODE (0b0000000000000000)//連続
Gaku0606 0:387c3e3b28f1 112 #define PGA (0b0000001000000000)//4.096
Gaku0606 0:387c3e3b28f1 113 #define MUX (0b0000000000000000)//0 vs 1
Gaku0606 0:387c3e3b28f1 114 // 0b0000001011101111
Gaku0606 0:387c3e3b28f1 115 /*=========================================================================*/
Gaku0606 0:387c3e3b28f1 116
Gaku0606 0:387c3e3b28f1 117
Gaku0606 0:387c3e3b28f1 118 typedef enum {
Gaku0606 0:387c3e3b28f1 119 GAIN_TWOTHIRDS = ADS1015_REG_CONFIG_PGA_6_144V,
Gaku0606 0:387c3e3b28f1 120 GAIN_ONE = ADS1015_REG_CONFIG_PGA_4_096V,
Gaku0606 0:387c3e3b28f1 121 GAIN_TWO = ADS1015_REG_CONFIG_PGA_2_048V,
Gaku0606 0:387c3e3b28f1 122 GAIN_FOUR = ADS1015_REG_CONFIG_PGA_1_024V,
Gaku0606 0:387c3e3b28f1 123 GAIN_EIGHT = ADS1015_REG_CONFIG_PGA_0_512V,
Gaku0606 0:387c3e3b28f1 124 GAIN_SIXTEEN = ADS1015_REG_CONFIG_PGA_0_256V
Gaku0606 0:387c3e3b28f1 125 } adsGain_t;
Gaku0606 0:387c3e3b28f1 126
Gaku0606 0:387c3e3b28f1 127 class Adafruit_ADS1015
Gaku0606 0:387c3e3b28f1 128 {
Gaku0606 0:387c3e3b28f1 129 protected:
Gaku0606 0:387c3e3b28f1 130 // Instance-specific properties
Gaku0606 0:387c3e3b28f1 131 uint8_t m_i2cAddress;
Gaku0606 0:387c3e3b28f1 132 uint8_t m_conversionDelay;
Gaku0606 0:387c3e3b28f1 133 uint8_t m_bitShift;
Gaku0606 0:387c3e3b28f1 134 adsGain_t m_gain;
Gaku0606 0:387c3e3b28f1 135 I2C* m_i2c;
Gaku0606 0:387c3e3b28f1 136
Gaku0606 0:387c3e3b28f1 137
Gaku0606 0:387c3e3b28f1 138 public:
Gaku0606 0:387c3e3b28f1 139 Adafruit_ADS1015(I2C* i2c = 0, uint8_t i2cAddress = ADS1015_ADDRESS); // set i2c adress = 0 to allow ADS1115 to use this as default constructor
Gaku0606 0:387c3e3b28f1 140 uint16_t readADC_SingleEnded(uint8_t channel);
Gaku0606 0:387c3e3b28f1 141 int16_t readADC_Differential_0_1(void);
Gaku0606 0:387c3e3b28f1 142 int16_t readADC_Differential_2_3(void);
Gaku0606 0:387c3e3b28f1 143 void startComparator_SingleEnded(uint8_t channel, int16_t threshold);
Gaku0606 0:387c3e3b28f1 144 int16_t getLastConversionResults();
Gaku0606 0:387c3e3b28f1 145 void setGain(adsGain_t gain);
Gaku0606 0:387c3e3b28f1 146 adsGain_t getGain(void);
Gaku0606 0:387c3e3b28f1 147 void user();
Gaku0606 0:387c3e3b28f1 148
Gaku0606 0:387c3e3b28f1 149 private:
Gaku0606 0:387c3e3b28f1 150 uint16_t readRegister(uint8_t i2cAddress, uint8_t reg);
Gaku0606 0:387c3e3b28f1 151 void writeRegister(uint8_t i2cAddress, uint8_t reg, uint16_t value);
Gaku0606 0:387c3e3b28f1 152 };
Gaku0606 0:387c3e3b28f1 153
Gaku0606 0:387c3e3b28f1 154 // Derive from ADS1105 & override construction to set properties
Gaku0606 0:387c3e3b28f1 155 class Adafruit_ADS1115 : public Adafruit_ADS1015
Gaku0606 0:387c3e3b28f1 156 {
Gaku0606 0:387c3e3b28f1 157 public:
Gaku0606 0:387c3e3b28f1 158 Adafruit_ADS1115(I2C* i2c, uint8_t i2cAddress = ADS1015_ADDRESS);
Gaku0606 0:387c3e3b28f1 159
Gaku0606 0:387c3e3b28f1 160 private:
Gaku0606 0:387c3e3b28f1 161 };