Sign in to follow this  
Followers 0
BenJones

Reading and presenting 32 bit number with Exp.

16 posts in this topic

I'm having difficulty presenting a 32 bit number with exponent on my SCADA screen (E1101). I am reading the 32 bit number into 2 x D registers after reading the data from a kwh meter. I can read the data from the kwh meter device (via Modbus RTU). I am using IEC Developer. The parameter I wish to read is 'current' (Iph1). The number is represented as 32 bit unsigned number (of Type T5) please see attachement. The 24 least significant bits are a binary unsigned value and the 8 most significant bits are the decade exponent. First question : Is there an easy way to read/view this 32 bit number with an FX3u and E1101 (maybe using float with exponent or 32 bit unsigned or something) ? Second question : Do I have to use some more complicated method to read the data ? If so, I was thinking I must have to separate the most significant byte (which is the exponent) from the 32 bit number. Then I'd need to use a roll left function to roll by 8 bits and then shift function to shift by 24 bits right. Bloody complicated ! This would represent the binary number as 00000000 XXXXXXXX XXXXXXXX XXXXXXXX where X is the binary value. I could then multiply the binary number and the exponent. There must surely be an easy way to do this or do I have to use the more convoluted mathematical method ? any help is appreciated. Thanks, Ben data type.bmp

Share this post


Link to post
Share on other sites
I'm pretty sure you can simply BMOV the two registers containing the values into a REAL variable in the PLC. From my head (not tested):

Share this post


Link to post
Share on other sites
If the 2 ints are not properly formatted for type REAL, you can change in the PLC first using the FLT instruction. After that, displaying it in the E1101 is just a matter of selecting the right data type in the pull down (Signed Integer is default, just change it to REAL), with the desired number of decimals to display.

Share this post


Link to post
Share on other sites
The data is a simple precision Float that is recognized by the PLC(FX3U). It can be converted in to integer type with function INT or in to scientific notation with DEBCD function. If it is modbus communication it is possible that the two registers D and D+1 might be inverted and you must use the XCHP function.

Share this post


Link to post
Share on other sites
Thank you for your help ! Kaare your method did work. I now have the hexadecimal number FD01 E240 in binary floating point format ( -1.079032... x 2 ^ 37). I think I need to now convert this base 2 number (binary) into base 10 number (decimal). Is there an easy way to do this ? I've looked through the programming manual and searched through all the function blocks but can't see an easy way to do this. I used the DEBCD scientific notation function but this didn't put the number into decimal format it just put -1079 into D and 34 into D+1 ie representing the mantissa and exponent in the same base (-1079 x 2^34) Thanks again, Ben

Share this post


Link to post
Share on other sites
Where exactly do you have a problem? In the PLC the binary number is the same. Is it in the operator panel? In the OP you simply select the correct format (e.g. REAL/FLAOT) and the number will be 123.456. You say you have the hex number but wan't it converted to decimal, where exactly do you need this?

Share this post


Link to post
Share on other sites
Hi Kaare, I can get the number shown in the OP no problem with 'FLOAT WITH EXP' but I don't think it's the correct number. I don't think it has converted it to decimal, I think it has stayed in binary with exponent. I may be wrong just a bit confused. Looking at the example from the manual it says that 123456 x 10-3 is stored as hex FD01 E240. When I convert FD01 E240 in the PLC I get -1.0790 to the power of 37 and I think this is base 2 binary and not base 10 decimal (surely the number I should get is 123456 with exponent -3. I downloaded an excel spreadsheet tool which converts to precision floating point number. I get the same number as the spreadsheet tool -1.0790 to the power of 37, when inserting FD01 E240 but is this base 2 ? If so then I think I need to convert this (somehow) to decimal !? ieeefloats.xls

Share this post


Link to post
Share on other sites
I may be misunderstanding this, but the Excel sheet seems to calculate this correctly, and since the number in the PLC is the same as the number in the excel sheet (FD01 E240 = -10790.....) isn't this correct? If you try to convert the other way around, you can input a floating point number in the PLC (e.g. 123456.0) and see how it looks in a DINT.... And in the OP you can use 'FLOAT WITHOUT EXP' to present the float as a [number.decimal] instead of [numberExxx]....

Share this post


Link to post
Share on other sites
The excel sheet and the PLC looks to be right. I have another converter and: 123.456 = 42 F6 E9 79 (Motorola - Big Endian) 123.456 = 79 E9 F6 42 (Intel - Little Endian) another observation: 123456 (dec) = 1 E240 (hex) (a part of your number - FD01 E240. Where did you find this example? In which manual?

Share this post


Link to post
Share on other sites
Hi, thank you for your continued help. I'm still having problems. I think the problem is as follows : Please look at the 2 attachments. The PLC reads a floating point number as : Mantissa : 23 bits (b0-b22) Exponent : 8 bits (b23-b30) sign : 1 bit (b31) The modbus data type is read by the PLC from the kWh meter as follows : Mantissa : 24 bits (b0-b23) Exponent including sign : 8 bits (b24-b31) Does this mean that when the plc tries to interpret this as a floating point number it will not do it correctly because the bit order is different ?

Share this post


Link to post
Share on other sites
If this is correct, that the kWh meter stores information in this format, you have a problem. However, it sounds strange that a Modbus kWh meter doesn't present the numbers in standard IEEE float format. Please also provide the spec for the kWh meter.

Share this post


Link to post
Share on other sites
Hi ! It seems very strange that the manufacturer (Areva) presents the data in this format ! I have done some programming (took me ages) to try and read the number by splitting the data into the upper 8 bits and the lower 24 bits, so I now have the signed exponent and the mantissa, but I don't know how to put this as one number and display it on the HMI (E1101). Been trying to read this number and put it on the HMI for about three weeks now. Crazy ! I've attached the Areva kWh meter manual as well as the programming which I have done (in IEC Developer). The Data type is under 'Data Types' in the manual on page 27. The modbus addresses which I'd like to display the values of, are 36-41 on page 16. (I can read from the addresses no problem). There surely is an easy way to do this because why would Aveva make there data so hard for a plc to read from their kWh meter ? Any help is much appreciated. Thanks, Ben AREVA M231 MANUAL.pdf MODBUS_READ_CURRENT_backup_file_change _extension_to_pcd.pdf

Share this post


Link to post
Share on other sites
You have a problem.... Change the kWh meter (cheaper than spending a lot of time writing program for decoding/encoding the numbers).... Sorry and good luck

Share this post


Link to post
Share on other sites
Maybe is obvious but I don't see any solution to decode their format. Can you ask the producer about this "proprietary" format?

Share this post


Link to post
Share on other sites
Ok thanks guys. I don't think there is any easier way to do it. It's ok though, I've finished off the program to read in the number now (the long way!). If you do come accross the same problem in the future then the code I attached will work. Thanks for your comments and help, Ben ps. Is there any way to mark this post as 'completed/finished' or shall I just leave it ?

Share this post


Link to post
Share on other sites
Just leave it, but it would be great for others if you attached the code (maybe you forgot it?)

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