SX/B Maths
Hi,
I'm trying to get the sensirion SHT1x humidity sensor up and running with my SX28 and I'm having a little trouble...
I've adapted the example Basic Stamp code to mostly work under SX/B to the point whereby·I am able to get readings from the SHT1x and I am able to do the calcs to get the correct temperature however I can't get the humidity calcs to work - due to my inexperience/ignorance I suspect.
The code example to linearize the humidity reading is:
Note that soRH is a word variable that holds the reading from the SHT1x and rhLin is also defined as a word variable.
With Basic Stamp code to do this:
·So apart from the fact that I haven't managed to work out how we got from the first box to the second (I need to do more reading here) and that it would appear that SX/B can only do one math operation per line (I probably should have read this but ended up working it out by trial and error), I am still unable to replicate this code (or should I say the result from this code) using SX/B.
Is the answer straight forward or do I need to go back to school to learn about maths in binary and hex?
I'm trying to get the sensirion SHT1x humidity sensor up and running with my SX28 and I'm having a little trouble...
I've adapted the example Basic Stamp code to mostly work under SX/B to the point whereby·I am able to get readings from the SHT1x and I am able to do the calcs to get the correct temperature however I can't get the humidity calcs to work - due to my inexperience/ignorance I suspect.
The code example to linearize the humidity reading is:
' linearize humidity: ' rhLin = (soRH * 0.0405) - (soRH * 0.004 * soRH * 0.0007) - 4 '
Note that soRH is a word variable that holds the reading from the SHT1x and rhLin is also defined as a word variable.
With Basic Stamp code to do this:
rhLin = soRH ** 26542 rhLin = rhLin - ((soRH ** 3468) * (soRH ** 3468) + 50 / 100) rhLin = rhLin - 40
·So apart from the fact that I haven't managed to work out how we got from the first box to the second (I need to do more reading here) and that it would appear that SX/B can only do one math operation per line (I probably should have read this but ended up working it out by trial and error), I am still unable to replicate this code (or should I say the result from this code) using SX/B.
Is the answer straight forward or do I need to go back to school to learn about maths in binary and hex?
Comments
The above equation can be further reduced to save memory space by eliminating the tmpW2 variable and re-using soRh:
You don't need a complete understanding of binary to understand what they're doing (except for the multiply high operator, maybe). The main thing is to remember that the SX (and in turn, the BS2) can only do integer math. In order to complete mathematical operations such as multiplying by a decimal, they first multiply one of the multiplicands by a factor of ten, or however much it takes to make the decimal a whole number. The result is later divided by that same factor.
My code might be able to be even further simplified, but I think this way might be the easiest for you to see...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Paul
The function code looks like this:
In my travels to find information on SX/B Maths I found Tracy Allen's website (click the link) that has a wealth of information on the Basic Stamp including explanations on how to do complex maths.· For anyone who is struggling with the understanding of how to do floating point maths in an integer world this will help.