Controlling ADC with new I2C version

leenowell
Posts: 155
Joined: Tue Jan 15, 2019 1:50 pm

Re: Controlling ADC with new I2C version

Postby leenowell » Thu Feb 06, 2025 7:55 am

I have now got everything up and running and have been trying to calibrate my thermistor with limited results. The test rig was a small lidded cast iron pan filled with oil (both to try and stabalise the temp) and the test probe and known "good" thermometer probe in the small hole in the lid (I removed the knob and used the screw hole). The probes were about 2cm above the oil - not sure whether the probes are waterproof. Using the complete circuit I plotted temperature vs resistance (calculated from the ADC value) on the following (attached) graph.
Screenshot from 2025-02-06 07-28-41.png
Screenshot from 2025-02-06 07-28-41.png (116.77 KiB) Viewed 2171 times
I got it to draw a log/ exponential line of best fit (black line) and the jagged one are my results. I can imagine there were a few dodgy readings (the ADC value was never solidly stable at a give temp) but was expecting better than this. TBH it is probably no better than using the onboard ADC. So a couple of questions if I can
1. When we discussed the design before I had thought the capacitor show go between the ADC pin and ground (essentially bi-passing the thermistor). Looking at the spec of the ADS1115 again now I *think* it is saying to add a 0.1UF capacitor (I have a 104 labelled brown round one which I think is correct?) across the power pins as it has internal capacitors on the input pins. I have been struggling to understand the data sheet so wanted to check which I should be doing?
2. I used the 3.3v output of the dev board to go across the voltage divider rather than the 5v and a 10k (measures 9170 ohms with my multi-meter so used that in my calcs) fixed resistor.I set the gain amplifier to 4.096 so wonder if it is better to switch to the 5v and/ or lower the fixed resistor to increase the range. According to my calcs at 20C the voltage across the probe is around 3v and at 105C around 1v.

Anything else I can try to get a more stable output.

Many thanks as ever

MicroController
Posts: 2045
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Controlling ADC with new I2C version

Postby MicroController » Thu Feb 06, 2025 8:28 am

leenowell wrote:
Thu Feb 06, 2025 7:55 am
1. When we discussed the design before I had thought the capacitor show go between the ADC pin and ground (essentially bi-passing the thermistor).
Yes, that is the idea. The decoupling capacitor at the supply side is mandatory for operation of the ADC in all cases. Capacitors on the analog inputs can be considered as signal conditioning and may or may not improve accuracy depending on properties of the signal source.
2. I used the 3.3v output of the dev board to go across the voltage divider rather than the 5v and a 10k (measures 9170 ohms with my multi-meter so used that in my calcs) fixed resistor.I set the gain amplifier to 4.096 so wonder if it is better to switch to the 5v and/ or lower the fixed resistor to increase the range. According to my calcs at 20C the voltage across the probe is around 3v and at 105C around 1v.
Yes, you get the best resolution out of the ADC if the signal uses as much of the ADC's range as possible.

Apparently you have pretty big fluctuations in the ADC readings; much bigger than I'd expect from an ADS1115, so I assume the input signal to be the main contributor.

Note that the ADS1115 has effectively 15 bits of resolution, so even at 4096mV range that's 1/8mV per count. You may get better results if you use all the bits, i.e. not calculate with integer milli-volts.

leenowell
Posts: 155
Joined: Tue Jan 15, 2019 1:50 pm

Re: Controlling ADC with new I2C version

Postby leenowell » Thu Feb 06, 2025 2:25 pm

Thanks very much for getting back to me - very useful. So at least I can rule out the ADS1115 as the problem. Also the probe itself gives a constant resistance at room temp (despite the ADC giving fluctuating results) so looks like there is something wrong with the circuit itself. It is all on a breadboard at the moment so wonder if that is a contributing factor. Removing the probe from the phono jack still gives fluctuating results but I guess that is expected as the ADC line is essentially floating? Will do some proper testing tonight and let you know.

I wasn't sure what you meant by your last comment though?

MicroController
Posts: 2045
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Controlling ADC with new I2C version

Postby MicroController » Thu Feb 06, 2025 4:59 pm

A bit of 'wiggle' in the ADC's readings is often unavoidable. As a test, you can try and measure any low-impedance voltage source directly, e.g. a simple AA battery; you should see fairly stable readings from the ADC (fluctuating +/- a few counts at most).

By "use all the bits" I mean that, if&when you convert an ADC reading to a voltage (on the ESP), you will want to avoid 'early' impairment of the resolution of the result. As we discussed, voltage = (reading * FSR)/32768. If you do the calculations with integers, and represent FSR in mV (e.g. 256 or 4096mV), you lose the sub-mV resolution in this step... Don't know if that's how you do it though. If you only take the raw ADC readings and for now do all calculations in a spreadsheet, loss of resolution is not an issue.

leenowell
Posts: 155
Joined: Tue Jan 15, 2019 1:50 pm

Re: Controlling ADC with new I2C version

Postby leenowell » Thu Feb 06, 2025 7:39 pm

Good idea re: battery. When I connected the battery, the ADC value was circa 15 it took a few readings/ seconds to build up to value and then bounced between 12323 and 12365. Does this imply the ADS1115 is faulty?

MicroController
Posts: 2045
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Controlling ADC with new I2C version

Postby MicroController » Fri Feb 07, 2025 10:30 am

leenowell wrote:
Thu Feb 06, 2025 7:39 pm
Does this imply the ADS1115 is faulty?
I don't think so. (12323...12365 would be about +/-20 counts, i.e. +/-0.06% FSR - not too bad, and additionally you may be picking up all kinds of EMI in the circuit, so...)


OTOH, the ADS1115 comes in at 6 to 3€ per chip from well-known parts suppliers. Seeing modules built with an "ADS1115" retail at 1,50€ or less, I sometimes wonder about the authenticity and quality of the chips on the modules.

