Binary

nhatpham

Member
Join Date
Dec 2013
Location
iowa
Posts
6
I have two inputs, 8 bits each input, combine together to give me -32767 to 32767 decimal. In RS 5000, what operation can I use to combine it together in to a 16 bits group instead of 8 bits each input. Because the value will varies between -32767 to 32767 so how can I combine these two group together and converter to signed decimal number. Please Help! I really appreciated.

Example.
Local:I.Data[0]
0 1 2 3 4 5 6 7
Local:I.Data[1]
0 1 2 3 4 5 6 7
 
You can use the COP instruction to move these two SINT elements into a single INT element.

COP
Source Local:I.Data[0]
Destination Integer_Value
Length 1


The tag "Integer_Value" must be an INT type.

The Length is =1 because the Length of a COP instruction in RSLogix 5000 is the number of destination elements.

You will end up with Local:I.Data[0] in the lower 8 bits of the 16-bit Integer_Value tag, and Local:I.Data[1] in the upper 8 bits of the 16-bit Integer_Value tag.
 
You will end up with Local:I.Data[0] in the lower 8 bits of the 16-bit Integer_Value tag, and Local:I.Data[1] in the upper 8 bits of the 16-bit Integer_Value tag.

Yes nhatpham, be sure you have the 8-bit bytes the correct way round, as Ken has posted.

If they are wired "wrong" and your upper 8-bits are wired to Local:I.Data[0], then you can do either of the following...

1. Rewire your I/O

2. Use 2 BTD instructions to copy the bits from your source SINTs into the INT in the correct order.

3. Do the COP as Ken has suggested, but to a temporary INT, and then execute a SWPB (Swap Byte) instruction to swap the bytes into your final destination.

I would go with either 2 or 3, most likely 3.
 
Thank you very much.

How is the COP instruction moves data[0] and data[1], if we only using one source in your case data[0]. Or do I have to create another COP instruction for data[1] and length to be 2?
Sorry, I'm new to RS5000. But I really appreciate your help.
 
Yes nhatpham, be sure you have the 8-bit bytes the correct way round, as Ken has posted.

If they are wired "wrong" and your upper 8-bits are wired to Local:I.Data[0], then you can do either of the following...

1. Rewire your I/O

2. Use 2 BTD instructions to copy the bits from your source SINTs into the INT in the correct order.

3. Do the COP as Ken has suggested, but to a temporary INT, and then execute a SWPB (Swap Byte) instruction to swap the bytes into your final destination.

I would go with either 2 or 3, most likely 3.

I'm connecting this device through ethernet communication, so I guess I will try option 3. Thanks a lot for the tips guys.
 
Data[0] and Data[1] are 2 elements of an array tag called Data. The source specification is just telling the COP where to start.

Because it is an array tag, the elements are stored in sequential memory locations, in this case those elements are byte-aligned.

COP is quite a dumb instruction, and misuse of it can be dangerous. Essentially the COP instruction is a "byte copier", and just copies the specified number of bytes from source, to destination, regardless of data-type. The number of bytes copied is determined by the Length specified, and the data-type of the destination tag.

The only saviour to the damage that COP CPS and FLL could potentially cause if Length is wrongly specified is that the controller will cease the instruction when the destination tag boundary is reached, meaning it will not trample all over other tag memory in the database.

Here's an example of this in action... Both the source and destination array tags are only 20 elements long, yet the COP is trying to copy 200 elements. Notice that the processor is still running happily, and there is no corruption of other tags in the database.

2013-12-07_014922.jpg
 
Last edited:
Data[0] and Data[1] are 2 elements of an array tag called Data. The source specification is just telling the COP where to start.

Because it is an array tag, the elements are stored in sequential memory locations, in this case those elements are byte-aligned.

COP is quite a dumb instruction, and misuse of it can be dangerous. Essentially the COP instruction is a "byte copier", and just copies the specified number of bytes from source, to destination, regardless of data-type. The number of bytes copied is determined by the Length specified, and the data-type of the destination tag.

The only saviour to the damage that COP CPS and FLL could potentially cause if Length is wrongly specified is that the controller will cease the instruction when the destination tag boundary is reached, meaning it will not trample all over other tag memory in the database.

I understand what you trying to say. In another word COP will start and end at whatever length you assign then store it in a temporary INT. What about SWPB? Why do we want to use SWPB when COP start from data[0] and end at data[1] according to length 1?
 

Similar Topics

Hi folks, I'm trying to parse a binary string on a Red Lion DA30D using a Raw UDP/IP input port. I've done this before with ASCII strings so I do...
Replies
38
Views
1,051
So here's my situation, I have been tasked with modifying the logic to mimic a button press in the PLC. I have two identical machines however one...
Replies
6
Views
569
Hi, I want to extract every second bit of a double word and place it in a new word but the position of placement should be from 0,1,2......15...
Replies
17
Views
3,108
Hello, I am trying to convert a incoming string that is in Binary format (See attachment) to a DINT. Any ideas? When I use the STOD command it...
Replies
6
Views
2,243
How can I read individual binary bits from a SLC500 within FTH SE? With the Tag Browser I can get to the Binary Files and get each Integer from...
Replies
5
Views
1,631
Back
Top Bottom