How to implement temperature compensation for multiple temperature sources? - Page 1
Forum section: electronics / projects

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: July 19, 2022, 09:28:58 am
content: Hello everyone,I’m working on a project that samples data with an ADC and then transforms the data before sending it to a computer. All the measuring is done by a microcontroller.The electronics vary significantly over temperature and I’m unsure as to how to go about solving this in a good way.The problem is that there are two temperature sensitive parts of the circuit that are exposed to two different temperature sources that in turn are independent from one another.One part is the actual sensor that is exposed to the measurement medium, and the other is the analog electronics that measure the sensors potential and convert it to a digital signal for the processor (simplified). The sensor "head" is insulated which prevents the heat from traveling to the PCB.All tests were performed with a static temperature stable measurement medium and identical software and hardware versions.I drew a picture to try and illustrate the system.This is a typical example letting it run on my bench. The temperature varied roughly 0.5 C during the 3-hour period.The ADC varies roughly 50 LSBs and you can see some sort of correlation between the ambient temperature and the RAW ADC value.Similar results can be seen when running it in a temperature stable environment, even if run for multiple days.Below image is from a test in a temperature cabinet where both electronics and sensor are inside it. It was set to 50 C for a few hours before recording the data to ensure that everything had an equal temperature. The test was performed for 45 hours, the first hour being 50 C and then switching the cabinet over to 20 C.The ADC value varies roughly 2000 LSB's over the entire temperature sweep but only 50 LSB's once the temperature has stabilized.The "Housing temperature" is the temperature of the sensors housing not the temperature of the cabinet.Here is an additional test where only the sensor is inside the cabinet while the electronics are on the outside exposed to room temperature and humidity.You can clearly see that the sensor is affected by the temperature, just not as much as when the entire thing is subjected to elevated temperatures.My question for all of you is how do I go about compensating for this?My thought is to weight each temperature sensor reading and combine them to make some sort of "global" temperature that I can use to scale the ADC value.The relationship doesn’t seem to be completely linear, so some sort of polynomial curve fitting is probably needed.But im not completely sure how to make robust implementation of this.I’m sure that I’m not the only person who has this issue but searching on the internet doesn’t return too much applicable in this case.I want to avoid doing complex real-time math since processor isn’t very powerful, being 8-bit and all. Running a temperature sweep for each board + sensor together is reasonable but plotting the output and calculating some sort of curve fitting for each is not. A general equation could be constructed from multiple tests and the sweep would adjust the constants unique for each board. It is not reasonable to run temperature sweeps for the individual parts every time like following.Il be making a few dozen of these every year and sweeping the temperature takes half a day so id prefer not to do it for every combination of the two.I’ve also been thinking of heating the analog side to 60 C and keeping it stable above ambient temperature for little to no variance. I’m aware that serious instruments use this approach but id like to avoid it since it adds an extra layer of complexity. I’m also not sure how to create a streamlined economically viable "PCB mounted" heat chamber that also does not effect the measurement.As aside note as I know some will ask:I have done significantly more tests than I’m posting. Reason for not posting them is that many tests were performed with an older software version so it’s an apples to oranges comparison. I’m currently redoing all tests which takes roughly a week so will add them as time goes if there is any interest in it.The trend is however the same which is why I’m posting this now and not just waiting a week.Any help is appreciated!

author: Anders Petersson
author_rank: Regular Contributor
timestamp: July 21, 2022, 07:41:23 pm
content: The temperature effect on the sensor is independent of the temperature effect on the analog circuit and thus are best treated separately. The uncorrected analog signal (with error caused by deviation from calibration temperature) is the input to the analog circuit with a separate temperature deviation that obscures the uncorrected analog signal. If you have a mathematical model of each part, for example a series oftemperature/error points, you can count backwards first from uncorrected digital signal to temperature-corrected analog signal, then to temperature-corrected sensor reading.You might be able to analyze the two parts separately by disconnecting them from each other and measure/simulate the range of the signals. If you're lucky, it can turn out only one of the two needs annually updated temperature profile.

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: July 22, 2022, 07:24:22 am
content: Thanks for the input.If you have a mathematical model of each part, for example a series of temperature/error points, you can count backwards first from uncorrected digital signal to temperature-corrected analog signal, then to temperature-corrected sensor reading.Unfortunately, I don’t have a mathematical model of the system, I’ve done similar things but it was a long time ago.You might be able to analyze the two parts separately by disconnecting them from each other and measure/simulate the range of the signals. If you're lucky, it can turn out only one of the two needs annually updated temperature profile.This has been my approach, trying to gather as much data as possible through controlled tests. This isn’t the easist since both parts are needed for it to function properly.I’ve runt them both in the test-chamber according to the following table (all combinations).The main issue is that I only have one chamber so the part that is outside (cold) is exposed to the variable temperature in the room. The room temperature is mostly constant but is still not ideal.I created a simple compensation routine in the processor for testing.The sensors temperature drift seems to be completely linear while the analog electronics seem to be exponential (described with a second order polynomial expression).The temperature compensation can be seen in the figure below.Where "Temp_SensorScaleFactor" and "Temp_AmbientScaleFactor" are the corresponding ADC LSBs/C.TestsThese tests were performed with the entire device inside the temperature chamber, the temperature was sweeped from 20 C to 50 C then back down to 20 C.I’m currently performing a test series with all heating configurations, it takes roughly one day to complete one but will get back with the results.As can be seen in the last image, its a clear improvement over the non temperature compensated value.The question is if it would give good results if only one part was heated while the other is not.

author: Anders Petersson
author_rank: Regular Contributor
timestamp: July 22, 2022, 12:02:35 pm
content: By "mathematical model" I simply mean the effect of temperature put into numbers. It can be based on measured values and interpolated linearly. If better matching is needed, you can use some curve-fitted function.You're not treating the system as two independent parts. Your equation for temperature compensation is on the form ADC_tempcomp = ADC_raw + f(Temp_sensor) + g(Temp_electronics) and your tests change the temperatures of both parts.I instead suggest this model:analog_signal = f(actual_property, Temp_sensor)adc_value = g(analog_signal, Temp_electronics)Then you need to figure out the functions f and g. These are independent from each other. When you have approximated the functions, you can reverse them:analog_signal = g_reverse(adc_value, Temp_electronics)actual_property = f_reverse(analog_signal, Temp_sensor)The point is that you first apply g_reverse() and then apply f_reverse() *on the result* instead of summing up two terms as your equation for temperature compensation does. Now you can derive actual_property from adc_value, Temp_electronics and Temp_sensor.I find it easiest to use mathematical terms here but in practice it can be done as basic programming.In order to analyze f and g you're really well-served to keep the other part of the system constant so you can investigate a single variable at a time, for example replacing the sensor by a constant voltage or resistor. Minimize the mathematical complexity. Select a baseline temperature.BTW, I suggest that you always specify if temperature numbers are for the sensor or electronics, not just "temperature". Your graphs would be easier to read.

author: mikerj
author_rank: Super Contributor
timestamp: July 22, 2022, 12:35:14 pm
content: Quote from: Sudo_apt-get_install_yum on July 22, 2022, 07:24:22 amWere the electronics AND the sensor in the chamber? You need to isolate the two effects. Could you replace the sensor with a stable signal (e.g. a precision resistor, voltage or current according to whatever the sensor produces) and then sweep the electronics temperature? You probably want to perform sweeps at multiple different (dummy) sensor outputs to see if this impacts the temperature coefficient.Once you have added compensation for the electronics, sweep the sensor temperature only and then add compensation for that.