How works float variable in Flowcode 4 for PIC ?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

How works float variable in Flowcode 4 for PIC ?

Post by Mathy »

Hi,

I'm trying to use float variable only because I need to calculate the displacement of an object with an optical encoder on 32bit variable.

I thought in a float variable, I could get a number between -2 147 483 648 and + 2 147 483 647 but in the simulation, I can get an number like + 5 000 000 000.

What are the real end authorized by a float variable in Flowcode?

Thanks,

Mathy

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: How works float variable in Flowcode 4 for PIC ?

Post by Benj »

Hello Mathy,

This Wikipedia page may help as it has a section detailing the range of Floating point variables.

http://en.wikipedia.org/wiki/Floating_point

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: How works float variable in Flowcode 4 for PIC ?

Post by Mathy »

It is like chinese to me :D

I don't need floating point in my application. Only the integer.
Is it annoying to use floating point in my case ?

Or, Is it possible to use 32 bit integer in Flowcode ?

I just need to count pulse from my optical encoder.

Thank you.

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: How works float variable in Flowcode 4 for PIC ?

Post by DavidA »

Hello Mathy,

Unfortunately in Flowcode v4 you cannot use 32bit integers natively, in Flowcode v5 we will be changing this and adding more options.

However for the time being you can use techniques described in this article to break down your int into smaller chunks.

http://www.matrixmultimedia.com/article.php?a=366

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: How works float variable in Flowcode 4 for PIC ?

Post by Mathy »

Ok Thanks for the article. I will read it.

In the mean time, is it possible to use float variable to count pulse in clock wise and counter clock wise ?

I ask this because if I make a decision : if FLOAT1>0 then put C1=1 --> works well

But if make : if FLOAT1<0 then put C1=0 --> the result is C1=1 in the real hardware. C1=0 in simulation

Do you have an idea ?

Thanks a lot.

Mathy

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: How works float variable in Flowcode 4 for PIC ?

Post by Benj »

Hello,

Floats and BoostC do not work well together. To do a floating point comparison on PIC you have to use the floating point functions.

Eg

Calculation: INTvar = float_le(FLOATvar, 0)
Decision: INTvar

All the floating point functions are available in the functions list for the calculation icon.

If you do not specifically want floating point then I would either use several byte variables or create a long variable in C code and use this to do your calculations and decisions.

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: How works float variable in Flowcode 4 for PIC ?

Post by Mathy »

I just try with the floating point function but without any success. It works only on simulation.

Floats works with Hitech C compiler ?

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: How works float variable in Flowcode 4 for PIC ?

Post by Benj »

Hello,

Yes Floats work as expected with HiTech.

Can you post your program using the float function and I will see if I can spot what's gone wrong.

Post Reply