ADS1115 - strange behaviour

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

ADS1115 - strange behaviour

#1 Post by Shardan » 30 Nov 2016, 23:42

Hello all,

i'm using two ADS 1115 breakout boards in a circuit for ampere metering on several lines.
Addresses are set to 0x48 and 0x49, both addresses are found by I²C-Scan correctly.
The lower board is running exactly as wanted, i can read the ports 0...3 without issue.
The board on 0x49 shows a strange behaviour.

On port 4 i see the value of port 0 (the Ao-port on 0x48).
Port 5..7 working correct. I get a reading on port 8 which seems to be a differential reading to port 5:

Voltage to A0, A1 open (20KOhm to ground) shows A0 on port 8 with 32767 (correct) and A1 on port 5 with 65529 (more or less correct, maybe some offset from the PGA).
Voltage to A1, A0 open (20KOhm to ground) shows A0 with 32768 and A1 on 32767.
Voltage to both shows A0 with 65513 and A1 with 32767.
No woltage to both shows both inputs around zero.

I removed the module at 0x48 without result.
I swaped both modules - no result, i took a new module alone on 0x49 - same.

Is this possibly an addressing bug in the sketch? That might explain the reading on port 8 instead of port 4 and the setup as a differential input.

Regards
Shardan
Regards
Shardan

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: ADS1115 - strange behaviour

#2 Post by Shardan » 01 Dec 2016, 19:41

Found the point, solved.

The breakoutboards start counting with "0".
If you enter port 0 into ESPEasy config the sketch produces unpredictable results.
ESPEasy starts counting with "1".....
Regards
Shardan

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: ADS1115 - strange behaviour

#3 Post by Shardan » 01 Dec 2016, 22:51

Sorry, nope - not solved.
Now i have this behaviour on both ADS1115.

Put some voltage on A0 - reading is on port 4, not on port 1 as it should be
if i put the same voltage on A1 and A0 i get a differential output again.

I use 16x gain and a voltage of about 0.2 V.

Voltage on A0 shows 25500 (correctly) on port 4, all other ports around zero.
Voltage on A1 shows 25500 on Port 1 and 40000 on port 4 (which is the difference from 65535 - 25500)
Voltage on A0 and A1 shows 25500 on Port 1 and around zero on Port 4.

Definitely something is going wrong.
Any ideas?

Regards
Shardan.
Regards
Shardan

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: ADS1115 - strange behaviour

#4 Post by Shardan » 01 Dec 2016, 23:42

Something is strange in the code.

I'm a hardware guy, my programming knowledge is limited (and very old), so i might be wrong with the following:

Code: Select all

        byte unit = (Settings.TaskDevicePort[event->TaskIndex] - 1) / 4;
        byte port = Settings.TaskDevicePort[event->TaskIndex] - (unit * 4);
        uint8_t address = 0x48 + unit;
This calculates the address from the configured port number.
"byte" as far as i know is an unsigned integer type with rollover.
If you chose port=0 in the configuration the calculation might run crazy: (0 - 1) will set the "unit" from 0 to 255, it rolls over.
255/4 gives 63 as it is an integer. That will give a non existing adress with "0x48 + unit"
Following this the lowest allowed port number is 1. Ports should count 1 .... 4 for the ADS1115 on 0x48
With 1 ... 4 the "unit" has the value 0, i think that is correct.

The "port" calculation uses the calculated "unit" value.
So for a configured Port 1 the "unit" is 0 - the lowest resulting "port" value is 1: 1 - (0 *4)

Later in the code there is

Code: Select all

        switch (port)
        {
        case (0):			<--- Here the ports count 0 ... 3 !
          config |= (0x4000);
          break;
        case (1):
          config |= (0x5000);
          break;
        case (2):
          config |= (0x6000);
          break;
        case (3):
          config |= (0x7000);
          break;
        }
Ports are addressed from 0 .... 3 here.

As said i might be wrong as i'm far away from being a programmer. But this seems to me as if the "port 0" will never get data.

Did i miss something or is that right?

Regards
Shardan
Regards
Shardan

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: ADS1115 - strange behaviour

#5 Post by Shardan » 02 Dec 2016, 13:47

Did some further testing today.

First i made a simple breadboard testing circuit.
Two ADS1115 and a nodemcu showed the same behaviour as the PCB, so the PCB layout isn't faulty.

Then i changed the code in _P025_ADS1115. To keep an existing configuration runnning i changed lines 175ff to

Code: Select all

        switch (port)
        {
        case (1):				
          config |= (0x4000);
          break;
        case (2):				
          config |= (0x5000);
          break;
        case (3):				
          config |= (0x6000);
          break;
        case (4):				
          config |= (0x7000);
          break;
        }
Instead of case(0) ... case(3) i use case(1) .... case(4) now.
And voilá! Both, breadboard and PCB show correct values now.

@Martinus:
Please check this as i'm definitely no coder and i have no knowledge about arduino programming. I might have done something stupid.
Please verify if this is really a bug.

Regards
Shardan
Regards
Shardan

Post Reply

Who is online

Users browsing this forum: No registered users and 123 guests