This is only a preview of the November 2023 issue of Silicon Chip.
You can view 47 of the 112 pages in the full issue, including the advertisments.
Articles in this series:
Items relevant to "Pico Audio Analyser":
Articles in this series:
Items relevant to "K-Type Thermostat":
Items relevant to "Modem/Router Watchdog":
Items relevant to "1kW+ Class-D Amplifier, Pt2":
Items relevant to "Recreating Sputnik-1, Part 1":
Purchase a printed copy of this issue for $12.50.
Using Electronic Modules with Jim Rowe 16-bit precision 4-input ADC This month we’re looking at the tiny ADS1115 that can add up to four high-speed 16-bit analog-to-digital conversion (ADC) channels to almost any microcontroller. It has a built-in I2C serial interface, so it can be easily connected to popular microcontrollers like an Arduino Uno or Nano. L et’s say you want to make precise measurements of analog voltages or currents with one of the common microcontroller units (MCUs). The ADC in most MCUs provides a resolution of only ten bits over a range of either 3.3V or 5V, which corresponds to a precision of ±1.6mV (3.3V ÷ 1024 ÷ 2) or ±2.5mV (5V ÷ 1024 ÷ 2), where 1024 is equal to 210. That is acceptable for many applications, but not good enough if you want to make precision measurements, especially of small voltages. That’s where this module is worth considering because it allows you to add precision 16-bit ADC capability to any of the popular MCUs. As a result, you will be able to make much more precise measurements, even on quite small signals. It offers a precision improvement of 64 times compared to a 10-bit ADC or 16 times compared to a 12-bit ADC. It is not just useful for a single-ended full-scale range of 3.3V or 5V either, because the module gives you a choice of six different full-scale ranges: ±6.144V, ±4.096V, ±2.048V, ±1.024V, ±512mV or ±256mV. This means that the smallest step size on the highest range is 187.5µV, while on the lowest range, it’s 7.8125µV. Note though that the inputs must go no more than 0.3V beyond the supply rails and those measurement ranges can be between two inputs or from an input to ground. So you can’t actually measure voltages very far below ground or above the (typically 3.3V or 5V) supply range. A further feature of the module is that it has four analog inputs, which can be used to measure either four different voltages with respect to ground, or to provide two differential inputs. Another feature of the module which adds to its appeal is the ability to make measurements at eight different rates, from eight per second to 860 per second. It connects to the MCU via a standard two-wire I2C serial interface, with the ability to set the module’s I2C port to one of four addresses: 48h, 49h, 4Ah or 4Bh (h = hexadecimal). That means you can connect up to four modules to a single I2C port on an MCU, each set for a different I2C address. Even if you don’t need the improved precision, if you’ve run out of ADC channels on your micro, it might be worth considering this module for the extra analog inputs it provides. If you’re already using an I2C serial bus in your project, it won’t even take up any more pins on the micro to add as many as 16 more analog inputs. Otherwise, you can dedicate two digital pins – not a bad swap. In short, it’s a very flexible and impressive precision ADC module. All of these capabilities are due to the IC that forms the ‘heart’ of the module: an ADS1115 made by Texas Instruments. So let’s look at the innards of this impressive chip. Inside the ADS1115 Fig.1: a block diagram of the ADS1115 IC. This shows the ADS1115 can be configured as four single-ended channels or as two differential channels. 46 Silicon Chip Australia's electronics magazine Fig.1 shows the basic block diagram of the ADS1115. The 16-bit delta- sigma ADC is in the centre, with the chip’s built-in voltage reference just above it and the internal clock oscillator just below. To the left of the ADC (on its input side) is a programmable-gain differential amplifier (PGA), providing the chip’s six full-scale ranges. Left of the PGA is the input multiplexer (MUX), which selects which of siliconchip.com.au the four single-ended inputs (AIN0AIN3) are connected to the input of the PGA, or which two inputs are connected as a differential input. When one of the single-ended inputs is selected, the lower input of the PGA is connected internally to ground. In contrast, when two inputs are selected for differential measurements, each is connected to one of the PGA inputs. You can see the chip’s I2C interface to the right of the ADC. This provides two-way communication between the ADS1115 and the external MCU, with programming and control data inwards, and the measurement data stream outwards. This is done using the SCL and SDA pins; the ADDR pin sets the chip’s I2C address by linking it to one of the Vdd, GND, SCL or SDA pins, as will be explained shortly. Above the I2C interface is a comparator with its output connected to the chip’s ALERT/READY (or ALRT/ RDY) pin. The comparator can be programmed to perform one of two functions: either an alert ‘flag’ whenever the ADC output reaches the top or bottom threshold of its measurement range, or as an indication that a measurement has been made and the result is ready for ‘collection’ by the MCU. The final section of the ADS1115 is below the I2C interface. This comprises four 16-bit registers: 1. The Conversion register, which holds the last conversion data. 2. The Configuration register, which holds the programming bits for the chip’s input multiplexer, the gain/ range settings for the PGA, the sampling rate setting and whether the device is to operate in single-shot or continuous conversion mode – see Fig.2. 3. Lo-thresh, the lower threshold value for the Alert Comparator. 4. Hi-thresh, the upper threshold value for the Alert Comparator. Data in the Conversion, Lo-thresh and Hi-thresh registers is stored in signed two’s complement format: from 8000h (-32768) to 7FFFh (+32767). Because this ADC has differential inputs, it can produce negative results, meaning that a signed number is needed. This also means that there are effectively 15 bits of resolution when single-ended samples are taken. siliconchip.com.au Fig.2: how the configuration register is arranged. This 16-bit register handles the chip’s input multiplex (bits 12-14), the PGA (bits 9-11), whether the device is operated in single-shot or continuous conversion mode (bit 8) and the sampling rate (bits 5-7). Fig.3: the ADS1115-based module is extremely simple, as can also be seen in the lead photo. The values of the L1 & L2 inductors are unknown, they could be ferrite beads. Fig.4: it’s easy to connect the ADS1115-based module to an Arduino Uno or similar, as all you need to do is connect its I2C interface (SCL & SDA) and power rails to the Arduino. Australia's electronics magazine November 2023 47 As you can see, there’s quite a lot inside the ADS1115’s tiny (3.0 × 3.0mm) 10-pin VSSOP (very-thin shrink small-outline) package. It can be powered from supply voltages (Vdd) between 2.0V and 5.5V. However, the analog input voltages must be kept within the range of (GND − 0.3V) to (Vdd + 0.3V) to prevent the ESD diodes inside the input MUX from conducting, which would degrade the accuracy of the ADS1115 as well as possibly damaging it. When the ADS1115 is initially powered up, it is set to its reset/default mode: the input MUX selects AIN0 and AIN1 in differential mode, the PGA is set for a full-scale range of ±2.048V, the sampling rate set to 128 samples per second and the conversion mode set to one-shot mode. If any of those need to be changed, it can be done by sending the appropriate instructions from the MCU. The I2C address of the chip is not determined by anything in the Configuration register, but by the connection to the ADDR pin. The module circuit As you can see from the circuit in Fig.3, there’s very little in the module apart from the ADS1115 chip itself. There are three pull-up resistors connected between its SDA, SCL and ALRT/RDY pins and the Vdd line, a pull-down resistor between the ADDR line and GND, two small inductors (L1 and L2) of unknown value (they might even be ferrite beads), plus two 100nF capacitors which provide filtering for the module’s input power. The only other item is 10-pin SIL header CON1, which makes all the connections to the module. Connecting to an Arduino Fig.5: this wiring diagram shows how to connect the ADS1115 module to an Arduino Nano. Fig.6: by default the ADS1115 has an I2C address of 48h. If you plan to connect multiple ADS1115 modules to communicate with a microcontroller, then you will need to link the ADDR pin to one of the other pins as shown. 48 Silicon Chip As mentioned earlier, one of this module’s features is how its I2C interface makes it easy to connect to one of the popular MCUs. This is illustrated in Fig.4, which shows how easily it can be connected to an Arduino Uno. The module’s Vdd pin connects to the Arduino’s +5V pin, its GND pin to one of the Arduino’s GND pins, its SDA pin to the Arduino’s A4/SDA pin and its SCL pin to the Arduino’s A5/SCL pin. With R3 and later versions of the Uno, the last two pins can be connected to the SDA and SCL pins at upper left on the Arduino, just to the left of the AREF pin. These locations have the advantage of always being in the same position on Uno-compatible boards, regardless of which pins the micro actually uses for I2C. Connecting the module to an Arduino Nano is just as easy, as shown in Fig.5. As you can see, the module’s Vdd pin connects to the Nano’s +5V pin, the GND pin to one of the Nano’s GND Australia's electronics magazine pins, its SCL pin to the Nano’s A5 pin and its SDA pin to the Nano’s A4 pin. By default, the ADDR pin is connected to ground by a 10kW resistor, so the module will have the address 48h. To change it, link the module’s ADDR pin to one of the pins to its left, as shown in Fig.6. Linking this pin to the Vdd pin sets the I2C address to 49h; linking it to the SDA sets the address to 4Ah, while linking it to the SCL pin sets the address to 4Bh. It should be just as easy to connect the ADS1115 module to just about any other MCU, including one of the ‘Mite’ series (Maximite, Micromite, PicoMite etc). Whichever MCU you want to connect the module to, you will need software to configure it and interpret its output data stream. Let’s now consider how this can be done with an Arduino. This will involve finding a software library designed to communicate with the ADS1115, plus (hopefully) an example sketch to show how it’s done. Arduino software libraries Searching the web for Arduino libraries for the ADS1115, I came up with three choices: 1. A library called ADS1x1x, written by someone named hideakitai, with the documentation and the zipped-up library code at https://github.com/ hideakitai/ADS1x1x 2. A library called ADS1x15, written by Rob Tillaart, with the documentation and the zipped-up library code at https://github.com/RobTillaart/ ADS1X15 3. A library called ADS1115_WE, written by Wolfgang Ewald, with the documentation and the zipped-up library code at https://github.com/ Wollewald/ADS1115_WE All three come with at least one example sketch, while the third comes with no fewer than 10 examples illustrating different ways of using the ADS1115. After trying each of these libraries and their example sketches, I decided that the ADS1115_WE library and its examples were probably the easiest to use. I also found that Mr Ewald had a very informative piece on his blog site (linked at the end of this article) giving a lot of information regarding the ADS1115, how it works and how it is programmed. siliconchip.com.au I made a few minor changes to Mr Ewald’s single-shot example and tried using it to take measurements of different DC voltages. You can see the results in the Serial Monitor listing shown in Fig.7. I had connected the test voltage to AIN1, with the AIN0 and AIN2 inputs connected to ground and the AIN3 input left floating. The ADS1115 was programmed to set its measurement range to ±2048mV and to compare AIN1 to GND. When I set the sketch at 7:09:36am, the voltage fed to the AIN1 input was +100mV and remained so until 7:09:49am. Then I changed it to +200mV before changing it to +500mV at 7:05:58am. Then at 7:10:07am, I changed it to +50mV, passing briefly through +100mV. Finally, at 7:10:16am, I changed the voltage to +20mV. The AIN0 column remains fixed at readings of -0.00, as does the AIN2 column, reflecting the fact that both of these inputs were grounded. But because the AIN3 input was left floating, the readings in this column remained fixed at 0.27V. If you decide to try out my example sketch, remember to change the address in the code to match what you have configured your module for, as shown in Fig.6. Conclusion Overall, this module is easy to use, flexible, and far more accurate than most microcontrollers for measuring analog voltages. It doesn’t have as much precision as a good DMM, but it is nonetheless extremely handy. If you want to learn more about the ADS1115, you can view the datasheet at: www.ti.com/product/ADS1115 Also see the technical write-up on Wolles Elektronikkiste: siliconchip. au/link/abph Above: the ADS1115 module can run from a 2-5.5V supply, making it easy to use both 3.3V and 5V powered micros. The available sampling rates are: 8, 16, 32, 64, 128, 250, 475 and 860 samples per second (SPS). Fig.7 (right): we ran Wolfgang Ewald’s singleshot example code, with some minor changes, and used it to measure different DC voltages. Where you can get it The ADS1115 module I checked out is currently available from Altronics (stock number Z6221) for $20.75 (including GST). At the time of writing, it is also available from Paktronics for $30.07, eBay supplier duomin 87 for $16.01, Temu for $7.48 and AliExpress from $2.39 + P&P. There are some other modules using the ADS1115 that look a little different but are very similar in terms of circuitry. SC siliconchip.com.au Australia's electronics magazine November 2023 49