EmbeddedRelated.com
Forums

Sensirion RH sensor Temp Compensation using an 8 bit PIC

Started by K Ludger October 24, 2008
I'm trying to implement temperature compensation on a Sensirion SHT11 RH 
sensor.

I've got most of it up & going using a 16F628 + *assembler* but I am having 
a hard time wtih the temp compensation - in particular - all of it!

While I'm not looking for an exactly correct calculation, it'd be nice to be 
in the ball park. (Yes I know, how long is a piece of string....)


From the data sheet for a 12 bit RH measurement:

Temp Comp in %RH = (Temp - 25)[0.01 + 0.00008.(ADC value)] + RHuncompensated



I've done the RGH calcs based on a x10 calculation to get resolution to 0.1% 
etc. Multiplying the above by 10 gives:

Temp Comp in %RH x 10 = (Temp - 25)[0.1 + 0.0008.(ADC value)] + 
10.RHuncompensated



I've done a heap of searching and can only find information on the 
linearisation process, not temp compensation. What's going to be the 
simplest approach to doing this in assembler on an 8 bit pic?

All suggestions greatfully received!






K Ludger wrote:

> I'm trying to implement temperature compensation on a Sensirion SHT11 RH > sensor. > > I've got most of it up & going using a 16F628 + *assembler* but I am having > a hard time wtih the temp compensation - in particular - all of it! > > While I'm not looking for an exactly correct calculation, it'd be nice to be > in the ball park. (Yes I know, how long is a piece of string....) > > From the data sheet for a 12 bit RH measurement: > > Temp Comp in %RH = (Temp - 25)[0.01 + 0.00008.(ADC value)] + RHuncompensated > > I've done the RGH calcs based on a x10 calculation to get resolution to 0.1% > etc. Multiplying the above by 10 gives: > > Temp Comp in %RH x 10 = (Temp - 25)[0.1 + 0.0008.(ADC value)] + > 10.RHuncompensated > > I've done a heap of searching and can only find information on the > linearisation process, not temp compensation. What's going to be the > simplest approach to doing this in assembler on an 8 bit pic? > > All suggestions greatfully received!
You don't need dynamic range you are looking for precision. The first question you need to ask is What do you want to know about RH? How much precision? The result is always between 0..100 (one byte is good to .5%) The compensation is a two term polynomial dominated by temperature. 1% of the temperature change from 25 degrees. What will your working temperature range be? The second term has two parts 8 parts/ 100K of reading value with a little adjustment for temperature. Is this adjustment going to affect your requirements? Answer these questions and implementation will be a lot easier to design. Regards -- Walter Banks Byte Craft Limited http://www.bytecraft.com

"Walter Banks" <walter@bytecraft.com> wrote in message 
news:4901C9E7.5B82ABC3@bytecraft.com...
> > > K Ludger wrote: > >> I'm trying to implement temperature compensation on a Sensirion SHT11 RH >> sensor. >> >> I've got most of it up & going using a 16F628 + *assembler* but I am >> having >> a hard time wtih the temp compensation - in particular - all of it! >> >> While I'm not looking for an exactly correct calculation, it'd be nice to >> be >> in the ball park. (Yes I know, how long is a piece of string....) >> >> From the data sheet for a 12 bit RH measurement: >> >> Temp Comp in %RH = (Temp - 25)[0.01 + 0.00008.(ADC value)] + >> RHuncompensated >> >> I've done the RGH calcs based on a x10 calculation to get resolution to >> 0.1% >> etc. Multiplying the above by 10 gives: >> >> Temp Comp in %RH x 10 = (Temp - 25)[0.1 + 0.0008.(ADC value)] + >> 10.RHuncompensated >> >> I've done a heap of searching and can only find information on the >> linearisation process, not temp compensation. What's going to be the >> simplest approach to doing this in assembler on an 8 bit pic? >> >> All suggestions greatfully received! > > You don't need dynamic range you are looking for precision. The first > question > you need to ask is > > What do you want to know about RH? > How much precision?
0.1% precision, I've used a modified (multiplied by 10) version of Sensirions 2 segment linearisation and this seem work ok.
> > The result is always between 0..100 (one byte is good to .5%) > > The compensation is a two term polynomial dominated by temperature. > 1% of the temperature change from 25 degrees. > > What will your working temperature range be? >
Working temp range is 0C - 50C (32F - 120F)
> The second term has two parts 8 parts/ 100K of reading value > with a little adjustment for temperature. > > Is this adjustment going to affect your requirements? >
At 50% RH the TC is ~0.12%/C. Over a temp range of say 10-->40C this would be ~3% which would be significant as the SHT11 sensor is good for around 3%
> Answer these questions and implementation will be a lot easier to design. > > > Regards > > -- > Walter Banks > Byte Craft Limited > http://www.bytecraft.com > >
"K Ludger" <kjhi@hjhk.org> writes:

