View previous topic :: View next topic |
Author |
Message |
JAM2014
Joined: 24 Apr 2014 Posts: 138
|
Sensor Calibration |
Posted: Thu Feb 28, 2019 5:48 pm |
|
|
Hi All,
I'm trying to figure out an algorithm to calibrate a thermocouple sensor. I have a thermocouple simulator that can apply known temperature values to my input, and I can then measure the A/D response converted to temperature via an initial Slope (M0) and Offset (B0). I've written code to prompt the user to set the simulator to a desired value, and then it measures the A/D and calculates the temperature. So, at the moment I've got a list of 'ideal temperatures', 'measured temperatures', and deviations at each temperature point. How do I calculate a new Slope (M1) and a new Offset (B1) to give me a calibrated thermocouple reading?
This tutorial is similar to what I want to do, but it's for a 2 point calibration:
https://learn.adafruit.com/calibrating-sensors/two-point-calibration
How do I do this with more data points?
Thanks,
Jack |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9253 Location: Greensville,Ontario
|
|
Posted: Fri Mar 01, 2019 6:41 am |
|
|
Can't help with the math at the moment but..
Be sure to use a precision reference for the ADC especially for 10bits ! unless that's rock stable (NOT VDD...) you'll never get good results. Also be sure VDD is 'clean' and use LOTS of 'bypass' caps, great grounds, etc.
Analog design, well, is challenging. |
|
|
dluu13
Joined: 28 Sep 2018 Posts: 395 Location: Toronto, ON
|
|
Posted: Fri Mar 01, 2019 8:05 am |
|
|
temtronic wrote: | Can't help with the math at the moment but..
Be sure to use a precision reference for the ADC especially for 10bits ! unless that's rock stable (NOT VDD...) you'll never get good results. Also be sure VDD is 'clean' and use LOTS of 'bypass' caps, great grounds, etc.
Analog design, well, is challenging. |
Very true. I've been jerked around with analog stuff when trying to mess around with ADC measurements when trying to do low-side current measurements. Thinking back I'm not sure why we tried low side in the first place... Anyway analog is not as straightforward as 1's and 0's that's for sure. |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 304
|
|
Posted: Fri Mar 01, 2019 9:10 am |
|
|
There are a lot of calibration options depending on what you want and need.
If you are calibrating amplifier gain & offset to a fixed curve, then two point calibration with points far apart.
If the curve is non-linear and you want to calibrate the entire thing you may be able to do a piece wise linear curve using point-slope between each two consecutive points. Depending on how close the points are and how much accuracy you need in between this can work well.
Multiple point calibration of a non-linear curve is possible but the math required will take a lot of ROM, RAM, and processing time. One way to offload this may be taking measurements and then sending them to a PC for the heavy processing and have the PC return a curve fit.
There is no one size fits all answer. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19562
|
|
Posted: Fri Mar 01, 2019 9:35 am |
|
|
Dead right.
I'm just doing a unit that fits a fifth order polynomial to a series of
points. Does it as an inverse matrix solution. On a DsPIC, it works well
and is quite quick, but I wouldn't want to even attempt this on a lesser
PIC. Both the RAM needed (when you have an array of 25 floating
point parameters, and then need to generate the inverse matrix as
well, a lot of room is used), and the arithmetic involves a total of
thousands of maths operations.
For a thermocouple, two different approaches:
Standard thermocouples have a published 3rd order
equation. All that calibration needs to do, is adjust the parameters
to that equation. So with four points (minimum), you can do simple
algebra to solve for the four parameters.
The second approach is to ignore the polynomial, and instead
do multi points over the entire range that the thermocouple is
to be used for, and then just do simple linear interpolation between
these points. Given that the response is actually very close to
linear, this works well. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Mar 19, 2019 6:28 am |
|
|
One step solution: MCP9600.
Problem solved. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9253 Location: Greensville,Ontario
|
|
Posted: Tue Mar 19, 2019 7:19 am |
|
|
ahh,, that's 'cheating', using an $8 extra part....
you could toss the 'data' into MATLAB and have it 'reverse engineer' the math, then code the derived equations and constants into your program....
Jay |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Mar 19, 2019 2:15 pm |
|
|
So to be clear you are attempting to read EMF with the PIC ADC?
Assuming a Type-K thermcouple and 3.3v PIC and 10 bit ADC you have a 3.22 mV step size.
which means you could only resolve increments of about 79°C assuming linear thermocouple voltages.
https://www.thermocoupleinfo.com/type-k-thermocouple.htm
Without a dedicated EMF amplifier/ Thermocouple IC I don't know what you are expecting to happen.
Or am I missing something?
EDIT: I Just noticed this is an old thread... i had not checked the forum in a while...sorry for the bump _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
|