Arduino library for 18 bit ADC I2C MCP3424 and compatibles.
Experimental
Library not tested with hardware yet.
This library is to be used to configure and read the 18 bit MCP4324 4 channel ADC et al.
The MCP3424 is not a fast ADC, however with 18 bit it has at least a very high resolution. What the effects of the long sampling time means is to be investigated. The high resolution combined with an optional gain of 8x means one could measure voltage in steps of about 2 µV.
The library cannot check yet if a conversion is ready. Need hardware to check how this works in detail.
The library has three functions that return a reading in Volts, milliVolts or microVolts to match the need of the user.
The user has to configure the ADC device (bits, gain) and can call read() (et al) without parameters to keep usage straightforward.
Current implementation will probably change slightly in the future when related devices will be supported. (See future section).
Alt-230 = µ
Bits | LSB (gain=1) | SPS | Raw range | Notes |
---|---|---|---|---|
12 | 1 mV | 240 | -2048 .. 2047 | |
14 | 250 µV | 60 | -8192 .. 8191 | |
16 | 62.5 µV | 15 | -32768 .. 32767 | |
18 | 15.625 µV | 3.75 | -131072 .. 131071 | not for 3426/27/28. |
The effective resolution also depends on the gain set. In theory with a gain of 8 the LSB of the 18 bit resolution represents 1/8 of 15.625 µV == 1.95 µV. If this is feasible in practice is to be seen.
The MCP3421 and MCP3426 have a fixed address 0x68, one can order different addresses at the factory (how?).
The other devices have two address pins to set 8 addresses. The trick is to leave address pins floating. See datasheet table 5.3 for details.
The MCP342x devices support 100 KHz, 400 KHz and 3.4 MHz. The latter is not (yet) supported by the library. The sketch MCP3424_performance.ino can be used to get some insight in the performance. It will check up to 800 kHz.
TODO verify with hardware.
Sometimes you need to control more devices than possible with the default address range the device provides. This is possible with an I2C multiplexer e.g. TCA9548 which creates up to eight channels (think of it as I2C subnets) which can use the complete address range of the device.
Drawback of using a multiplexer is that it takes more administration in your code e.g. which device is on which channel. This will slow down the access, which must be taken into account when deciding which devices are on which channel. Also note that switching between channels will slow down other devices too if they are behind the multiplexer.
#include "MCP3424.h"
The MCP3421/2/3/6/7/8 constructors have the same parameters.
The user has to configure the ADC device (bits, gain) and can call read() (et al) without parameters to keep usage straightforward.
Correct settings will be written to the device immediately, but be aware of the fact that it will take some time before the conversion with new settings is done.
The set function write their changes directly to the device. It might be better to have one function to set all parameters in one call. To be investigated.
The library caches the last configuration, it is not read back from the device. This might be added in the future.
If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.
Thank you,