CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Sensor Calibration

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
JAM2014



Joined: 24 Apr 2014
Posts: 138

View user's profile Send private message

Sensor Calibration
PostPosted: Thu Feb 28, 2019 5:48 pm     Reply with quote

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: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Mar 01, 2019 6:41 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri Mar 01, 2019 8:05 am     Reply with quote

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: 303

View user's profile Send private message

PostPosted: Fri Mar 01, 2019 9:10 am     Reply with quote

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: 19499

View user's profile Send private message

PostPosted: Fri Mar 01, 2019 9:35 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 19, 2019 6:28 am     Reply with quote

One step solution: MCP9600.

Problem solved.
_________________
CCS PCM 5.078 & CCS PCH 5.093
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 19, 2019 7:19 am     Reply with quote

ahh,, that's 'cheating', using an $8 extra part.... Smile
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

View user's profile Send private message

PostPosted: Tue Mar 19, 2019 2:15 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group