Home     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
   
 Home     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   

Author Topic: calibrating a sensor  (Read 18083 times)

0 Members and 1 Guest are viewing this topic.

cheerio

  • Sr. Member
  • ****
  • Posts: 306
calibrating a sensor
« on: May 19, 2013, 12:44:20 PM »
Not sure if this is really digitial or more analog diskussion.
Well i want to know how you calibrate a sensor. to be more precise i speak about a sensor that has an analog output that is converted by an ADC unit inside a MCU.
I always look for a linear offset first. After i have compensated that i do the following:
i write down the corresponding ADC value for a given sensor value. for ex. i write down ADC 50 for 10°C. then i increase th sensor value using a stepping that makes sense for the application. for ex. if i want to measure 0-500°C i would measure the ADC Value for each 10°C increase.
after that i have smth like this:
50, 10
55, 20
65, 30
75, 40
80, 50
...

what i do now is that i look for simmilar ADC increases per °C:

50, 10-> X
55, 20-> .5
65, 30-> 1
75, 40-> 1
80, 50-> .5
...

next step is to do a very nasty if else chain where i check if the ADC value is for ex. between 55 and 75 then i do the calc like this:
°C = 55+(ADC-20)*factor
where factor is 1 in this case


this works very accurate but it is very nasty to do and you always need a good reference sensor to do this.

How do you calibrate your sensors? do you have better ideas to compensate not linear errors?

kam

  • Administrator
  • Hero Member
  • *****
  • Posts: 1849
Re: calibrating a sensor
« Reply #1 on: May 19, 2013, 17:40:15 PM »
Are you trying to re-create the temperature to voltage characteristic???

cheerio

  • Sr. Member
  • ****
  • Posts: 306
Re: calibrating a sensor
« Reply #2 on: May 19, 2013, 19:46:01 PM »
yes

cheerio

  • Sr. Member
  • ****
  • Posts: 306
Re: calibrating a sensor
« Reply #3 on: May 27, 2013, 17:28:51 PM »
so this is how this is done?

kam

  • Administrator
  • Hero Member
  • *****
  • Posts: 1849
Re: calibrating a sensor
« Reply #4 on: May 28, 2013, 17:48:12 PM »
Well, its a way. But you really have to identify the curve (since its not linear).

Sir N

  • Newbie
  • *
  • Posts: 26
Re: calibrating a sensor
« Reply #5 on: June 27, 2013, 21:54:09 PM »
Hi,

next step is to do a very nasty if else chain [...]

this works very accurate but it is very nasty to do and you always need a good reference sensor to do this.
A look up table is way easier.

cheerio

  • Sr. Member
  • ****
  • Posts: 306
Re: calibrating a sensor
« Reply #6 on: June 27, 2013, 22:46:07 PM »
it is indeed. but at a huge expense of ram or flash memory. after all it would be the same procedure to calibrate. Do you know a better way to calibrate?



i read some of your posts Sir N and i am glad you found your way to this forum. You seem to be an experienced guy and a big gain for this small community. Welcome!

Sir N

  • Newbie
  • *
  • Posts: 26
Re: calibrating a sensor
« Reply #7 on: June 28, 2013, 01:27:20 AM »
Hi,

it is indeed. but at a huge expense of ram or flash memory.
It depends on how long a table you need of course, but don't underestimate the speed advantage of a table (compared to nested IF/ELSE chains). Further, most controllers above base line has got way more memory than you want to fill in assembler :)


after all it would be the same procedure to calibrate. Do you know a better way to calibrate?
If you refer to calibrating a single sensor from scratch, I'd look in the datasheet for starters. Most sensors have outputs that, if not linear, at least conform to a reasonably simple math function. The trick is to first define what tolerance you allow (be realistic here), then find a rough fitting function and bash it around until it's within your tolerance for all values. I'll see if I can come up with a blow-by-blow example once I'm back home.

It also depends on which sensor. A NTC resistor eg. can be rather linearized by adding a single parallel resistor - at the cost of less Ohm/°C

Do you have a particular sensor in mind and if, do you have a datasheet for it?


i read some of your posts Sir N and i am glad you found your way to this forum. You seem to be an experienced guy and a big gain for this small community. Welcome!
Thanks - I've been around the block a few times, and I hope that others may benefit from what I picked up along the way :)