Shop OBEX P1 Docs P2 Docs Learn Events
Can clkfreq be converted to float? — Parallax Forums

Can clkfreq be converted to float?

lardomlardom Posts: 1,659
edited 2011-12-19 21:27 in Propeller 1
I want to use a float number in a 'delay' expression. The following line does not work;
waitcnt(clkfreq /(float) + cnt)
Calculating the distance along a circumference, C = 2pi * r, is easily done in the float objects. I want to be able to define speed as well as distance in float.

Comments

  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2011-12-19 10:24
    You'll have to use a float conversion method from an object (like F32 or FloatMath), then do the float math, then convert it back to int.

    So something like this:
    waitcnt(FLT.FRound(FLT.FDiv(FLT.FFloat(clkfreq), [float val])) + cnt)
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-19 11:57
    Larry,

    Like Bobb said, you could use a foating point conversion object to do this.

    I think it would be best to wait to convert the difference of two times. Use interger math to do the subtraction of the two clock values and then, if you need/want to, convert this smaller number to a float. I bet just converting the final difference will save you a lot of headache.
  • lardomlardom Posts: 1,659
    edited 2011-12-19 14:48
    Bobb Fwed and Duane Degn, thanks for your replies. I'm going to test your examples.
    I think I spotted an important key in this thread. Here
    Since the system counter only works with integers I see that I'll have to convert my result values to integers before I insert them into a waitcnt expression. I'll move the decimal points to the right to maintain precision and try again.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2011-12-19 14:51
    That's what the FRound method does (I used that in my example).
  • lardomlardom Posts: 1,659
    edited 2011-12-19 21:27
    Bobb and Duane, thanks a lot. I made great progress with my code. :smile: I met my short goal which was to write an object ahead of the motors and wheels that are being shipped to me.
Sign In or Register to comment.