|
| 1 | +========== |
| 2 | +TI ADS1115 |
| 3 | +========== |
| 4 | + |
| 5 | +Contributed by Jia Lin |
| 6 | + |
| 7 | +The ADS1115 is a 16-bit, 4-channel ADC made by Texas Instruments which operates over |
| 8 | +I2C. It can measure voltages from each channel individually, or between different |
| 9 | +pairs of channels. The ADS1115 also supports a programmable gain amplifier (PGA) and |
| 10 | +a digital comparator. |
| 11 | + |
| 12 | + |
| 13 | +.. list-table:: Channel Numbers and Corresponding Sources |
| 14 | + :widths: auto |
| 15 | + |
| 16 | + * - Channel number |
| 17 | + - AINP |
| 18 | + - AINN |
| 19 | + * - 0 |
| 20 | + - AIN0 |
| 21 | + - AIN1 |
| 22 | + * - 1 |
| 23 | + - AIN0 |
| 24 | + - AIN3 |
| 25 | + * - 2 |
| 26 | + - AIN1 |
| 27 | + - AIN3 |
| 28 | + * - 3 |
| 29 | + - AIN2 |
| 30 | + - AIN3 |
| 31 | + * - 4 |
| 32 | + - AIN0 |
| 33 | + - GND |
| 34 | + * - 5 |
| 35 | + - AIN1 |
| 36 | + - GND |
| 37 | + * - 6 |
| 38 | + - AIN2 |
| 39 | + - GND |
| 40 | + * - 7 |
| 41 | + - AIN3 |
| 42 | + - GND |
| 43 | + |
| 44 | +Driver Interface |
| 45 | +--------------------- |
| 46 | + |
| 47 | +To register the ADS1115 device driver as a standard NuttX analog device on your |
| 48 | +board, you can use something similar to the below code for the RP2040. |
| 49 | + |
| 50 | +.. code-block:: c |
| 51 | + |
| 52 | + #include <nuttx/analog/ads1115.h> |
| 53 | + #include <nuttx/analog/adc.h> |
| 54 | +
|
| 55 | + /* Register ADS1115 ADC. */ |
| 56 | +
|
| 57 | + struct adc_dev_s *ads1115 = ads1115_initialize(rp2040_i2cbus_initialize(0), |
| 58 | + CONFIG_ADC_ADS1115_ADDR); |
| 59 | + if (ads1115 == NULL) |
| 60 | + { |
| 61 | + syslog(LOG_ERR, "Failed to initialize ADS1115\n"); |
| 62 | + } |
| 63 | +
|
| 64 | + ret = adc_register("/dev/adc1", ads1115); |
| 65 | + if (ret < 0) |
| 66 | + { |
| 67 | + syslog(LOG_ERR, "Failed to register ADS1115 device driver: %d\n", ret); |
| 68 | + } |
| 69 | +
|
| 70 | +If you have a measurement from the ADS1115, you can convert it into a voltage |
| 71 | +like so: |
| 72 | + |
| 73 | +.. code-block:: c |
| 74 | +
|
| 75 | + #define FSR (2.048) |
| 76 | +
|
| 77 | + struct adc_msg_s msg; |
| 78 | +
|
| 79 | + /* Some code here to read the ADC device, you can read the ADC driver docs */ |
| 80 | +
|
| 81 | + double voltage = ((double)msg.am_data * FSR) / (32768.0); |
| 82 | +
|
| 83 | +Once registered, this driver can be interacted with using the ADC example |
| 84 | +(:ref:`adc-example`). Be sure to enable the software trigger, since the ADS1115 |
| 85 | +driver does not support hardware triggers (interrupts). You can also change the |
| 86 | +number of samples per group up to 8 for all 8 channels of the ADC. |
| 87 | + |
| 88 | +You may need to increase the `CONFIG_ADC_FIFOSIZE` value to something larger |
| 89 | +than 8 in order to be able to store all the ADC measurements after a measurement |
| 90 | +trigger (i.e 9). |
| 91 | + |
| 92 | +Configuration |
| 93 | +--------------------- |
| 94 | + |
| 95 | +.. list-table:: Configuration Options |
| 96 | + :widths: auto |
| 97 | + |
| 98 | + * - Name |
| 99 | + - Description |
| 100 | + * - CONFING_ADC_ADS1115_I2C_FREQUENCY |
| 101 | + - I2C frequency of the ADS1115 |
| 102 | + * - CONFIG_ADC_ADS1115_ADDR |
| 103 | + - I2C address of the ADS1115 |
| 104 | + * - CONFIG_ADC_ADS1115_CHANNEL |
| 105 | + - Default ADC channel to read |
| 106 | + * - CONFIG_ADC_ADS1115_PGA |
| 107 | + - Gain of the ADS1115 |
| 108 | + * - CONFIG_ADC_ADS1115_CONTINOUS |
| 109 | + - Continous mode of the ADS1115 |
| 110 | + * - CONFIG_ADC_ADS1115_DR |
| 111 | + - Data rate of the ADS1115 |
| 112 | + * - CONFIG_ADC_ADS1115_COMP_MODE |
| 113 | + - Mode of the ADS1115 comparator, traditional or window |
| 114 | + * - CONFIG_ADC_ADS1115_COMP_POL |
| 115 | + - Polarity of the ADS1115 comparator, active high or active low |
| 116 | + * - CONFIG_ADC_ADS1115_COMP_LAT |
| 117 | + - Latching mode of the ADS1115 comparator, traditional or latching |
| 118 | + * - CONFIG_ADC_ADS1115_COMP_QUE |
| 119 | + - Comparator queue of the ADS1115, which changes when the ALRT/RDY pin is asserted. |
| 120 | + * - CONFIG_ADC_ADS1115_HI_THRESH |
| 121 | + - HIGH_THRESH register of the ADS1115 |
| 122 | + * - CONFIG_ADC_ADS1115_LO_THRESH |
| 123 | + - LOW_THRESH register of the ADS1115 |
| 124 | + |
| 125 | +.. list-table:: Data Rates |
| 126 | + :widths: auto |
| 127 | + |
| 128 | + * - Value in Kconfig |
| 129 | + - Data Rate |
| 130 | + * - 0 |
| 131 | + - 8 SPS |
| 132 | + * - 1 |
| 133 | + - 16 SPS |
| 134 | + * - 2 |
| 135 | + - 32 SPS |
| 136 | + * - 3 |
| 137 | + - 64 SPS |
| 138 | + * - 4 |
| 139 | + - 128 SPS |
| 140 | + * - 5 |
| 141 | + - 250 SPS |
| 142 | + * - 6 |
| 143 | + - 475 SPS |
| 144 | + * - 7 |
| 145 | + - 860 SPS |
| 146 | + |
| 147 | + |
| 148 | +.. list-table:: PGA Values |
| 149 | + :widths: auto |
| 150 | + |
| 151 | + * - Value in Kconfig |
| 152 | + - Full Scale Range (FSR) |
| 153 | + * - 0 |
| 154 | + - ±6.144V |
| 155 | + * - 1 |
| 156 | + - ±4.096V |
| 157 | + * - 2 |
| 158 | + - ±2.048V |
| 159 | + * - 3 |
| 160 | + - ±1.024V |
| 161 | + * - 4 |
| 162 | + - ±0.512V |
| 163 | + * - 5 |
| 164 | + - ±0.256V |
| 165 | + * - 6 |
| 166 | + - ±0.256V |
| 167 | + * - 7 |
| 168 | + - ±0.256V |
| 169 | + |
| 170 | + |
| 171 | +.. list-table:: Comparator Queue Values |
| 172 | + :widths: auto |
| 173 | + |
| 174 | + * - Value in Kconfig |
| 175 | + - Comparator Queue |
| 176 | + * - 0 |
| 177 | + - Assert after one conversion |
| 178 | + * - 1 |
| 179 | + - Assert after two conversions |
| 180 | + * - 2 |
| 181 | + - Assert after four conversions |
| 182 | + * - 3 |
| 183 | + - Disable comparator |
| 184 | + |
| 185 | + |
| 186 | + |
| 187 | +Additional ioctl Commands |
| 188 | +-------------------------------- |
| 189 | + |
| 190 | +There are various additional ioctl() commands that can be used with the ADS1115 driver. |
| 191 | +These mostly allow for changes of configuration in runtime. |
| 192 | + |
| 193 | +.. c:macro:: ANIOC_ADS1115_SET_PGA |
| 194 | +
|
| 195 | +This command changes the gain of the ADS1115 driver. The argument passed should |
| 196 | +be of type ads1115_pga_e, which corresponds to the gain seen above. |
| 197 | + |
| 198 | +.. c:macro:: ANIOC_ADS1115_SET_MODE |
| 199 | +
|
| 200 | +This command changes the ADS1115 to operate in continous or single-shot mode. |
| 201 | + |
| 202 | +.. c:macro:: ANIOC_ADS1115_SET_DR |
| 203 | +
|
| 204 | +This command changes the data rate of the ADS1115 driver. The argument passed should |
| 205 | +be of type ads1115_dr_e, which corresponds to the data rate seen above. |
| 206 | + |
| 207 | +.. c:macro:: ANIOC_ADS1115_SET_COMP_MODE |
| 208 | +
|
| 209 | +This command changes the ADS1115 to operate in either traditional or window comparator mode. |
| 210 | + |
| 211 | +.. c:macro:: ANIOC_ADS1115_SET_COMP_POL |
| 212 | +
|
| 213 | +This command changes the ADS1115 to operate in either active high or active low mode. |
| 214 | + |
| 215 | +.. c:macro:: ANIOC_ADS1115_SET_COMP_LAT |
| 216 | +
|
| 217 | +This command changes the ADS1115 to operate in either traditional or latching comparator mode. |
| 218 | + |
| 219 | +.. c:macro:: ANOIC_ADS1115_SET_COMP_QUEUE |
| 220 | +
|
| 221 | +This command changes the comparator queue feature of the ADS1115. The argument passed should |
| 222 | +be of type ads1115_comp_queue_e, which corresponds to the comparator queue seen above. |
| 223 | + |
| 224 | +.. c:macro:: ANOIC_ADS1115_SET_HI_THRESH |
| 225 | +
|
| 226 | +This command changes the HIGH_THRESH register of the ADS1115. The argument passed should be |
| 227 | +of type uint16_t, which corresponds to the HIGH_THRESH register value. |
| 228 | + |
| 229 | +.. c:macro:: ANOIC_ADS1115_SET_LO_THRESH |
| 230 | +
|
| 231 | +This command changes the LOW_THRESH register of the ADS1115. The argument passed should be |
| 232 | +of type uint16_t, which corresponds to the LOW_THRESH register value. |
0 commit comments