logo Welcome, Guest. Please Login or Register.
October 23, 2017, 08:28:37 PM
Home Help Search Login Register
 News: Self-Registration temporarily suspended due to abuse.To Register as a member, please email to webmaster@triplc.com with your email and username.

  Internet PLC Forum
  General
  Frequently Asked Questions
(Moderator: support)
  Managing IEEE Floating Point Numbers
? previous next ?
Pages: [1] Go Down Reply Notify of replies Send the topic Print
   Author  Topic: Managing IEEE Floating Point Numbers  (Read 4800 times)
support
Global Moderator
*****

Posts: 3044





View Profile WWW E-Mail
Managing IEEE Floating Point Numbers
« on: December 07, 2011, 01:45:48 AM »
Reply with quote

Although the Nano-10, FMD and F-series as well as the older T100M+ PLCs do not directly support floating point computation, there may be situation when it become necessary to deal with numbers that it obtains that is formatted as a floating point number.  For example the PLC could interface to a Modbus power meter that only presents data in floating point format via Modbus registers. The retrieved floating point data needs to be converted into fixed point integer for computation.

In other occasions, the PLC may need to present its result as a floating point number for other devices that only accepts data in floating point format. This enables the PLC to be programmed as an instrument, a smart sensor gateway, or act as a data concentrator, data translator or protocol converters between incompatible industrial devices.

We have written and tested two TBASIC custom functions to enable translation of floating-point to fixed-point data and vice versa. The .PC6 files containing the two functions can be downloaded from the following link. These two functions are written to be easily copied into your application programs. Please refer to the comments in the functions for details.

http://www.tri-plc.com/trilogi/Float2Integer-RevA.zip

If you wish to check the conversion result of the function, the following website is a good calculator:

http://www.h-schmidt.net/FloatApplet/IEEE754.html

More information about IEEE Single Precision Floating point format can be found at:

http://en.wikipedia.org/wiki/Single-precision_floating-point_format
« Last Edit: December 07, 2011, 01:30:30 PM by support » Report to moderator   Logged

Email: support@triplc.com
Tel: 1-877-TRI-PLCS
support
Global Moderator
*****

Posts: 3044





View Profile WWW E-Mail
Re:Managing IEEE Floating Point Numbers
« Reply #1 on: October 29, 2014, 11:55:23 AM »
Reply with quote

The Fx1616-BA, Fx2424 and SmartTILE-Fx board now all natively support floating point numbers and it is very easy for these PLCs to read from MODBUS registers that contain numbers in floating point format.

The i-TRiLOGI version 7 supports the commands:

A = FLOAT2BITS (x#)  ' convert floating point number into IEEE 32-bit single precision hex number
X# = BITS2FLOAT(n)  ' convert a 32-bit number in IEEE single precision format into a floating point number.

Hence you can use the standard READMB2 command to read two consecutive Modbus registers and then convert the 32-bit number into internal floating point numbers for computation.
Report to moderator   Logged

Email: support@triplc.com
Tel: 1-877-TRI-PLCS
BC SYSTEMS
Sr. Member
***

Posts: 146





View Profile E-Mail
Re:Managing IEEE Floating Point Numbers
« Reply #2 on: January 16, 2015, 03:50:31 PM »
Reply with quote

Hi,

I'm using a fx PLC and reading data from a power meter in the IEEE format. When I look at the variable A# in the online viewer the value is correct "240.5". If I copy this to the LCD I get "+240.50000" but really all I want is "240.50".

I have copied the data from A# to A, multiplied by 10 then used the MOD function to get " 240.50" but this seems a little long winded and uses up the 32 bit variable.

I was wondering if I could truncate the A# string?  Have tried A# = MID$(A#),2,6) but this fails to compile 
« Last Edit: January 16, 2015, 05:44:43 PM by BC SYSTEMS » Report to moderator   Logged
support
Global Moderator
*****

Posts: 3044





View Profile WWW E-Mail
Re:Managing IEEE Floating Point Numbers
« Reply #3 on: January 16, 2015, 11:45:47 PM »
Reply with quote

try this:

SETLCD 1,1, STR$(A#, -2)
Report to moderator   Logged

Email: support@triplc.com
Tel: 1-877-TRI-PLCS
BC SYSTEMS
Sr. Member
***

Posts: 146





View Profile E-Mail
Re:Managing IEEE Floating Point Numbers
« Reply #4 on: January 17, 2015, 03:07:55 AM »
Reply with quote

Hello,

Thanks that helped but you still have the signed bit representing a + or - depending on your value.  Can I remove this also without moving the data into the 16/32 bit memory?  Appreciate IEEE is for both positive and negative number representation but the value I'm reading will always be positive.

Cheers
Report to moderator   Logged
support
Global Moderator
*****

Posts: 3044





View Profile WWW E-Mail
Re:Managing IEEE Floating Point Numbers
« Reply #5 on: January 17, 2015, 06:23:45 PM »
Reply with quote

Sorry, but you will have to use MID$ to remove the sign.


A# = 240.50000
A$ = STR$(A#,-2)
SETLCD 1,1, A$

A$ = MID$(A$, 2, LEN(A$)-1)
SETLCD 2,1, A$


Report to moderator   Logged

Email: support@triplc.com
Tel: 1-877-TRI-PLCS
BC SYSTEMS
Sr. Member
***

Posts: 146





View Profile E-Mail
Re:Managing IEEE Floating Point Numbers
« Reply #6 on: January 17, 2015, 07:01:06 PM »
Reply with quote

Ok Thanks
Report to moderator   Logged
garysdickinson
Expert Member
****

Posts: 363



Old PLC Coder

View Profile E-Mail
Re:Managing IEEE Floating Point Numbers
« Reply #7 on: January 19, 2015, 01:52:21 PM »
Reply with quote

Marcus,

I was having problems formatting negative floating point values with str$(x#,n).

This code shows a similar usage of mid$ to swap a "+" for a "-".


  ' print float with 2 decimal points of accuracy
  '
  if (i# < 0.0)
      A$ = str$(-i#,-2)
      A$ = "-" + mid$(A$,2,len(A$)-1) 
      print #2 A$
  else
      print #2 str$(i#,-2)
  endif

Best regards,

Gary d
Report to moderator   Logged
BC SYSTEMS
Sr. Member
***

Posts: 146





View Profile E-Mail
Re:Managing IEEE Floating Point Numbers
« Reply #8 on: January 19, 2015, 02:03:04 PM »
Reply with quote

Thanks Gary,

I'll give that a try!

Cheers

Marcus

Report to moderator   Logged
Pages: [1] Go Up Reply Notify of replies Send the topic Print 
? previous next ?
Jump to: 


Login with username, password and session length

Powered by MySQL Powered by PHP Internet PLC Forum | Powered by YaBB SE
© 2001-2004, YaBB SE Dev Team. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!