Shop OBEX P1 Docs P2 Docs Learn Events
Looking For A Stop Watch Object With Floating Point Support — Parallax Forums

Looking For A Stop Watch Object With Floating Point Support

idbruceidbruce Posts: 6,197
edited 2011-08-14 00:54 in Propeller 1
Hello Everyone

Does anyone know of an existing object that can be used as a stop watch for code execution and includes floating point support?

Thanks in advance.

Bruce

Comments

  • Heater.Heater. Posts: 21,230
    edited 2011-08-13 12:52
    That's a very vague description of what you want Bruce. Time generally does not come in floating point. Do elaborate.
  • idbruceidbruce Posts: 6,197
    edited 2011-08-13 13:23
    Heater

    I was going to try and represent my idea with code, but I think a description would be much simpler.

    My main product line includes six different sizes. To make the product for a specific size, a block of code is executed with a specified set of variables. To execute this block of code, there is an elapsed time from start to finish, and it is elapsed time that I want to measure. However, instead of a result that ends 5 seconds and 3 milliseconds, I want a result of 5.003 seconds to display on a LCD.

    Bruce
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-08-13 13:30
    if you measure milliseconds I think it is quite easy without floating point

    all calculatins are done in milliseconds.

    seconds := All_The_milliseconds / 1000

    milliseconds := seconds // 1000 (modulus operator)

    lcd.dec (seconds)
    lcd.tx(".")
    lcd.dec(millisecond)

    keep the questions coming
    best regards

    Stefan
  • idbruceidbruce Posts: 6,197
    edited 2011-08-13 13:47
    StefanL38

    Well that was a pretty fast and decent solution. Thanks Stefan. I apologize for getting upset with you a couple weeks ago. Sorry.

    Bruce
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-08-13 13:55
    The technique Stefan used is often referred to as pseudo real. I've read about it in several of Parallax's books (I don't remember which ones anymore).

    Duane

    Edit: It's called pseudo real not pseudo random.
  • idbruceidbruce Posts: 6,197
    edited 2011-08-13 13:58
    There is something written about it in PE Kit Labs V1.2 for timekeeping applications. But after first glance it did not appear that it would do what I wanted. However, after seeing Stefans code, it became crystal clear :)
  • AribaAriba Posts: 2,690
    edited 2011-08-13 14:51
    idbruce wrote: »
    ... a result that ends 5 seconds and 3 milliseconds, I want a result of 5.003 seconds to display on a LCD.

    Stefans code will show 5.3 and not 5.003 in this case. You can calculate every decimal place separatly to get the correct result:
    lcd.dec(milliseconds/1000)
      lcd.tx(".")
      lcd.dec(milliseconds/100//10)
      lcd.dec(milliseconds/10//10)
      lcd.dec(milliseconds//10)
    
    But I''ve seen dec-methodes with an additional dec-point several times in this forum, just don't find it now.

    Andy
  • idbruceidbruce Posts: 6,197
    edited 2011-08-13 15:36
    Thanks Andy, very much appreciated.
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-08-14 00:54
    Hi Ariba,

    thanks for clearing up this.

    This is the difference between quick and dirty just writing code and carefully having tested code.
    keep the corrections coming
    best regards

    Stefan
Sign In or Register to comment.