Home › Forums › Mayfly Data Logger › Mayfly 16 bit ADC errors
- This topic has 3 replies, 3 voices, and was last updated 2020-04-27 at 7:05 PM by Jrmichler.
-
AuthorPosts
-
-
2020-04-20 at 3:53 PM #14086I am learning how to use a Mayfly. I will be using two of the 10 bit ADC’s and one 16 bit ADC to start. My application is best met by powering with a 6AA battery pack, so I started by measurI am learning how to use a Mayfly. I will be using two of the 10 bit ADC’s and one 16 bit ADC to start. My application is best met by powering with a 6AA battery pack, so I started by measuring the battery voltage. I wired a voltage divider with a 1 Meg resistor in series with a 330K resistor. The divider is connected to both Pins 2 and 7, so both pins are getting exactly the same voltage, about 2.37 volts.
With the battery connected, the 10 bit ADC reads 9.62 volts, while the 16 bit ADC reads 9.35 volts. This is a difference of almost 3%. My Fluke DMM reads the battery voltage as 9.62 volts.
With the battery disconnected, both pins are grounded through the 330K resistor. The 10 bit ADC reads 0 volts, while the 16 bit ADC reads 0.117 volts.
Does anybody know why the 16 bit ADC is so far wrong?
12345678910111213141516171819202122232425262728293031323334// AnalogInput3.ino - Read battery voltage on both Pin 2 (10 bit) and Pin 7 (16 bit).#include <Wire.h>#include <Adafruit_ADS1015.h> //looks in library directories, typically Documents/Arduino/librariesAdafruit_ADS1115 ads; /* Use this for the 16-bit version */int sensorPin = A0; // select the input pin for the battery voltageint ledPin = 8; // select the pin for the LED (8 or 9)float BatteryVoltage = 0; // variable to store the battery voltage from 10 bit ADCfloat adc0; // variable to store battery voltage from 16 bit ADCvoid setup(){pinMode(ledPin, OUTPUT);Serial.begin(9600);Serial.println(" ");Serial.println("Single-ended external battery voltage from AIN0 and A0");// ADS1015 ADS1115// ------- -------ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mVads.begin();}void loop(){adc0 = ads.readADC_SingleEnded(0); // Get same readings from ADC AIN0, 1, 2, and 3BatteryVoltage = analogRead(sensorPin);digitalWrite(ledPin, HIGH); delay(100); // LED ON 100 msecdigitalWrite(ledPin, LOW); delay(900); // LED Off 900 msecBatteryVoltage = BatteryVoltage * 3.3 / 1024 * 4.052;adc0 = adc0 * 4.096 * 2 / 65536 * 4.052;Serial.print("A0: ");Serial.print(BatteryVoltage,3);Serial.print(" AIN0: ");Serial.println(adc0,3);} -
2020-04-20 at 10:35 PM #14087Where did the calibration coefficients you used in line 31 come from? They could be in error. The raw value of adc0 in line 26 is a bit count and 65536 (2^16) is the maximum which would be the valWhere did the calibration coefficients you used in line 31 come from? They could be in error. The raw value of adc0 in line 26 is a bit count and 65536 (2^16) is the maximum which would be the value output if the analog input was connected to Vdd (~3.3V).
Don’t know why the zero offset. I would try printing out your raw adc0 with the analog input grounded and with it connected to Vdd. Measure the Vdd with your Fluke DMM using that as your reference and adjust the calibration coefficients accordingly.
-
2020-04-20 at 11:51 PM #14088I usually leave the ADS1115 in its default gain setting (which is 0.1875 mv per bit), which is more than sufficient for most measurements. If you do that, you can easily calculate voltage by using tI usually leave the ADS1115 in its default gain setting (which is 0.1875 mv per bit), which is more than sufficient for most measurements. If you do that, you can easily calculate voltage by using these two lines:Arduino12adc0 = ads.readADC_SingleEnded(0);voltage = (adc0 * 3.3)/17585.0;
If you’re using a voltage divider, you’ll need to add an additional multiplier that is determined by the ratio if your two resistors, which is where I guess that 4.052 came from. Did you measure actual resistances of your two resistors, since tolerances can be anywhere from 1% to 20% depending on what resistor you’re using.
It also looks like you’re using 4.096 as the voltage reference of the ADS1115 in your equation on line 31, and that is incorrect. The absolute maximum reference voltage of the ADS1115 chip is 4.096v, but it is tied to the Vcc rail of the Mayfly, which is 3.3v, so you cannot measure anything higher than 3.3v with the Mayfly, and you need to use 3.3 as the multiplier in that equation.
Are you using the 6 AA battery pack to power your Mayfly? If so, it needs to be connected to the Ext 4-12v pins in the upper right corner of the board (near the FTDI header), and flip the small slide switch to EXT. You should never plug anything other than a 3.7v Lipo battery into the JST jacks labeled “LIPO BATT” because the onboard charger will attempt to charge the battery whenever a USB cable or solar panel is plugged into the Mayfly. So if you’re powering the Mayfly with alkaline batteries, it must be connected to the EXT 4-12 pins.
You can also measure whatever voltage source is powering your Mayfly by simply analog reading A6 which is connected through a voltage divider to the battery providing the power for the Mayfly. There’s an example sketch here: https://github.com/EnviroDIY/EnviroDIY_Mayfly_Logger/blob/master/examples/battery_measurement/battery_measurement.ino
-
2020-04-27 at 7:05 PM #14101Finally got back to this project…
The 6AA battery pack is wired to the “Ext 4-12V” solder pads. The voltage divider consists of a 989K resistor soldered to the battery positive l
Finally got back to this project…The 6AA battery pack is wired to the “Ext 4-12V” solder pads. The voltage divider consists of a 989K resistor soldered to the battery positive lead, connected to a 324K resistor, which is connected to Pin 20 (GND). The connection between the two resistors is connected to both Pins 2 and 7. I attached a schematic. When the 6AA pack is unplugged, Pins 2 and 7 are directly connected to each other, and connected to ground through the 324K resistor.
I commented out the multipliers so as to print the ADC counts directly. Output with battery pack disconnected:
17:31:05.868 -> Single-ended external battery voltage from AIN0 and A0
17:31:07.885 -> A0: 0.000 AIN0: 222.000
17:31:08.918 -> A0: 0.000 AIN0: 226.000
17:31:09.943 -> A0: 0.000 AIN0: 240.000
17:31:10.919 -> A0: 0.000 AIN0: 239.000
17:31:11.960 -> A0: 0.000 AIN0: 225.000
17:31:12.954 -> A0: 0.000 AIN0: 223.000
17:31:13.986 -> A0: 0.000 AIN0: 237.000
17:31:15.011 -> A0: 0.000 AIN0: 241.000And output with the battery pack connected:
17:34:48.862 -> Single-ended external battery voltage from AIN0 and A0
17:34:49.886 -> A0: 741.000 AIN0: 18462.000
17:34:50.879 -> A0: 736.000 AIN0: 18449.000
17:34:51.904 -> A0: 736.000 AIN0: 18460.000
17:34:52.935 -> A0: 736.000 AIN0: 18468.000
17:34:53.919 -> A0: 736.000 AIN0: 18466.000
17:34:54.950 -> A0: 737.000 AIN0: 18458.000
17:34:55.973 -> A0: 737.000 AIN0: 18455.000The blinky light blinks the same whether the board is powered by the USB port or by the 6AA battery pack.
It was my understanding that the ADS1115 outputs 0 to 2^15 ADC counts for 0 to 4.096 volts, but that the voltage in this application cannot exceed 3.3 volts without causing damage. That would explain your factor of 17,585 (32,768 / 17,585 X 3.3 = 6.149 volts).
I did not try to read Pin A6 after I had read the following:
On the Mayfly, analog pin A6 is connected to a resistor divider that measures the voltage of the battery connected to the LiPo jack.
NOTE: If the USB cable or an FTDI adapter is connected to the Mayfly (ie, to connect to the Serial Monitor) the measured voltage will be from the voltage from USB/FTDI cable (~5V) and not the voltage of the LiPo battery.
I could just apply an offset and calibration factor to the 16 bit results to force them to agree with the Fluke meter and the 10 bit ADC. The problem is that the discrepancy is outside the ADS1115 datasheet error specifications by more than a factor of ten. It is far preferable to find the root cause of the discrepancy.
This particular sketch is for the purpose of learning to use the Mayfly before I connect the real sensors. But first I need to get the 10 bit and 16 bit ADC’s to agree.
Attachments:
-
-
AuthorPosts
- You must be logged in to reply to this topic.