View Single Post
  #77  
Old 28-01-2018, 10:52 PM
Garbz (Chris)
Registered User

Garbz is offline
 
Join Date: May 2012
Location: Brisbane
Posts: 644
Quote:
Originally Posted by GRM View Post
I'd love to get a copy of your simplified formula for Dew Point. Below are the 3 versions I have been using. I don't know which one is more economical when it comes to microcontroller cycles.
Microcontrollers hate logarithms, floating point and division. However if you're just calculating a dew point and you don't have concerns about sleeping to save battery life then there's really no benefit. I'm using a slight variant of the "simple calc" formula you already listed:

Quote:
dew_point = t-(100-h)/5.0;
That one is an order of magnitude more efficient than the full formula.

I changed that to:

Quote:
dew_point = t-((100-h)*410>>11);
and I used deci-degrees for everything i.e. 15 = 1.5C The result is a pure simple integer maths and critically, no division. A floating point division takes 100s of instructions. A logical shift right takes a single instruction (or 11 in this case).

1>>11 = 1/(2^11) = 0.00048828125. If you pre-multiply by 411 you get 0.20068359375. Very close to what you get if you divide something by 5.

Okay that is probably all of no interest to you


But this here may be more interesting to you:

Below I've graphed the relative error for dew point calculations at 5C. Note at 0C the max error increases to +1.2C and at -5 it's +1.5C. However the dewpoint calculation error decreases the closer to the dewpoint you get. At 90%RH you're at 0.5C error.
Attached Thumbnails
Click for full-size image (Capture.JPG)
119.3 KB36 views
Reply With Quote