> I'm trying to implement temperature compensation on a Sensirion SHT11 RH > sensor. > > I've got most of it up & going using a 16F628 + *assembler* but I am having > a hard time wtih the temp compensation - in particular - all of it! > > While I'm not looking for an exactly correct calculation, it'd be nice to be > in the ball park. (Yes I know, how long is a piece of string....) > > > From the data sheet for a 12 bit RH measurement: > > Temp Comp in %RH = (Temp - 25)[0.01 + 0.00008.(ADC value)] + RHuncompensated
What does the "(ADC value)" represent? How is it represented? The second "." in "0.00008.(ADC value)" is an asterisk?
> I've done the RGH calcs based on a x10 calculation to get resolution to 0.1% > etc. Multiplying the above by 10 gives: > > Temp Comp in %RH x 10 = (Temp - 25)[0.1 + 0.0008.(ADC value)] + > 10.RHuncompensated > > I've done a heap of searching and can only find information on the > linearisation process, not temp compensation. What's going to be the > simplest approach to doing this in assembler on an 8 bit pic?
Scaled, fixed-point arithmetic.
> All suggestions greatfully received!
K Ludger wrote:
> > I'm trying to implement temperature compensation on a Sensirion > SHT11 RH sensor. I've got most of it up & going using a 16F628 + > *assembler* but I am having a hard time wtih the temp compensation > - in particular - all of it! While I'm not looking for an exactly > correct calculation, it'd be nice to be in the ball park. (Yes I > know, how long is a piece of string....)
What you have to handle is the math, not the language. In general these things follow an S shaped curve, which can be nicely fitted to a 3rd order polynomial. I have no idea whether your system varies sufficiently that you will need to fit to the individual sensor. At any rate, look up the literature on least squares fits. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home.att.net> Try the download section.

"CBFalconer" <cbfalconer@yahoo.com> wrote in message 
news:49023ED7.815618E6@yahoo.com...
>K Ludger wrote: >> >> I'm trying to implement temperature compensation on a Sensirion >> SHT11 RH sensor. I've got most of it up & going using a 16F628 + >> *assembler* but I am having a hard time wtih the temp compensation >> - in particular - all of it! While I'm not looking for an exactly >> correct calculation, it'd be nice to be in the ball park. (Yes I >> know, how long is a piece of string....) > > What you have to handle is the math, not the language. In general > these things follow an S shaped curve, which can be nicely fitted > to a 3rd order polynomial. I have no idea whether your system > varies sufficiently that you will need to fit to the individual > sensor. At any rate, look up the literature on least squares fits. >
True - the math is the problem, I mentioned that I was doing it in assembler as I need to any/all math long hand. It's only a 1st order linear calculation needed, I thought someone may have "been there, done that". Thanks.

"Everett M. Greene" <mojaveg@mojaveg.lsan.mdsg-pacwest.com> wrote in message 
news:20081024.79D07D0.6B32@mojaveg.lsan.mdsg-pacwest.com...
> "K Ludger" <kjhi@hjhk.org> writes: > >> I'm trying to implement temperature compensation on a Sensirion SHT11 RH >> sensor. >> >> I've got most of it up & going using a 16F628 + *assembler* but I am >> having >> a hard time wtih the temp compensation - in particular - all of it! >> >> While I'm not looking for an exactly correct calculation, it'd be nice to >> be >> in the ball park. (Yes I know, how long is a piece of string....) >> >> >> From the data sheet for a 12 bit RH measurement: >> >> Temp Comp in %RH = (Temp - 25)[0.01 + 0.00008.(ADC value)] + >> RHuncompensated > > What does the "(ADC value)" represent? > How is it represented?
Sorry - I was unclear, the ADC value is the value returned from the sensor, it is used to calculate RHuncompensated (0/1000 in 2 x 8 bit bytes representing 0-->100.0% RH)
> The second "." in "0.00008.(ADC value)" is an asterisk?
Yes the second "." represents "*" or multiplication.
On Fri, 24 Oct 2008 14:27:46 +0800, "K Ludger" <kjhi@hjhk.org> wrote:

