Controlling ADC with new I2C version

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

Re: Controlling ADC with new I2C version

Postby leenowell » Thu Jan 09, 2025 7:41 am

Thanks for your replies as always. Will try the capacitor out and see if I get any better results. My voltage divider resistor is 10k so will try lowering that too then.

As for calibrating the probe, I was a bit concerned about whether it is fully waterproof. It is encased in a steel meat probe so I guess the probe itself must be waterproof whereas the top probably isn't. Will give your suggestion a try and see what happens.

Now need to figure out how to translate the raw value/ mV into the Steinhart equation (it takes resistance) to calculate the temp. I did it before so will have to unpack how I did it 😄

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

Re: Controlling ADC with new I2C version

Postby MicroController » Thu Jan 09, 2025 8:21 am

My voltage divider resistor is 10k so will try lowering that too then.
10k should be ok. 50k+ would be worth lowering.
Now need to figure out how to translate the raw value/ mV into the Steinhart equation (it takes resistance) to calculate the temp. I did it before so will have to unpack how I did it
Yes, Steinhart-Hart will be easier if you use resistance. So probably best to first convert ADC/mV into Ohm. Do you already know the A, B and C coefficients of the thermistor?

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

Re: Controlling ADC with new I2C version

Postby leenowell » Thu Jan 09, 2025 12:44 pm

The thermistor is 100k ohms at room temp and looking to measure food temperature so I guess a range of 0 to 100 C would be ok. Assume the 10k works ok for that?

The trouble I have is that the probe needs to be thin and have a pointed end to insert into the food it is measuring (e.g. meat). The only solution I have found is to buy replacement probes like these which are for existing digital thermometers and therefore don't come with any specs. -
https://www.ebay.co.uk/itm/373035375854

I you have resistances for 3 temperatures (either end of range and one in the middle) then there is an online calculator which calculates ABC for you.

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

Re: Controlling ADC with new I2C version

Postby leenowell » Sat Jan 11, 2025 5:38 pm

The good news is I have now cleaned up the setting of the config to make it readable in the code. As part of it I did some more thorough testing and it is behaving a bit oddly. I have connected a single read probe to each of the ADCs in turn and my code reads all 4 in turn by setting the config then reading the value each time. Surprisingly I got the following results (I have put EXPECTED to mean the result I expect the probe to read and NULL to show the reading I'm getting when nothing connected to the pin).
Pin Result from readings in code
ADC0 ADC0 = NULL; ADC1 = NULL; ADC2 = EXPECTED; ADC3 = EXPECTED
ADC1 ADC0 = NULL; ADC1 = NULL; ADC2 = NULL; ADC3 = NULL
ADC2 ADC0 = EXPECTED; ADC1 = EXPECTED; ADC2 = NULL; ADC3 = NULL
ADC3 ADC0 = NULL; ADC1 = NULL; ADC2 = NULL; ADC3 = NULL
My #define's for the various settings are

Code: Select all

#define ADS1115_DEFAULT_MASK_BYTE1	0x8383 [quote][/quote]
#define ADS1115_ADC0_CONFIG			0x4000 | ADS1115_DEFAULT_MASK_BYTE1
#define ADS1115_ADC1_CONFIG			0x5000 | ADS1115_DEFAULT_MASK_BYTE1
#define ADS1115_ADC2_CONFIG			0x6000 | ADS1115_DEFAULT_MASK_BYTE1
#define ADS1115_ADC3_CONFIG			0x7000 | ADS1115_DEFAULT_MASK_BYTE1
I initially thought it must be in comparitor mode in error but believe this is disabled with bits 0,1 being 1 - although doesn't explain why they seem to be flipped (i.e. ADC0 is detected on ADC2 and ADC3).

Edit - finally saw a post where someone had a similar thing and they issue was that the esp was reading the ADS1115 too quickly. So, I put a 1s delay between each read. The result was that only one ADC at a time read the EXPECTED value but they weren't at the right pin! It was rotated oddly
Pin ADC of reading
ADC0 ADC1
ADC1 ADC2
ADC2 ADC3
ADC3 ADC0
Any ideas?

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

Re: Controlling ADC with new I2C version

Postby MicroController » Sat Jan 11, 2025 7:34 pm

Any ideas?
Not many.
Could your timing be off?
As I sought to convey earlier, you have to configure + start a conversion, then wait, then read the result of the conversion you started.
Is that how you do it? - If you don't wait long enough (i.e. >7.8ms at 128 SPS, which means at least one 10ms tick in FreeRTOS) between starting a new conversion and reading a result, you will read the result of a previous conversion.

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

Re: Controlling ADC with new I2C version

Postby leenowell » Sun Jan 12, 2025 9:06 am

As usual.... spot on :)

