Real value shows as Double Word in DB in Simatic Manager

orense

Member
Join Date
Apr 2006
Location
Norway
Posts
196
Hi,

I am currently reading a Modbus value from a Device, through TCP, going into our 400 series plc. The Modbus value is a real value, and it is declared as a real value in the DB. However, the value which comes up is a Double Word value, with no comma. I suspect it is a very small value.

Anyone seen Real values in a DB, displayed as Double Word value? Never seen it before.
 
In the Modbus protocol, Modbus values are always 16-bit unsigned values.

If a device has a value that is a (32-bit) REAL value accessible via the Modbus protocol, then it is represented in the Modbus protocol as two 16-bit unsigned integer registers in two contiguous Modbus addresses.

The key here is to copy the bits (not the value) of those two contiguous 16-bit integers (i.e. two single words) into a REAL value on the 400 series PLC. It sounds like you have already copied the two words to a double word (perhaps your Modbus messaging logic writes to a double-word address); it should be straightforward to copy the bits from that double word into a REAL value.

For clarity and debugging, can you give an example of the current value of the double-word, in hexadecimal if possible, and also of the floating-point value of the REAL value that you think the double-word represents?
 
There is no difference in the bits of a double-word value and a REAL value: both comprise 32 contiguous bits.

The difference is in how those bits are interpreted: interpreting the aggregate of 32 bits a "double-word" gives each bit a value, from 1 to 1G for bits 0 to 30, and -2G for the sign bit (bit 31); interpreting the aggregate of 32 bits a "REAL" defines three types of bits: 1 sign bit; 8 exponent bits; 23 mantissa bits. The 8 exponent bits have a combined binary integer value of 0 to 255 excess 127, representing a base-2 exponent from -127 to +128. The 23 mantissa bits are similar to an unsigned integer, but bit 22 represents ½ (2-1), bit 21 represents ¼ (2-2), bit 20 represents ⅛ (2-3), etc., plus a "hidden" bit to the "left" of bit 23 that represents 1 ((20). But you do not need to concern yourself with those details as long as you can copy the bits, not the value, from the word(s) to the REAL.
 
It may be that there are no REAL values, per se, in Simatic 400, only MDx addresses, representing groups of contiguous 32-bit data, that are interpreted as floating-point values.

Of you are already storing two contiguous Modbus registers, that the Device says represent a REAL value, into an MDx address, then simply using that same MDx address in a floating-point instruction on the 400 will cause those 32 bits to be interpreted as a REAL.

There could be a issue with word, or byte, order in the MDx addresses. That is why it is important to have an example of what the REAL value is for a particular double-word value, as I requested earlier.
 
If the 32 bits are not a valid floating point number, the value is displayed as dword.


Oof. That stings; sounds like a word- or byte-order issue. Again, what is the displayed dword value (hexadecimal, if possible), and what is the expected REAL value?
 
Thank you for all this good info.

Will go to site this upcoming week, and will revert back with some more info on this.
 
If the word or bytes are swapped, that would explain your issue also.
Since you are using an AS400, is this PCS7? Are you sure you are looking at the correct DB register? All the Siemens addressing is in HEX, in most cases.
 
It may be that there are no REAL values, per se, in Simatic 400, only MDx addresses, representing groups of contiguous 32-bit data, that are interpreted as floating-point values.

Of you are already storing two contiguous Modbus registers, that the Device says represent a REAL value, into an MDx address, then simply using that same MDx address in a floating-point instruction on the 400 will cause those 32 bits to be interpreted as a REAL.

There could be a issue with word, or byte, order in the MDx addresses. That is why it is important to have an example of what the REAL value is for a particular double-word value, as I requested earlier.

When you set up the DB in classic Step7 or PCS7, all the addressing is in bytes. When you are building the DB and you declare a value as Real, it will automatically reserve 4 bytes. It will show something like Byte 0.0 Real, then the next entry will be Byte 4.0.

Since the OP says it was declared as a Real in the DB, then it will try and show real values, something is wrong outside the DB.
 
Since the OP says it was declared as a Real in the DB, then it will try and show real values, something is wrong outside the DB.

Ah. Gotcha.

Another possibility, other than byte- and/or word-swapping that we mentioned already, is that, since the bits are coming from a Modbus transaction, that the canonical "Modbus off-by-one" issue is in play here. We also don't know if this is a process that used to work and is only recently giving anomalous results, or if this is a new process recently coded.

The best thing would be to get four 16-bit unsigned integers from the Modbus call starting at one before the device target address.

And again, having an idea of what the floating-point value is, to ± several percent, will make debugging this much easier.
 
Last edited:

Similar Topics

OK I'm ashamed that I'm here asking this as I think in 23 years I would have ran into this before. But here we are. Created an AOI to manipulate...
Replies
6
Views
1,994
Hi all, Let's say we have a nice real (analog) value that has already been scaled with an SCP in Studio5000. Is there a slick method to...
Replies
6
Views
1,570
My company imposes programming standards and insists on using AOIs for AI, AO, DI, DO points. I like AOIs and use them as subroutines when I have...
Replies
10
Views
3,056
Hi Guys, i'm begginer and i'm trying to convert a real value (not fix value) to BCD. It works if i put fix real value but when i put variable...
Replies
2
Views
1,931
Hi everyone :* I am using using unity pro v.13 i want to do the mathematical function of floor() which makes for example 1.2 to 1 and makes 2.9...
Replies
7
Views
3,050
Back
Top Bottom