> >I'm trying to implement temperature compensation on a Sensirion SHT11 RH >sensor. > >I've got most of it up & going using a 16F628 + *assembler* but I am having >a hard time wtih the temp compensation - in particular - all of it! > >While I'm not looking for an exactly correct calculation, it'd be nice to be >in the ball park. (Yes I know, how long is a piece of string....) > > >From the data sheet for a 12 bit RH measurement: > >Temp Comp in %RH = (Temp - 25)[0.01 + 0.00008.(ADC value)] + RHuncompensated > > > >I've done the RGH calcs based on a x10 calculation to get resolution to 0.1% >etc. Multiplying the above by 10 gives: > >Temp Comp in %RH x 10 = (Temp - 25)[0.1 + 0.0008.(ADC value)] + >10.RHuncompensated > > > >I've done a heap of searching and can only find information on the >linearisation process, not temp compensation. What's going to be the >simplest approach to doing this in assembler on an 8 bit pic? > >All suggestions greatfully received! > > > >
I have just developed a complete temp/humidity sensor with this part and have all the code in C, so I thought I would respond. By the way, they work very nicely and its easy to check their accuracy at various humidities with pure chemical salts, one of which harmless table salt. Google up "salts humidity". You could also use a 30,000 dollar Thunder Scientific chamber. If you have the time, do it right. That means 1. Establish the accuracy and precision of the humidity result your micro will report or use to make a decision. (Do you really need to temp comepensate the humidity, or can you ignore the uncertainty due to temperature) 2. Getting the correct sequence of calculations on a piece of paper without regard to resolution. 3. Determine the size of the variable and signed-ness (ie signed or unsigned) needed to implement step 2. 4. Juggle it around-- maybe its better to replace a second or third order polynomial calculation with a piecewise linear fit to that polynomial. 5. Implement the math with the prewritten assembly routines provided in the microchip app notes, such as X*X signed or usigned addition, subtraction, multiplication, division They have assembly routines for X=8 to 32 bits, including 24 bits. ( I would avoid 24) Oh, and always assume the sensor is going to fail and make sure your math responds like you would want it to.
"K Ludger" <kjhi@hjhk.org> writes:
> "Everett M. Greene" <mojaveg@mojaveg.lsan.mdsg-pacwest.com> wrote > > "K Ludger" <kjhi@hjhk.org> writes: > > > >> I'm trying to implement temperature compensation on a > >> Sensirion SHT11 RH sensor. > >> > >> I've got most of it up & going using a 16F628 + *assembler* > >> but I am having a hard time wtih the temp compensation -- > >> in particular - all of it! > >> > >> While I'm not looking for an exactly correct calculation, > >> it'd be nice to be in the ball park. (Yes I know, how long > >> is a piece of string....) > >> > >> > >> From the data sheet for a 12 bit RH measurement: > >> > >> Temp Comp in %RH = (Temp - 25)[0.01 + 0.00008.(ADC value)] + > >> RHuncompensated > > > > What does the "(ADC value)" represent? > > How is it represented? > > Sorry - I was unclear, the ADC value is the value returned from > the sensor. It is used to calculate RHuncompensated (0/1000 in > 2 x 8 bit bytes representing 0-->100.0% RH)
Represented how? You're making it sound as if you're getting four BCD digits. If, as is more likely, the ADC value is something in binary, what magic incantation is used to convert it to RHuncompensated?
> > The second "." in "0.00008.(ADC value)" is an asterisk? > > Yes the second "." represents "*" or multiplication.
K Ludger wrote:
> "CBFalconer" <cbfalconer@yahoo.com> wrote: >> K Ludger wrote: >> >>> I'm trying to implement temperature compensation on a Sensirion >>> SHT11 RH sensor. I've got most of it up & going using a 16F628 >>> + *assembler* but I am having a hard time wtih the temp >>> compensation - in particular - all of it! While I'm not looking >>> for an exactly correct calculation, it'd be nice to be in the >>> ball park. (Yes I know, how long is a piece of string....) >> >> What you have to handle is the math, not the language. In general >> these things follow an S shaped curve, which can be nicely fitted >> to a 3rd order polynomial. I have no idea whether your system >> varies sufficiently that you will need to fit to the individual >> sensor. At any rate, look up the literature on least squares fits. > > True - the math is the problem, I mentioned that I was doing it in > assembler as I need to any/all math long hand. It's only a 1st > order linear calculation needed, I thought someone may have "been > there, done that".
Yes, I have. The math is simple. And believe me, you do want to fit a 3rd order polynomial of the form y = ax*x +bx +c. The problem is to select the optimum values for a, b, and c. When you have them correct the 1st derivatives will all be zero. The operations consist of forming some summations and then solving three simultaneous equations. You want at least 4 experimental points, 5 or 6 up is better. I am far too old and retired to work it all out, but it is all in the literature. Has been for about 200 years. I think Margenau and Murphy's book is probably the clearest. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home.att.net> Try the download section.