Searching \ for '[SX] SX/B Maths' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/ubicom/lib/math/index.htm?key=math
Search entire site for: 'SX/B Maths'.

Exact match. Not showing close matches.
PICList Thread
'[SX] SX/B Maths'
2008\06\09@214721 by CrustyNoodlen/a

flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, CrustyNoodle wrote:

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:



' 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?

---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=272864
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)

2008\06\09@220238 by VelocitąPaolan/a

flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, VelocitąPaola wrote:

You can still do everything in SX/B and decimal without having to think about it too much...  just replicate the equation in single steps using parenthetical order of operations, followed by "computer order of operations" (i.e. left to right).  They made it pretty easy by putting everything in parentheses though.  You might need to utilize a couple temporary word variables to get to the final value.


rhLin = soRh ** 26542 tmpW1 = soRh ** 3468
tmpW2 = soRh ** 3468
tmpW1 = tmpW1 * tmpW2
tmpW1 = tmpW1 + 50
tmpW1 = tmpW1 / 100 rhLin = rhLin - tmpW1
rhLin = rhLin - 40

The above equation can be further reduced to save memory space by eliminating the tmpW2 variable:


rhLin = soRh ** 26542 tmpW1 = soRh ** 3468
soRh = soRh ** 3468
tmpW1 = tmpW1 * soRh
tmpW1 = tmpW1 + 50
tmpW1 = tmpW1 / 100 rhLin = rhLin - tmpW1
rhLin = rhLin - 40

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 achieve 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.

---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=272864#m272865
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)

2008\06\09@224842 by JonnyMacn/a

flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, JonnyMac wrote:

Multiplication, division and related operators generate a fair bit of code; you might want to encapsulate ** into a function.  Delcare it like this:

MULT_HIGH       FUNC    2, 2, 4                 ' shell for **

The function code looks like this:

' Use: result = MULT_HIGH value1, value2
' -- if passing word and byte, pass word value as first parameter
FUNC MULT_HIGH
 IF __paramcnt = 2 THEN
   tmpW2 = __param1
   tmpW3 = __param2
 ELSEIF __paramcnt = 3 THEN
   tmpW2 = __wparam12
   tmpW3 = __param3
 ELSE
   tmpW2 = __wparam12
   tmpW3 = __wparam34
 ENDIF
 tmpW2 = tmpW2 ** tmpW3
 RETURN tmpW2
 ENDFUNC

---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=272864#m272872
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)

2008\06\10@150253 by CrustyNoodlen/a

flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, CrustyNoodle wrote:

OK thanks for all your help - I've got it working.

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.

---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=272864#m273013
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)

More... (looser matching)
- Last day of these posts
- In 2008 , 2009 only
- Today
- New search...