Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, an initiative of Stroud Water Research Center designed to help people advance knowledge and stewardship of fresh water.
New to EnviroDIY? Start here

Mayfly 16 bit ADC errors

Home Forums Mayfly Data Logger Mayfly 16 bit ADC errors

Viewing 3 reply threads
  • Author
    Posts
    • #14086
      Jrmichler
      Participant

        I 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?

         

      • #14087
        Jim Moore
        Participant

          Where 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.

        • #14088
          Shannon Hicks
          Moderator

            I 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:

            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

          • #14101
            Jrmichler
            Participant

              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.000

              And 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.000

              The 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:
          Viewing 3 reply threads
          • You must be logged in to reply to this topic.