Shop OBEX P1 Docs P2 Docs Learn Events
Single and floatmath — Parallax Forums

Single and floatmath

mosquito56mosquito56 Posts: 387
edited 2008-04-06 01:46 in Propeller 1
· 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!!

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2007-12-28 20:57
    Mosquito,
    your smaller problem is this:
    tempor:=(f.FDiv(f.Float(tempss),100.0))
    


    This is what's meant by "single precision floating point format" smile.gif 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
  • mosquito56mosquito56 Posts: 387
    edited 2007-12-28 21:09
    I know why it is high but that doesn't make any difference.

    ··· 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!!
  • AleAle Posts: 2,363
    edited 2007-12-28 21:20
    Mosquito: There are other ways to deal with this kind of number problem.

    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.
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-28 21:21
    No, Mosquito, you are just trying too many things at the same time (as me smile.gif )
    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 smile.gif

    P.S.: Hope this will not be classified as one of the "rude mails" smile.gif

    Post Edited (deSilva) : 12/28/2007 9:26:57 PM GMT
  • mosquito56mosquito56 Posts: 387
    edited 2007-12-28 21:31
    No, not a rude reply just one that makes my head spin even more. Only trying to do one thing. Learn to use floatmath.
    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!!
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-28 21:40
    Mosquito, this is something what I rarely understand... It happens with other posters, too.. I gave you a PRECISE answer (the short CODE-yection in the second posting above). That has been 1/2 of the solution. I also added the other half of the solution: FloatString...
  • mosquito56mosquito56 Posts: 387
    edited 2007-12-28 21:55
    1/2 an aswer here and 1/2 an answer there is pretty useless. I am a retired teacher so in this area I have a little knowlege. This I definetly and always understood. And yes yours is a· rude reply.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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!!
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-28 22:01
    Mosquito, this had been my fast answer to your question:
    deSilva said...

    Mosquito,
    your smaller problem is this:
    tempor:=(f.FDiv(f.Float(tempss),100.0))

    This is what's meant by "single precision floating point format" smile.gif 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 a 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...

    I think one could do it hardly better... Sorry you see it otherwise
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-28 22:06
    I just see you have a WAITCNT in your routine. This is not necessary, there is nothing to wait for.
  • AleAle Posts: 2,363
    edited 2007-12-28 22:11
    Mosquito: Besides you ignored my response, i'd try again.

    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.
  • mosquito56mosquito56 Posts: 387
    edited 2007-12-28 22:23
    Agreed, I will try it. Thanx for at least pointing out where the durned road is. BTW: I sent you a pm about the 16.16. I guess you didn't get it. Thank you for the help.

    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
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-29 01:18
    Mosquite, this is my last posting here in this thread...

    This was your original code
      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)
    



    And this is how you should have modified it after my first and second and Ale's postings:
      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([b]f.Float(tempss)[/b],100.0))  ' This LOCKS UP THE CHIP
      [b] '''''[/b]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([b]floatstr.FloatToString(tempor)[/b])
    




    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.
  • RinksCustomsRinksCustoms Posts: 531
    edited 2008-04-06 01:46
    @mosquito - if your resistorhappensto be a thermisistor, the "math" will not be linear cuz most thermisistors are negative coeficient type. Also, if your answer is in the billions, your most likely displaying clocks and not a converted temperature from the sounds of it. And Desilva may sound rude and cryptic, but has alot of useful knowledge.



    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.
Sign In or Register to comment.