BasicMicro - Forums

www.basicmicro.com
It is currently Sun May 20, 2012 11:04 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Floating Point problems
PostPosted: Tue Oct 30, 2007 10:00 pm 
Offline
Citizen

Joined: Wed Mar 13, 2002 11:00 am
Posts: 32
Hi
I try to do this: 'BasicAtom40

hilf1.......var........float
pWidth...var........long
tHigh......var.......LONG
tLow.......var.......long
x............var.......byte
temp_C...var......float

start:................'read temperature of the SMT160-30 (1 wire duty-cycle output)
..FOR x = 1 TO 5
.....PULSIN 23, 1, pWidth
..........tHigh = tHigh + pWidth
.....PULSIN 23, 0, pWidth
..........tLow = tLow + pWidth
...............NEXT

‘ The Problem: This formula now should convert to Temperature in Celsius

..........tempC = ((float tLow FSUB float tHigh) -0,32)/0,0047

.....DEBUG [" Temp = ",SDEC TempC," °C",CR] 'show temp

...............goto start

I tried a lot of different formulas !!
Reading much in the forums!!
But did not find results.
The IDE gives always an error

Even the simple conversation to Float don’t work
like:
..........Hilf1 = float tLow

The IDE gives an error
How can I calculate :
Temp_C=((tLow/tHigh)-0,32)/0,0047 ??

Thanks Heinz


Top
 Profile  
 
 Post subject: Re: Floating Point problems
PostPosted: Tue Oct 30, 2007 10:00 pm 
Offline
Citizen

Joined: Wed Mar 13, 2002 11:00 am
Posts: 32
Hi allanlane thanks for your quick replay.

Oh ..I did not realize that the “/” operator is not working for floating-point,
even as I have seen it in the manual. Thanks for explanation.
About the “.” dot I though about too.
.
I changed the formula like this:

.. ..tempC = ((float tLow fdiv float tHigh) - 0.32) fdiv 0.0047

(the “FSUB” was a mistake)

But still an error from the IDE
I divided the formula in different parts, but still no way

…..But what I can not understand is that there is an error from the IDE
on this :

********……..hilf1 = FLOAT tLow…….**********

(hilf1 var float . . . tLow var long)

I believe that I use it like the manual shows:

“FLOAT expr”
or the example with “INT”
“x = INT y”
Page 63 ……….I use the IDE 05.3.1.0

I don’t find the right way to use it.
Some tip in the right direction would help me…

Thanks Heinz


Top
 Profile  
 
 Post subject: Re: Floating Point problems
PostPosted: Wed Oct 31, 2007 10:06 am 
Offline
Citizen

Joined: Sat Mar 08, 2003 11:00 am
Posts: 40
I don't think MBasic likes "," in its literals. I think it's using the 'American' format of
0.32 or 0.0047. Plus, 0.32 / .0047 is zero -- since the "/" operator is an INTEGER operator in MBasic. You probably want FDIV or FMULT.


Top
 Profile  
 
 Post subject: Re: Floating Point problems
PostPosted: Tue Nov 06, 2007 11:00 pm 
Offline
Citizen

Joined: Wed Mar 13, 2002 11:00 am
Posts: 32
Hi
I tried to convert my BasicStamp integer math to Atom floating point math
After a long time, I fond my correct formula.
It should be like this:
“tempC = (float tHigh fdiv (float tHigh fadd float tLow)fsub 0.32) fdiv 0.0047”

the biggest problem was the New IDE 5.3.1.0 it did not accept integer math.
The older version 02.2.1.1 accepted it. (why??)
I used the first time the Atom and did not aspect such problem und it needed some time before I got the idea to change to the older version.

I used 6 SMT 160
For someone who like to use the SMT 160, here is a subroutine :
Heinz

' 6 Stück SMT160-30 (one-pin pulse-width temperature sensor)
'Temperature in °C proportional to the (highpuls / (high puls + lowpuls))

Ta_Pin ...... CON AX3 'Fühler 6
TvB_Pin .... CON p27 'Fühler 5
TvH_Pin .... CON p26 ' 4
TrB_Pin .... CON p25 ' 3
TrH_Pin .... CON p24 ' 2
Ti_Pin ....... CON p23 'Fühler 1


'***** Variables ****************************
Tpin .......... VAR byte 'Pin nummer f Temp Messung
tHigh ....... VAR long 'Pulslänge vom High Puls
tLow ....... VAR long
pWidth ...... VAR long
TempC ...... VAR long
x .......... VAR byte

cr.............. con 13


start:
TPin=Ti_Pin
gosub getTemp

goto start

getTemp:
tHigh = 0: tLow = 0
FOR x = 1 TO 10
PULSIN TPin, 1, pWidth
tHigh = tHigh + pWidth
PULSIN Tpin, 0, pWidth
tLow = tLow + pWidth
NEXT

tempC =(float tHigh fdiv (float tHigh fadd float tLow)fsub 0.32) fdiv 0.0047

DEBUG ["Temp_I = ", real TempC," °C",CR] 'real number 8 digid
tempC = tempC fmul 10.0 '
tempC = int tempC
DEBUG ["Temp_I = ", dec TempC," °C",CR] ...... 'integer number 3 digit
................... return ...................................' later needed


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

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO