Sign in to follow this  
Followers 0
Leandro

Floating Point with FX1N and GX Developer?

9 posts in this topic

Hi all! I have a problem when trying to work with floating point numbers with a FX1N PLC using GX Developer. I need to do some simple calculations (divide and multiply) , in order to calculate a motor speed with an encoder, but as simple as it might sound, the FLT instruction is not available, so i can't convert a simple 16 bit integer to floating point. Do i need some kind of library to get it to work, or what? I would thank anybody who could help me with this. =) Regards.

Share this post


Link to post
Share on other sites
FX1N doesn't have float (or real). To get a better accuracy, convert the integers to doubleintegers and do the calculation. Convert back when your finished if you need to.

Share this post


Link to post
Share on other sites
Thanks kaare_t! So i will try to work with doble integers, which means that i will not have decimal precision. Do you know which is the instruction to convert? Thanks.

Share this post


Link to post
Share on other sites
You don't need to actually convert it to dint, just use e.g. D10 = your original value. Then process D10+D11 (e.g. DMUL) accordingly, then when finished make sure that the value is max 16 bits, and just use the lower device of the two. To get "kind of" decimal precision, just multiply your original value (D10) with 10 (that's for 1/10) or 100 (for 1/100). Then you get "decimals" in the form of trailing numbers after your actual number. E.g.: D10 = 10 and you want to divide with 0.25 then you just: (D10 * 100) / 25 = 40 Thats the code for the actual: 10/0.25 = 40. Just remember when finished that your value is max 16 bits, if not or if you have any remaining commas just remove them (ddiv) and use the remaining value which will be fairly accurate.

Share this post


Link to post
Share on other sites
I get your procedure, but the problem is when i divide two integers and the result is irrational float. e.g.: 12/11 = 1.09090909..... the instruction is as follows: e.g.: D250 = 12 D260 = 11 (DDIV D250 D260 D270) the tag D270 is assigned with the int part from the result, then D270 = 1. What happens with the decimal part 0.090909.... ? Thanks very much! PS: the point of all this is to show in a HMI the motor's speed in float format, e.g: Speed: 3,45 metres/minute Edited by Leandro

Share this post


Link to post
Share on other sites
Well, if you take 12000/11 instead; 1090,9090..... I guess you can scale in the HMI so that the value 1090 will scale to 1,09.... Then you get decimals in the HMI. In essence you scale up the value in the PLC to avoid getting decimal parts, and you scale it back in the HMI. Would that work?

Share this post


Link to post
Share on other sites
Thanks for your support kaare. I scaled in HMI so i can see the value as float. Regards!!

Share this post


Link to post
Share on other sites

Hello. I have the same question on how to convert INT to FLT on FX1N but I need to show the decimal point on my 6 digits-7 segments numerical display which has built in address. Thanks in advance!

Share this post


Link to post
Share on other sites

As stated earlier in this same post, FX1N does NOT have floating point math.  All you can do is make an INT with some implied decimal places and then insert the decimal on an HMI.

So for example, 10000 can actually mean 10.000 and you can put the . in via the HMI.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0