"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
Float calculation stays 0.00000
Moderator: Benj
- 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:
- 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
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)
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)
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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
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
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!"
"This is not a bug, this is a feature!"