Math with my SX?
Hey guys,
well i have a chip that i am interfacing to that gives me some variables an then i have to do some math with these values.· Can i do these functions internally with the SX.· Examples of structure would be greatly appreciated.
1.· Temp = 200+dT*(C2+50)/2^10············C2 and dT·are·know values and we are solving for Temp
2.· OFF = C2*4+((C4-512)*dT)/2^12··········C1 and·C3 are both know and we are solving for OFF
3.· SENS = C1+(C3*dT)/2^10+24576········ Again C1,C3 , and dT are known
4.· X = (SENS*D1-7168))/2^14-OFF
5.· P=X*10/2^5+250*10
6. dT=D2-UT1
7. UT1=8*C5+20224
Thanks in advance for all your help
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Post Edited (altitudeap) : 9/18/2006 6:20:31 PM GMT
well i have a chip that i am interfacing to that gives me some variables an then i have to do some math with these values.· Can i do these functions internally with the SX.· Examples of structure would be greatly appreciated.
1.· Temp = 200+dT*(C2+50)/2^10············C2 and dT·are·know values and we are solving for Temp
2.· OFF = C2*4+((C4-512)*dT)/2^12··········C1 and·C3 are both know and we are solving for OFF
3.· SENS = C1+(C3*dT)/2^10+24576········ Again C1,C3 , and dT are known
4.· X = (SENS*D1-7168))/2^14-OFF
5.· P=X*10/2^5+250*10
6. dT=D2-UT1
7. UT1=8*C5+20224
Thanks in advance for all your help
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Post Edited (altitudeap) : 9/18/2006 6:20:31 PM GMT
Comments
If you want to work dfirectly in assembly, go to this page:
www.sxlist.com/techref/expeval2.asp
It will take your math expression and convert it to code. It uses various functions that are accessible from this page:
www.sxlist.com/techref/ubicom/lib/math/basic.htm
I recommend starting with some simple examples (such as are on the first page) to get a handle on the way the code is written. It's a little more like the intermediate output of a compiler, but it's not too hard once you work with it a bit. OF course, you can also just directly use the math functions yourself to do the work.
I imagine this can also be handled with SX/B, but I'll leave that to those fluent in that language.
Thanks, PeterM
Can you give us the range of each variable (F, dT, A, B, C, D, temp) ?
Or some example values for them ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
There are only two guaranteed ways to become weathy.
Spend less than you make.
Make more than you spend.
·
Here we go.
Min typ. max
C1 17250 24285 30950
C2 600 1384 3350
C3 500 745 810
C4 200 405 1023
C5 0 932 1650
C6 10 28 63
D1 0 17000 40000
D2 0 22500 45000
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Okay, so which one is A, B, C, D, dT, and F ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
There are only two guaranteed ways to become weathy.
Spend less than you make.
Make more than you spend.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
I am learning SX/B and really do not understand C or C++ which is what this example is that i got from the pdf for the device that i am trying to use. I would like to recieve some help as to how to write it in SX/B
'
Calc
Void calcPT1234 (double *pressure, double *temperature, long d1_arg, long d2_arg)
{
double dt, off, sens;
double fd1, fd2, x;
d1_arg = d1_arg & 0xFFFF;
d2_arg = d2_arg & 0xFFFF;
fd1 = (double) d1_arg;
fd2 = (double) d2_arg;
dt = fd2 - ((8.0 * fc) + 20224.0);
off = fc * 4.0 + ((( fc - 512) * dt ) / 4096);
sens = 24576 + fc + 99 fc * dt) / 1024);
x = (( sens * (fd1 - 7168)) / 16384) - off;
if (pressure!=0)
* pressure = 250 + x / 32;
if (temperature!=0)
* temperature = 20 + (( dt * ( fc[noparse][[/noparse]6] + 50)) / 10240
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!