I must have missed the instruction to wait between the write and the read - sorry.

My base config mask (ie all the config with the 3 bits for the ADC number set to 0) is 0x8383 which I believe sets the SPS rate (bits 5,6,7) to 100 which according to the spec is 128 SPS. I updated the code to add this delay after the write

Code: Select all

  	vTaskDelay(x / portTICK_PERIOD_MS);
Having tried various values for x, 10 is the minimum that makes it work (I would have assumed 9 as 1/128 is just under 8ms). I tried increasing the SPS to 860 (max for ADS1115) by changing the base config mask to 0x83E3 (setting bits 5,6,7 to 111) and interestingly the minimum working value for x is still 10. Any idea why? Also

I also run some tests comparing the ADS1115 and the ESP onboard ADCs with and without a cap. Thought I would write a new post on that so others could benefit but in summary the ADS1115 is much more stable with the ADC +/- 15 with the cap and around 19 without. For the ESP it was more like 130 vs 80. When I calculate the temp from it, it might be that neither has too much impact on the temp if I only want whole numbers.

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

Re: Controlling ADC with new I2C version

Postby leenowell » Sun Jan 12, 2025 10:19 am

I dug out my Steinhart equation work from before. The use of the ADS1115 complicates it a bit so wanted to double check my logic :)

My voltage divider is wired as follows

+Vc ------ R1 ------- Rp ------ gnd

Vc = is the 3.3v from the dev board
R1 = 10k
Rp = resistance of the thermistor needed for the SH equation
Vp is the voltage measured by the ADS1115

Using the ADS1115 ADC I get

Vp = ADC * (4.096/ 32767)

Then use this in the voltage divider equation to get Rp.

Rp = (R1*Vp) / (Vc - Vp)

Does this make sense?

I have also measured Vp with my multi meter against that calculated using the ADC and the calc one seems consistently 6mV. Doubt this makes a difference in the grand scheme of things but thought I would mention in case there is something wrong and this is a symptom of a potentially bigger problem.

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

Re: Controlling ADC with new I2C version

Postby MicroController » Sun Jan 12, 2025 2:15 pm

FreeRTOS's time base is a 'tick', with the default tick rate being 100Hz, i.e. 10ms/tick. This is both the minimum possible delay time and the granularity of time for FreeRTOS. portTICK_PERIOD_MS is 10, and because ticks are integer values, x/portTICK_PERIOD_MS is 0 if x < 10.

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

Re: Controlling ADC with new I2C version

Postby MicroController » Sun Jan 12, 2025 5:17 pm

My voltage divider is wired as follows

+Vc ------ R1 ------- Rp ------ gnd

Vc = is the 3.3v from the dev board
R1 = 10k
Rp = resistance of the thermistor needed for the SH equation
Vp is the voltage measured by the ADS1115
I'd say that should be
Rp = R1 / ((Vc/Vp)-1) = 10kOhm /((3.3V/Vp)-1)

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

Re: Controlling ADC with new I2C version

Postby leenowell » Sun Jan 12, 2025 5:56 pm

Thanks for checking it for me. I updated my spreadsheet with your calc and it seems to calculate the same resistance so suspect it is another way of doing it. The ADS1115 is working great now and very little variance on readings so think that bit is sorted. Trouble is that the calibration is all over the place. I posted another thread here ( viewtopic.php?f=13&t=43905 ) with the details but not sure if it is my method, the code or my calcs. If I calculate ABC coefficients using my best readings (i.e. those that were most stable ) then use those to calculate some of the other temps I can be out by 5 to 10 degrees C! Something is wrong but not sure what.

Who is online

Users browsing this forum: Applebot, Baidu [Spider], PerplexityBot and 18 guests