Conversion rules float to/from unsigned integer

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
jadiflow
Flowcode v5 User
Posts: 249
Joined: Thu Apr 17, 2008 9:59 am
Contact:

Conversion rules float to/from unsigned integer

Post by jadiflow »

Hi,

My project requires conversion of (unsigned)integer to floating point and back. I've seen some anomalies in equations where I thought the conversion was inplicit but did not give the expected result.
I perused the Help file but it only gives rules for floating point operations as such, no conversion rules.
Are these available somewhere?

While I am at it: is it correct that the rounding function fround is not available for 16Fxxx PIC processors?

Jan Didden

User avatar
Benj
Matrix Staff
Posts: 14929
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Conversion rules float to/from unsigned integer

Post by Benj »

Hi Jan,
is it correct that the rounding function fround is not available for 16Fxxx PIC processors?
Yes this is not available for 8-bit PICs in Flowcode v5 and v6, it is available via the new compiler used in v7.

What sort of resolution are you looking for from the float to int conversion? it should be possible to do something like this.

intwhole = float2int( float )
floattemp = float - intwhole
floattemp = floattemp * 1000
intreal = float2int( floattemp )

jadiflow
Flowcode v5 User
Posts: 249
Joined: Thu Apr 17, 2008 9:59 am
Contact:

Re: Conversion rules float to/from unsigned integer

Post by jadiflow »

Thanks Ben, that is very helpful. I thought that something like fSomething = fSomethingElse + uiNumber would implicitly convert the ui before doing the operation but it is not consistent.
I was not aware of the float2int function.
Can I assume there is also an int2float? Is there a list of these functions somewhere?

I will check out FC7 for te fround; in fact I think I have upgraded to FC7 (and FC6 before that) but I am so used to FC5 that it's hard to say goodby to it...;-)

Jan

User avatar
Benj
Matrix Staff
Posts: 14929
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Conversion rules float to/from unsigned integer

Post by Benj »

Hi Jan,

Yes there is an int2float and the functions can be found in the Fx tab of the calculation icon properties.
CalcFunctions.jpg
CalcFunctions.jpg (41.69 KiB) Viewed 4897 times
V6 and v7 take a bit of getting used to (v7 less so than v6) but I vastly prefer them to v5 now I've gotten used to them.

jadiflow
Flowcode v5 User
Posts: 249
Joined: Thu Apr 17, 2008 9:59 am
Contact:

Re: Conversion rules float to/from unsigned integer

Post by jadiflow »

I bit the bullet and upgraded to FC7 ;-)

But I am getting stuck with the Supp Code for EEPROM presetting. Would be nice if you could take a look at my latest post in the FC7 forum.

User avatar
Benj
Matrix Staff
Posts: 14929
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Conversion rules float to/from unsigned integer

Post by Benj »

Congratulations, let us know how you get on.

I've replied to your other topic now.

User avatar
AbhijitR
Posts: 145
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Contact:

Re: Conversion rules float to/from unsigned integer

Post by AbhijitR »

Hello! Ben
good afternoon
Benj wrote:
Tue Jun 20, 2017 10:15 am
intwhole = float2int( float )
floattemp = float - intwhole
floattemp = floattemp * 1000
intreal = float2int( floattemp )
May I request you to help me with this conversion, I tried to do as mentioned above but without success.

I am able to increment/decrement the float variable, but cannot convert the float(100.5) back to integer along with the decimal value with the above calculation.

I created the variables as below
intwhole as a Integer variable
float as Float variable
floattemp as Float variable
intreal as Integer variable

Something wrong I think, can you correct?

Thank you.

Abhi

Edit: I just noticed after posting, I post in V5 while I am using V8, need to change the version? kindly correct.

User avatar
Benj
Matrix Staff
Posts: 14929
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Conversion rules float to/from unsigned integer

Post by Benj »

Hi Abhi,

Can you post your program and we will have a look for you.

the following lines might be better as

floattemp = float - FLOAT intwhole
floattemp = floattemp * 1000.0

User avatar
AbhijitR
Posts: 145
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Contact:

Re: Conversion rules float to/from unsigned integer

Post by AbhijitR »

Hi! Ben

Thanks for the reply, excuse me for the delay, it took some time to take out the required from the main chart.

I check the chart with F8, on every count the UP key will increment the count by 0.1 to 100 (and also decrement well), after five loop the count will be 100.5, I want to save the 100.5 to the Temporary_Variable pressing the enter key, I tried as you explained in the post, but I think I am making some mistake.

Thank you.

Abhi
Attachments
FloatTOInt_05-09-2020.fcfx
(15.75 KiB) Downloaded 1 time

User avatar
Bachman
Posts: 72
Joined: Sun Sep 07, 2014 11:37 am
Location: Hungary
Contact:

Re: Conversion rules float to/from unsigned integer

Post by Bachman »

Don't use FLOAT, you don't need it.

If you have a number what is needed to be increment or decrement by 0.1, multiply everything by 10. In this case, 1004 means 100.4 You have to make some tricks only if you want to display it as a Float.

x=1004 (the original number, means 100.4)
y=x mod 10 (y will be 4)
x=x/10 (x will be 100)

Display x, display decimal point, display y.

Yes, using division require lots of steps, it takes time but at the end, you can spare tons of RAM. If the process is slow, increase the speed of the controller. I don't now but I think, calculating with FLOAT also takes lots of steps/times.

User avatar
AbhijitR
Posts: 145
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Contact:

Re: Conversion rules float to/from unsigned integer

Post by AbhijitR »

Hello! Bachman

Thanks for your answer, I will try to understand and implement your suggestion, I also need to save the value in EEPROM.

Thank you again.

Abhi

Post Reply