Sign in to follow this  
Followers 0
Guest Colin Carpenter

FX2N and Floating Point Numbers

4 posts in this topic

Hi, Does anyone have any experience of using FX2N floating point calculations? I have an FX2N to play with and am using IEC Developer V5.02. I've found the functions FLT, DFLT, INT, DINT, DEADD, DESUB, DEDIV etc. and am now moving towards programming the application. Question is: I have an equation that I need to calculate, which is: Y = 0.00485 X + 0.985 X starts life as a Double Integer, is converted to Floating point by using DFLT, then I try to DEMUL using the constant 0.00485, but IEC developer tells me that 0.00485 is an invalid format. It's quite happy with 485 (an integer), and seems happy if I divide 485 by 10,000 elsewhere and even seems to work if I divide it by 100,000, but now I'm getting twitchy about 100,000 being greater than 32768, etc., etc. Does any one know a way of entering a Floating Point constant directly into a Floating Point Multiplication block?? I can do it in the QNA series where it talks about REAL numbers rather than Floating Point. Hope that makes sense, Thanks in advance

Share this post


Link to post
Share on other sites
I don't have IEC version but in standard GX Developer constants need prefix to specify format: K345 is 345 decimal H345 is 0x0345 hexadecimal E0.0345 is floating point decimal number 0.0345

Share this post


Link to post
Share on other sites
Instead of using a 'K' constant, you could use a battery backed 'D' location as a constant and write the value .00485 directly to it (I used device test, select 'Real number'). Also, you needn't worry about exceeding 32767 with a doubleword instruction. Remember 32767 is the largest signed integer (16 bits). You are now working with 32 bits signed, so your largest result or operand can be +- 2,147,483,648. Edited by mjrx

Share this post


Link to post
Share on other sites
Thanks for the replies ..... I think this must be highlighting some differences between IEC and GX developer. I've tried entering E0.0345 but IEC throws it out as an error when compiling. It happily accepts H or K prefixes as long as they are followed by "whole numbers". In IEC, you can view Floating Point numbers when monitoring, but they have an apparently meaningless number. This is mentioned in the FX2N manual, where it says that the format used is a special unreadable IEEE format. I've got round the problem by: Write "whole number" value into Double Integer Variable. Convert to Floating Point using DFLT. Divide that by a "whole number" constant. Then, IEC has the ability to graphically string together functions, using system variables during compiling, so I just take that unknown calculated value into other DE functions, and pop the answer out at the end using the DINT command. Seems to work fine, but is a bit baffling why I can't enter FP numbers in IEC when apparently it works in GX

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