At the bottom of the page you can download a simple driver for ADS1112 16 bit, self-calibrating, delta-sigma ADC. It has an internal 2.048V reference and I2C interface.
The driver files below are using the I2C interface functions from the standard peripheral library of ST Microelectronics STM32F051 but can be easily adapted to other I2C driver functions.
First, a little bit about the this ADC:
Datasheet here: http://www.ti.com/lit/ds/symlink/ads1112.pdf
Having a very small footprint, very few external components and a I2C interface means that you can put this ADC very close to the measuring point in your project, for minimum interference and then connect this with 4 wires (power and I2C) to your main board.
Note: ADS1112 can read bipolar differential signals but it cannot accept negative voltages on either input.
This ADC has four analog inputs and by configuring the INP bits in the configuration register, you can measure two differential channels or three single ended channels referenced to AIN3.
For single-ended measurements, AIN3 needs to be grounded and the signal applied to any of AIN0, AIN1 or AIN2
The ADS1112 input range is bipolar differential, so the single-ended circuit above will cover only half of the ADS1112 input scale because it does not produce differentially negative inputs and one bit of resolution will be lost.
Another feature of this ADC is it's PGA, which is a configurable gain that you can use: 1,2,4 or 8. This is very useful when you want to measure small signals and be able to use as much of ADS1112's input range as possible.
You can configure it with the PGA bits:
And then, you can control the data conversion rate of the ADC by configuring the DR bits, but for every doubling of the conversion speed starting from 15 samples per second you will loose a resolution bit:
And now a little bit about the driver:
These are the interface functions:
u8 ADS1112_Init(void);
u8 ADS1112_TriggerConversion(void);
u8 ADS1112_SetMeasurementChannel(u8, u8);
u8 ADS1112_GetSample(s16*, u8*);
u8 ADS1112_Init(void) needs to be called somewhere at startup, before the everything starts to run, before the cyclic endless loop is started. It will configure ADC SC and DR bits.
ADS1112_Init()
int main(void)
{
Config();
Errors_Init();
// other init code...
if(!ADS1112_Init()) {
Errors_SetError(ERROR_ADS1112);
}
//...main code
}
u8 ADS1112_TriggerConversion(void) triggers a new conversion in single conversion mode by writing the ST/DRDY in the configuration register. I didn't use this function, I set ST/DRDY bit in ADS1112_SetMeasurementChannel(channel, PGA) function but you can adapt as you like for your project.
u8 ADS1112_SetMeasurementChannel(u8, u8) function selects the measurement channel, configures the PGA (gain), sets the single conversion mode bit and also triggers a conversion.
Here is how I used it to switch from voltage measurement channel to current measurement channel.
u8 ADS1112_SetMeasurementChannel(channel, pga)
switch(ADS1112_channel)
{
case VOLT_MEASUREMENT: //if ADS1112_channel == VOLT_MEASUREMENT means that we have an amperage sample read from the ADC
{
ADS1112_channel = AMP_MEASUREMENT;
if(!ADS1112_SetMeasurementChannel(ADS1112_channel, pga)) {
Errors_SetError(ERROR_ADS1112);
}
else {
Errors_ResetError(ERROR_ADS1112);
}
// ...
u8 ADS1112_GetSample(s16*, u8*) function reads the conversion result from the ADC in the samp parameter and reads the status of the sample in sampstat, 1 means new data and 0 old data
ADS1112_GetSample()
if(!ADS1112_GetSample(&sample, &ADCNewSample))
{
Errors_SetError(ERROR_ADS1112);
}
else
{
Errors_ResetError(ERROR_ADS1112);
}
The ADS1112_cfg.* files contain the I2C needed functions for STM32F051 and the ADS1112 I2C address. These I2C function interfaces can be exchanged to your project needs.
You can find another version of this ADS1112 driver that contains software I2C routines that were used on a Microchip PIC16F876A because this micro did not have a hardware I2C peripheral, here on this bench supply project Voltage and current measurement in a bench power supply
I successfully used this ADC for some years now in a bench power supply and a programmable load for precision measurement of voltage and current of the bench supply and it proved to be very reliable and give very stable current and voltage readings.