BasicMicro - Forums

www.basicmicro.com
It is currently Sat Feb 04, 2012 6:51 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Float/decimal math Help!
PostPosted: Thu Apr 22, 2010 6:35 am 
Offline
Citizen

Joined: Wed Feb 10, 2010 1:09 pm
Posts: 16
Hello all; little question about the math functions. I will display my simple code and explain what I'm getting and what I should be getting.

PROCESS:
zero = 0
low 28:pause 100
result = 0
for i=0 to 64
ADin 28,2,AD_RON,temp2
result = result + temp2
next
result = result >> 4
if (zero = 0) then
lowend = result
zero = 1
endif


SLOPE = ((sizelimit - 0) / (4095 - lowend))

OFFSET = (0 - (SLOPE * lowend))

READING = ((SLOPE fmul RESULT) + OFFSET)


Now I omitted a few lines of code that weren't pertaining to my question. The lines in bold is what i am running into problems with. When calibrating our instrument, the instrument will be turned on with the lowest possible input coming in on the analog input. This analog input is summed 64times and shifted to get a value between 815-4095.(12bit) I had code to display my 'lowend' and 'result' prior to the slope/offset calculations to verify that my #s were correct before operating on them. They indeed were, lowend was reading 841 for my test. I was using floating point math in my slope/offset calcs and when I did that, I was getting 400.9 for my reading, which should have been 0.0. When Itest it as shown above I get 0.0 no matter what input I use.I also get 0 for slope and 0 for offset as well.

Any ideas on what I'm doing wrong?

Here is the slope/offset code for my other test:

SLOPE = ((float sizelimit fsub 0.0) FDIV (4095.0 FSUB 824.6041))
OFFSET = (0.0 FSUB (SLOPE FMUL 826.6041))
READING = ((SLOPE fmul float RESULT) fadd OFFSET)


Top
 Profile  
 
 Post subject: Re: Float/decimal math Help!
PostPosted: Thu Apr 22, 2010 11:25 am 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
Hello, Brock.
What kind of Atom are you using? From the syntax in the code, I'd say you are using the 2.2.1.1 compiler.
Am I correct?
Basic Micro no longer supports legay IDEs like this anymore, everything is now Studio_2x. You really should consider updating to the latest IDE version. There is a downside: syntax and timings have changed. And the manual is here on the forums, and is woefully incomplete.
However, there are still people here who know the old code, and may be available to assist you. Even BMicro's programmer visits here on a regular basis now.
'Luck!
kenjj

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: Float/decimal math Help!
PostPosted: Thu Apr 22, 2010 1:09 pm 
Offline
Citizen

Joined: Wed Feb 10, 2010 1:09 pm
Posts: 16
I'm definitely using the 2.2.1.1 compiler(as you can see from my other question in the thread about while..wend loops) :( ! This code I'm working with was written back in '04 so that would explain it. Thanks again.


Top
 Profile  
 
 Post subject: Re: Float/decimal math Help!
PostPosted: Fri Apr 23, 2010 6:56 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 784
Location: Temecula, CA
If you can, move to the latest Studio version 1.0.0.24. If you have trouble updating to Studio post your code and we'll try to help convert it.

_________________
Nathan Scherdin
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO