You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old August 10th, 2017, 03:18 PM   #1
Nhrafan26
Member
United States

Nhrafan26 is offline
 
Join Date: Nov 2008
Location: Slatington, PA
Posts: 53
More than 32767 in N file

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???
Attached Images
File Type: jpg 10 scale rung.jpg (16.2 KB, 23 views)
File Type: jpg 10 scale msg.JPG (54.8 KB, 19 views)
File Type: jpg 10 scale N table.JPG (41.0 KB, 21 views)
File Type: jpg 10 scale N table Hex.JPG (41.6 KB, 21 views)
  Reply With Quote
Old August 10th, 2017, 03:44 PM   #2
Epy
Lifetime Supporting Member
United States

Epy is offline
 
Epy's Avatar
 
Join Date: Jul 2012
Location: Allen-Bradley Valley
Posts: 371
16-bit signed integer: -32768 to 32767
16-bit unsigned integer: 0 to 65535
__________________
Quote:
Originally Posted by ganutenator View Post
customers:
I don't know how to do it so it must be easy
  Reply With Quote
Old August 10th, 2017, 03:56 PM   #3
Nhrafan26
Member
United States

Nhrafan26 is offline
 
Join Date: Nov 2008
Location: Slatington, PA
Posts: 53
Quote:
Originally Posted by Epy View Post
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?
  Reply With Quote
Old August 10th, 2017, 04:11 PM   #4
mellis
Member
United States

mellis is offline
 
Join Date: Nov 2004
Location: Cincinnati, Ohio
Posts: 801
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.
  Reply With Quote
Old August 10th, 2017, 04:11 PM   #5
GaryS
Member
United States

GaryS is offline
 
GaryS's Avatar
 
Join Date: Aug 2003
Location: Lancaster Pa.
Posts: 507
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
  Reply With Quote
Old August 10th, 2017, 04:20 PM   #6
labeledas
Member
Canada

labeledas is offline
 
labeledas's Avatar
 
Join Date: Apr 2010
Location: Peace River Alberta
Posts: 524
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/calcula...7037&binsign=1

I did hex2bin and bin2dec signed

Last edited by labeledas; August 10th, 2017 at 04:26 PM.
  Reply With Quote
Old August 10th, 2017, 04:33 PM   #7
mellis
Member
United States

mellis is offline
 
Join Date: Nov 2004
Location: Cincinnati, Ohio
Posts: 801
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 by mellis; August 10th, 2017 at 04:44 PM.
  Reply With Quote
Old August 10th, 2017, 05:29 PM   #8
Nhrafan26
Member
United States

Nhrafan26 is offline
 
Join Date: Nov 2008
Location: Slatington, PA
Posts: 53
Quote:
Originally Posted by GaryS View Post
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.
Attached Images
File Type: jpg scale output.JPG (45.4 KB, 11 views)
File Type: jpg scale output1.JPG (44.5 KB, 8 views)
  Reply With Quote
Old August 10th, 2017, 05:31 PM   #9
Nhrafan26
Member
United States

Nhrafan26 is offline
 
Join Date: Nov 2008
Location: Slatington, PA
Posts: 53
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?
  Reply With Quote
Old August 10th, 2017, 05:32 PM   #10
Nhrafan26
Member
United States

Nhrafan26 is offline
 
Join Date: Nov 2008
Location: Slatington, PA
Posts: 53
Quote:
Originally Posted by mellis View Post
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.
  Reply With Quote
Old August 10th, 2017, 05:35 PM   #11
Nhrafan26
Member
United States

Nhrafan26 is offline
 
Join Date: Nov 2008
Location: Slatington, PA
Posts: 53
Quote:
Originally Posted by labeledas View Post
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/calcula...7037&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.
  Reply With Quote
Old August 10th, 2017, 06:56 PM   #12
GaryS
Member
United States

GaryS is offline
 
GaryS's Avatar
 
Join Date: Aug 2003
Location: Lancaster Pa.
Posts: 507
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
  Reply With Quote
Old August 12th, 2017, 11:12 AM   #13
QvixoteRoux
Member
Mexico

QvixoteRoux is offline
 
Join Date: Jun 2014
Location: Reynosa
Posts: 70
use Long words for storing more data
__________________
Mexican, need to practice engrish, please cooperate

Industrial Engineer working as PLC programmer.
---
"Everybody believes what is easier for them to believe"
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
1734-IB8S EDS file jgebhardt LIVE PLC Questions And Answers 23 August 10th, 2017 10:30 AM
Add Remote IO with Devicenet SicknoteX LIVE PLC Questions And Answers 11 April 15th, 2016 04:11 PM
Simple way of Loading a relatively large data table ? (Micrologix) mike64b LIVE PLC Questions And Answers 8 November 30th, 2011 05:49 PM
Logix5 print to file question bbear LIVE PLC Questions And Answers 3 December 3rd, 2006 12:13 PM
am i correct? excel & logix CSV communication. fusion LIVE PLC Questions And Answers 14 October 19th, 2005 06:18 PM


All times are GMT -5. The time now is 05:32 AM.


.