MicroController
Posts: 2045
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Controlling ADC with new I2C version

Postby MicroController » Fri Feb 07, 2025 9:19 pm

Hmm. A little update:
Just ran the "battery experiment" with my ADS1115 on an ESP32-C3... Got rock-solid readings, not even twitching by 1 count (at 2048mV FSR, tested 8 and 64 SPS).

Full AAA battery:

Code: Select all

ADC-Value ch 0: 25341, 1583813uV, 1584mV
"Empty" AAA battery:

Code: Select all

ADC-Value ch 0: 18558, 1159875uV, 1160mV
(I believe I paid about 9€ shipped for the ADS1115 module back in the day.)

leenowell
Posts: 155
Joined: Tue Jan 15, 2019 1:50 pm

Re: Controlling ADC with new I2C version

Postby leenowell » Sat Feb 08, 2025 11:32 am

Thanks very much for your replies - very much appreciated. Also thanks for running the test your side that was very kind of you. I have now run a load of tests and think we are getting there :).

Firstly I think I got to the bottom of the battery test issue - the capacitor I put across the power supply wasn't in properly! So having fixed that, the battery test is much better although not as good as yours. Then adding a capacitor across the probe also seems to remove most (not all the noise). I have created some graphs to demonstrate the results (I plotted ADC and calculated mV for each test). All tests were done with a 104 capacitor (correctly inserted :)) across the power. Also for each reading I read the ADC 5 times and average the results.
Test 1 - the battery test
Test 2 - the probe with no capacitor across it
Test 3 - the probe with a 104 capacitor across it.
Test 4 - I disconnected the probe socket (and probe) from the circuit and measured the resistance of them over over time. i.e. the probe was inserted into the socket and I measured the resistance of both.

These are the results
Tests 1 and 2
Screenshot from 2025-02-08 11-11-02.png
Screenshot from 2025-02-08 11-11-02.png (137.77 KiB) Viewed 1678 times
Tests 2 and 3
Screenshot from 2025-02-08 11-11-10.png
Screenshot from 2025-02-08 11-11-10.png (125.5 KiB) Viewed 1678 times
A few observations
1. It take a while for the readings to settle down. This device will ultimately be battery powered so I was planning on sending it into deep sleep and wake up to read temp and go back to sleep. Based on these tests is looks like that isn't going to work?
2. The capacitor across the probe and the power makes a big difference. Given I am still getting some issues even in the battery test and the probe with capacitor I was wondering if a 104 capacitor (i.e. the little brown blobby ones with 104 written on them) is the right size/. one?
3. The probe seems to reduce resistance over time (shown in both tests 3 and 4) so was thinking this might be the probe heating up slightly as current goes through it. Does that sound likely? If so I guess I want to minimise the current - although I assume the multimeter will be sending minimal current through it to get the resistance so maybe that is not right?

Thanks once again for all your help with this - it is very much appreciated.

MicroController
Posts: 2045
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Controlling ADC with new I2C version

Postby MicroController » Sat Feb 08, 2025 1:00 pm

All a bit weird...
I'm wondering why the readings rise so slowly. Should be basically instantaneous. Especially with the battery as input signal.
"104" on a capacitor would be 10*10^4pF = 100'000pF = 100nF, checks out.
The multimeter in resistance mode will indeed send current through the probe. Not enough to cause heating, but possibly enough to generate enough additional voltage drop to be visible to the ADC. (I don't think you can measure resistance with a multimeter while there's some other current flowing through the resistor. - You should only try to measure voltage here.)
Some of the graphs look decent, except for the random spikes. If the spikes are not caused by you meddling with the setup, poor contact of the plug/jack is another likely explanation. Those headphone-jack type of connections are not known for the most reliable contact, and are notoriously sensitive to mechanical wiggling/rotating of the plug.
I was planning on sending it into deep sleep and wake up to read temp and go back to sleep. Based on these tests is looks like that isn't going to work?
May work no problem, depending on the sample rate you want. At 8 SPS, you have plenty of time to let the ESP light-sleep while the ADC is converting. At say 128 SPS, waking up once every second, taking one measurement, going back to deep sleep is also possible. (Waking up from deep sleep is 'expensive' though - doing a full boot of the chip each time, which takes a few hundred ms (of power) before your code can do anything.)

Another trick can be to take a reading, then set up the ADC's comparator with low and high thresholds close to that value and go to sleep until the ADC tells you via ALRT that the latest sample has deviated from the last one you read. This way, you can basically sleep forever when the analog signal stays steady. "Temporal run-length encoding" if you will ;-)
Thanks once again for all your help with this - it is very much appreciated.
You're welcome, I appreciate that :)

leenowell
Posts: 155
Joined: Tue Jan 15, 2019 1:50 pm

Re: Controlling ADC with new I2C version

Postby leenowell » Sat Feb 08, 2025 4:58 pm

Yeah definitely a puzzle this. Regarding the spikes in the tests, nothing moved during the tests as it was all on the work surface and connected to the laptop via USB and just sat there. I thought it might be useful for me to detail the wiring in case there is anything there that I might have done wrong. I have tried to do it exactly as I have it on the breadboard.
circuit_image (1).png
circuit_image (1).png (427.67 KiB) Viewed 1541 times
Only other potentially relevant information
1. the ADS1115 is actually one of these rather than the image from the drawing tool - https://www.ebay.co.uk/sch/i.html?_nkw= ... m570.l1313

2. The ESP is powered from the USB port of my laptop and the ADC from the 3.3v port on the dev board.

Good idea re: using the alert. If I can get this semi stable will look at that option next :)

Who is online

Users browsing this forum: Bing [Bot] and 121 guests