More than 32767 in N file

Nhrafan26

Member
Join Date
Nov 2008
Location
Slatington, PA
Posts
53
Ok this goes off of my recent thread but I thought I would start this one and break it down problem by problem instead.

I have a scale reading being brought in by a MSG instruction to an N file. Somehow this reading is being automatically transferred to Hex format because it is allowing a number greater than 32767 to be put in here. I will attach shots of the various screens.
How is this being done??

If you convert the Hex value you will see it comes to more than 32767 which is the limit on N files???

10 scale rung.jpg 10 scale msg.JPG 10 scale N table.JPG 10 scale N table Hex.JPG
 
16-bit signed integer: -32768 to 32767
16-bit unsigned integer: 0 to 65535
 
16-bit signed integer: -32768 to 32767
16-bit unsigned integer: 0 to 65535

That doesn't really explain anything though. Look at the N table, they are negative values. So how does a negative value equal over 32767 when converted from the Hex value?

And how do I specify signed or unsigned in the table or message?
 
A 16 bit integer is always interpreted in the PLC as a signed number with a range of -32768 to 32767. Other devices like a Panelview can choose to display it as an unsigned number 0-65535. Either way it is exactly the same 16 bits. Choosing to display it as Hexadecimal 0-FFFF does nothing to the value, it is just another way to display the same number.

It appears your scale is treating the integer as unsigned and expects a scale of 0-65535. The PLC is going to show anything outside the 0-32767 range as a negative number. It's all how you handle the data, it is still the same data.

Tell us what you need to do with this value, and we can offer some suggestions as to how to handle it. For instance, if you need to compare it to a setpoint it may be simplest to convert it to floating point format.
 
what is the data type you are reading
some Modbus data interchange the high and low words
the receiver data may place the high word to bits 0-7 and the low word I bits 8-15
you may have to reassemble the message after you receive it
if that is the case the data will look strange
 
just from quick conversion using online tools a hex value of 9666 gets converted to a signed integer of -27034 I am not sure how the plc does that conversion for it's display purpose but it looks valid to me it should be 9663 for -27037 but like I said not sure how the plc converts it

also the B18A conversion to -20086 on N12:60 works so maybe the data changed slightly between screenshots

http://www.hobbyprojects.com/calculators/binary_decimal_hex_converter.html?LED=-27037&binsign=1

I did hex2bin and bin2dec signed
 
Last edited:
There isn't any real conversion going on here.

The bit pattern 1001 0110 0110 0110 can also be represented as:
9666 in hexadecimal
38502 as an unsigned integer
-27034 as a signed integer - if the high bit is on, it is considered a negative number. Negative numbers are represented using a format called 2's complement (look it up if you are interested).

It's still the same 16 bits, nothing got converted.

This illustrate what is going on:

0111 1111 1111 1111 is 32767 (unsigned and signed)
Add 1 and you get
1000 0000 0000 0000 which is 32768 as unsigned or -32768 as signed
As you keep adding the signed number will continue to count up until it reaches zero.

It's just a convention to treat the bit pattern as signed or unsigned.

GaryS has a good point, Modbus packs all kinds of data as groups of bytes and it's up to us the re-assemble it properly. If you are dealing with Modbus communications it could even be floating point in four bytes of data.
 
Last edited:
what is the data type you are reading
some Modbus data interchange the high and low words
the receiver data may place the high word to bits 0-7 and the low word I bits 8-15
you may have to reassemble the message after you receive it
if that is the case the data will look strange

This is from the scale manual.

scale output.JPG scale output1.JPG
 
Now that being said, I would like to know how when I write the exact same MSG instruction on another PLC and get the same data, that PLC will not bring in the data as unsigned or Hex, it maxes out at 32767. How did I write the same thing and get a different result from the same piece of hardware?
 
There isn't any real conversion going on here.

The bit pattern 1001 0110 0110 0110 can also be represented as:
9666 in hexadecimal
38502 as an unsigned integer
-27034 as a signed integer - if the high bit is on, it is considered a negative number. Negative numbers are represented using a format called 2's complement (look it up if you are interested).

It's still the same 16 bits, nothing got converted.

This illustrate what is going on:

0111 1111 1111 1111 is 32767 (unsigned and signed)
Add 1 and you get
1000 0000 0000 0000 which is 32768 as unsigned or -32768 as signed
As you keep adding the signed number will continue to count up until it reaches zero.

It's just a convention to treat the bit pattern as signed or unsigned.

GaryS has a good point, Modbus packs all kinds of data as groups of bytes and it's up to us the re-assemble it properly. If you are dealing with Modbus communications it could even be floating point in four bytes of data.

That makes more sense now because the scale reading is 38502 on the display. What I'm trying to figure out is how they brought that higher number into the N file and not have any problems but I try the same thing and it maxes out at 32767 and faults.
 
just from quick conversion using online tools a hex value of 9666 gets converted to a signed integer of -27034 I am not sure how the plc does that conversion for it's display purpose but it looks valid to me it should be 9663 for -27037 but like I said not sure how the plc converts it

also the B18A conversion to -20086 on N12:60 works so maybe the data changed slightly between screenshots

http://www.hobbyprojects.com/calculators/binary_decimal_hex_converter.html?LED=-27037&binsign=1

I did hex2bin and bin2dec signed

I used the simple windows programmer calculator.
Hex=9666
Decimal equivalent= 38502
That's why I didn't understand where the PLC was showing -27037 but the explanation of signed vs unsigned makes the difference.
 
I think the data is brought in to 2 INT words in your case N12:20 and N12:21
I know it shows 4 words but those are 8 bit words in the device you are reading
I think the data you want is in word N12:21 word N12:20 should contain the header information.
The PLC will always use the consecutive words as needed for the received message
 

Similar Topics

Hi everyone, recently i worked with a cmore panel and have the question that how can clear alarm list whit remote form,right now only can with...
Replies
0
Views
76
Hello, friends, I am trying to upgrade a system that uses an Onrom incremental encoder (E6B2-CWZ6C) connected to a Danfoss VFD (FC360), but now...
Replies
4
Views
245
Hello Friends I have took the sample program from AB webpage and modified, but I can only send 127 chars...
Replies
1
Views
156
Hello, I am new here and have been working with PLCs for a few years now. I have been tasked with setting up a Micrologix 1400….. to a Cmore 10...
Replies
10
Views
447
I am very familiar with Studio 5000 PLC programming. And I'm very familiar with C-More HMI programming. But this is my first time using a C-More...
Replies
2
Views
280
Back
Top Bottom