Micrologix SWP instruction

danileru

Member
Join Date
Jan 2011
Location
Brisbane
Posts
5
Hello
Sorry if this is not a really smart question but how do you use the SWP (swap )instruction in a Micrologix 1100 processor?
I have got a dmx-512 to modbus rtu gateway that communicates with the micro via channel 0. The gateway sends 2 x bytes which are combined in a word , then I need to split the word in the Micro. I have tried using the SWP instruction in an unconditional logic rung followed by another rung with a MVM instruction but it looks like the 2 bytes in the word don 't get swapped, ie: nothing is happening to the word. Am I doing something wrong? How do you use the instruction? From the reference manual it looks like all I need to do is enter the address of the integer and the length ( number of registers to be swapped ).
Any help would be greatly appreciated.
Dan
 
Two warnings: (1) Certain values would look the same before and after a byte SWAP. For example, decimal 61664, binary 1111000011110000, would still have the same upper and lower bytes (and same numerical value) AFTER a Swap. There are many other byte combinations (at least 256) that would be the same after a swap. If your bytes contain characters, then you must use String commands.

(2) Make sure that you understand what the SWP Length parameter means. It can mean a different number of bits, depending on the type of memory entered into the address. It seems that you could also use Move with Mask 65280 (hexadecimal FF00) to pull out the upper byte, and Move with Mask 255 (hexadecimal 00FF) to pull out the lower byte. Once you have a word containing only the high or low bytes, then you need some command to use or see what is in that word. (Looking at the word value will not help you much to recover the original two bytes). You could use AEX (string extract) to pull out whichever 8 bits you want to look at. In fact, AIC and AEX may be the only commands that you need to recover the two original bytes.

To know how to recover the bytes, a person first needs to know what they represent: two different number values, string or characters, or two parts (integer and fraction) of the same number.
SWP [Swap]
Rockwell Software
Description
Use the swap instruction to swap the low and high bytes of a specified number of words in a bit, integer, ASCII, or string file. The instruction consists of two parameters, a source and a length.
Entering Parameters
The source can only be an indexed word address.
The length refers to the number of words (from the source word) to be swapped . The allowable ranges for the length, which is a constant, are based on the file type of the source and are as follows:
File Type Length Range
Bit 1-128
Integer 1-128
String 1-41 (limited to a single string)
ASCII 1-128
If the length causes the swapped words to exceed the maximum file length, the data table file is automatically extended, except when using the MicroLogix Controller. Data files are not extended for MicroLogix controller programs since their data table space is fixed in size.
 
Last edited:

Similar Topics

Hey all, first time poster here. I am wondering if anyone has tried using a Keyence SR-X300 barcode scanner to a Micrologix 1400. Keyence sent...
Replies
0
Views
26
I have been working on this for a while now and I can't seem to get it. I was finally able to view the 1500 on the PanelView under the serial...
Replies
1
Views
81
I'm using a SLC typed write from the ControlLogix5572 to the MicroLogix 1400, with path: 2, (MicroLogix IP). The ControlLogix equipment has a...
Replies
0
Views
89
"Hello! Good day! Excuse me, I have a question regarding the 1761-NET-ENI. RSLinx has already detected it but it's not connecting to the PLC...
Replies
4
Views
126
Hi, I cannot find the DLCA1764.EXE utilty software for data retrieving. Can someone share the link to download this software. Thanks!
Replies
4
Views
119
Back
Top Bottom