Float calculation stays 0.00000

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
Dutchie_World_Wide
Posts: 31
Joined: Thu Jul 08, 2010 8:52 am
Location: The Netherlands, or Thailand, or Gabon West Africa
Has thanked: 4 times
Been thanked: 3 times
Contact:

Float calculation stays 0.00000

Post by Dutchie_World_Wide »

"Hello"

I receive a String, which I use to calculate Degrees which I then send forward on RS232, but the result is always 0.00000
Degrees = stringtofloat$ (Pulses_String) * (360 / 7685)
Degrees_Calculated = floattostring$ (Degrees)

Pulses_String (String)
Degrees (Float)
Degrees_Calculated (String)

Dutchie
Dutchie

"This is not a bug, this is a feature!"

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Float calculation stays 0.00000

Post by Benj »

Hello,

This could potentially help.

Degrees = stringtofloat$ (Pulses_String) * (360.0 / 7685.0)

360 / 7685 = 0 because the compiler assumes integer maths.
360.0 / 7685.0 = 0.0468445 because the decimal point elevates the numbers to a float.

Which microcontroller family are you using? If your using 8-bit PIC then I would break up the calculation as much as possible.

Degrees = 360.0 / 7685.0
Degrees = Degrees * stringtofloat$ (Pulses_String)

User avatar
Dutchie_World_Wide
Posts: 31
Joined: Thu Jul 08, 2010 8:52 am
Location: The Netherlands, or Thailand, or Gabon West Africa
Has thanked: 4 times
Been thanked: 3 times
Contact:

Re: Float calculation stays 0.00000

Post by Dutchie_World_Wide »

Thanks Benj.
That did it.

I use the ECIO40P for small projects I do.
The test bench project I am working on at the moment is using the ECIO40P to control a SEW VFD Drive through CAN.
If this will turn out to be a reliable success, i will use that for the smaller VFD projects I have and hopefully keep the PLC's out as much as possible to safe costs.

PLC's are easier to work with, but the PIC's are cheaper ;-)

Thanks Benj
Dutchie

"This is not a bug, this is a feature!"

Post Reply