Single and floatmath
mosquito56
Posts: 387
· I am getting more into the prop chip and have found myself trying to get some decent output on the screen. I am using the r/c decay method to read a value. The value is working fine but it's in the billiions.
· I have tried the >> method to eliminate the lsb's but the minute I try to add or subtract my screen goes nut's.
· I then tried floatmath but it has something called a single? What is a single?
· I found an explination on how to convert to a usable scale, but with so much info to assimulate I just don't remember where I read it.
·term.str(string("Temperature· is .."))
·tempss:=temp.main··· 'get a value from the curcuit works fine
·setpos(26,9)········ ' using Pc_Interface works fine until I try to do math
·term.dec(tempss>>5)·· 'works but number still to high
·tempor:=(f.FDiv(tempss,100.0))· ' This LOCKS UP THE CHIP
·waitcnt(clkfreq/500+cnt)······· 'Thought floatmath was slow so gave it a chance to work.
·term.out($0D)··········· 'added in case number was way off screen
·term.dec(tempor)
Any suggestions on how to do this·converting r/c to scale would be appreciated.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mosquito: An animal which buzzes in your ear and never stops. He may byte you, he may nibble you, but you will know you were bit.
·A good engineer borrows from others, a great engineer steals everything outright!!
· I have tried the >> method to eliminate the lsb's but the minute I try to add or subtract my screen goes nut's.
· I then tried floatmath but it has something called a single? What is a single?
· I found an explination on how to convert to a usable scale, but with so much info to assimulate I just don't remember where I read it.
·term.str(string("Temperature· is .."))
·tempss:=temp.main··· 'get a value from the curcuit works fine
·setpos(26,9)········ ' using Pc_Interface works fine until I try to do math
·term.dec(tempss>>5)·· 'works but number still to high
·tempor:=(f.FDiv(tempss,100.0))· ' This LOCKS UP THE CHIP
·waitcnt(clkfreq/500+cnt)······· 'Thought floatmath was slow so gave it a chance to work.
·term.out($0D)··········· 'added in case number was way off screen
·term.dec(tempor)
Any suggestions on how to do this·converting r/c to scale would be appreciated.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mosquito: An animal which buzzes in your ear and never stops. He may byte you, he may nibble you, but you will know you were bit.
·A good engineer borrows from others, a great engineer steals everything outright!!
Comments
your smaller problem is this:
This is what's meant by "single precision floating point format" all routines (except FLOAT will need this special format, so you have to convert it. The IDE is able to do this for CONSTANTS (as 100.0) for itself.
This format however is not acceptable to any DEC routine. You will have to convert it into a string. There is very handy object called FloatString to do that.
However I see another problem.. Is it correct that your read temp value is such high? What does it mean? You need to understand how this value is generated...
Post Edited (deSilva) : 12/28/2007 9:02:11 PM GMT
··· I could
··· a.slow down the computer·: not possible
·· b. Give the cap less time to charge:··· fixes this problem but what about next time?
·· c. Decrease resistor: Same as b
I need to learn how to manage numbers. That is the first thing every language teaches you.
··
I found your posts awhile ago and noticed that you were having troubles with float also. I just downloaded the files from object exchange. The salespitch says does not need a seperate cog to run but is slow. Then Paul says that the startup needs to be run first. The startup starts a new cog. I want to save my cogs for other areas.
·I am up the same creek as usual.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mosquito: An animal which buzzes in your ear and never stops. He may byte you, he may nibble you, but you will know you were bit.
·A good engineer borrows from others, a great engineer steals everything outright!!
One approach is to once determined the range the number can take, scale it and use fixed 16.16 arithmetic. that works like integer arithmetic, fast and has some decimal places.
Another is to use directly floating point, all the way to avoid many conversions.
The last is to do all as integers.
Anyway the range of your quantities has to be limited (not all values are physically meaningful) and to deal with out of scale numbers gracefully.
There is no need for COGs.
Just stay with FloatMath until you need more advanced features!
My posting you are most likely referring to was one of a very advanved issue with instantiation of multiple Flaot32. This was some time ago, and this was when I recognized that you will not necessarily get the right answers here in the forum. That was when I decided to write the Tutorial. I know is has helped others.
So back to you: FloathMath and FloatString are very simple no-nonsense objects, so learn how to use them (which is extremely simple, FloatString has extensive comments inside)
RC-Decay has to be adapted to your needs. It makes no sense to wait for more than miliseconds, as the accuracy will not become better, so when you know the range of your resistor, chooses the cap accordingly!
Also: I see no reason why you could not use the large integer numbers... The Propeller is build to work with large numbers
P.S.: Hope this will not be classified as one of the "rude mails"
Post Edited (deSilva) : 12/28/2007 9:26:57 PM GMT
I just want to know something about why
tempor:=(f.FDiv(tempss,100.0)) doesn't work.
I could be wrong but I thought that was my original post. How do I scale a large number?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mosquito: An animal which buzzes in your ear and never stops. He may byte you, he may nibble you, but you will know you were bit.
·A good engineer borrows from others, a great engineer steals everything outright!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mosquito: An animal which buzzes in your ear and never stops. He may byte you, he may nibble you, but you will know you were bit.
·A good engineer borrows from others, a great engineer steals everything outright!!
I think one could do it hardly better... Sorry you see it otherwise
As deSilva said: _all_ except a handful of routines in the float lib EXPECT a number that has a precise format. Your variable tempss does not has this format. I'd recommend you read the source of that object to learn of the details of this format, or use another method entirely. We can show you the path, you have to walk it, as a teacher you may have said that more times than hello.
Have a nice evening.
This is the documentation; i.e. nothing. I read the manual. Only talk about different flavors, and using it in asm.
ahh well, back to the drawing board
PUB FMul(a, b)
· 'return sendCmd(FMulCmd + @a)
· command := FMulCmd + @a
· repeat while command
· return cmdReturn
·········
PUB FDiv(a, b)
· 'return sendCmd(FDivCmd + @a)
· command := FDivCmd + @a
· repeat while command
· return cmdReturn
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mosquito: An animal which buzzes in your ear and never stops. He may byte you, he may nibble you, but you will know you were bit.
Technologically challenged individual, Please have pity.
Post Edited (mosquito56) : 12/28/2007 10:31:34 PM GMT
This was your original code
And this is how you should have modified it after my first and second and Ale's postings:
But Ale and me had both the suspicion this could not be the root of your problem. It is very rare to need floating point for such manipulations....
It is no use lamenting over non-existing documentation. We know that all.
Have a nice evening.
Oh, and for a better answer to a question, attatching your code to a post may help point out a problem that you may have overlooked.
Just a bit to nibble on...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
E3 = Thought
http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! My team stats.