The text of a manual · part 15 of 23
Bulletin 1771 Communication Controller Module (Cat. Nos. 1771-KE, -KF) User's Manual, pages 141 to 150
Pages 141 to 150 of 228
The original document is the PDF (9.6 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Allen-Bradley 1771-KE
Page 141
Chapter
Data Manipulation
6.0 General
6.1 Data Encoding
6.1.1 Number Systems
6.1.1.1 Binary
This chapter explains two areas of special concern when you are transmitting messages between computers and PCs:
® Data encoding e Addressing formats
The information contained in this chapter gives some application details that relate to the data and address fields of the message formats described in chapter 5.
In general, PCs store binary data (1s and Os) in 16-bit groups called words. If you are looking at this data from a computer, however, you may interpret it in a number of different ways, depending on your application needs.
You may use any one of the following number systems to represent data in your computer application programs:
e Binary e Binary coded decimal e Decimal e Hexadecimal e Octal
You must design your computer application programs to make any necessary conversions from one number system to another. Once you have selected the number system that is best for your applications, try to use only that one system and convert all data values to that base to avoid confusion.
The binary number system is probably the simplest to use for computer and PC applications because it is the most natural way to represent data bits. However, since the binary system uses only the digits 0 and 1, it is cumbersome to show values in binary format.
Each digit in a binary number has a certain place value expressed as a power of 2. You can calculate the decimal equivalent of a binary number by multiplying each binary digit by its corresponding place value and then adding the results of the multiplications. Figure 6.1 shows the binary representation of the decimal number 239.
Page 142
Page 6-2
Data Manipulation
6.1.1.2 Binary Coded Decimal
1x 27= 128 1x 2° = 64 1 25 = 32 Ox 24=0 128 64 1x2=8 30 1x 22=4 8 4 1x21=2 2 1 1x21 23910 2 411011112 = 2391
11240
Figure 6.1, Binary Numbers
Quite often, PC data is represented in binary coded decimal (BCD) form. In this system, each group of four bits in a PC word represents one decimal number between 0 and 9. In this way, each 16-bit word can represent a BCD value between 0 and 9,999. Figure 6.2 shows the BCD representation of the decimal number 239.
0x 2°=0 Ox 22=0 1x 2122 0x 29=0 0x 2°=0 Ox 22=0 3 1x 21=2 Ox 2°=0 1x 2328 0x 22=0 9io 0x2'=0 4x 2024 olol1}olo}o]1 olo|1 N in 7, Vv W Vv 2 3 9
11241
Figure 6.2, BCD Representation of Decimal 239
Page 143
Page 6-3 Data Manipulation
6.1.1.3 Decimal
6.1.1.4 Hexadecimal
6.1.1.5 Octal
The decimal number system is probably the easiest for us to use because it is most familiar to us. It uses the common digits 0 through 9, and each digit has a place value that is a power of 10 (Figure 6.3). However, despite the convenience of decimal numbers, it is often easier to convert binary data to a number system other than decimal.
2x10? = 20010
200 3x 10'= 3010 3 9x 10°= Dio 23910
10238
Figure 6.3, Decimal Representation, Number 239
The hexadecimal number system is the most compact way to represent binary data, and it allows for the easiest conversion to and from binary. This system uses a number set of 16 digits: the numbers 0 through 9 and the letters A through F (where the letters A through F are equivalent to the decimal numbers 10 through 15, respectively).
Each group of four data bits represents one hexadecimal digit between 0 and F. In this way, each 16-bit data word can havea hexadecimal value between 0 and FFFF.
Each digit of a hexadecimal number has a place value that isa multiple of 16. To convert a hexadecimal number to its decimal equivalent, multiply each hexadecimal digit by its corresponding place value and add the results of the multiplications. Figure 6.4 shows the hexadecimal representation of the decimal number 423.
The octal number system is also a relatively easy way to represent binary data. This system uses the eight digits 0 through 7.
Each group of three data bits represents one octal digit between 0 and 7, This factor presents a slight conversion problem because bytes and words usually contain an even number of bits. Thus, an 8-bit byte can have an octal value between 0 and 377, while a 16-bit word can have an octal value between 0 and 177777.
Page 144
Page 6-4 Data Manipulation
Each digit of an octal number has a place value that is a multiple of 8. To convert from octal to decimal, multiply each octal digit by its corresponding place value and add the results of the multiplications. Figure 6.5 shows the octal representation of the decimal number 239.
0x 2'=0 0x2°=0 O16 ox2'=0 ox 2°=0 Ox2=0 Ox 27=0 116 ox 2'=0 1x2 =1 1x2=8 0x2=0 Aus 1xpleo 0x 2°=0 0x2*=0 1x2=4 716 4x2'=2 1x 2°=1 0 OfiprfPoryrtopfoyriprada 0x16? =0 1x16? =256 10x 16' =160 7*x16° = O1A7 16 = 42310
11335
Figure 6.4, Hexadecimal Numbers
Page 145
Page 6-5 Data Manipulation
1x2'=2 33 1x2=14 1x2 =4 ox2'=0 5s 1x 2°= 4 1x2=4 1x2'=2 43 1x 2°=1 1714010 PRag179191 3x 8? = 192 5x8 =40 7x8 =7 3575 = 23910
11336
Figure 6.5, Octal Numbers
6.1.2 PCs store data in 16-bit (2-byte) words. The bits in these words Order of Transmission are numbered (addressed) 0 through 17 octal, going from right to left within a word, as follows:
PC Word
Bits | 17}16] 15] 14] 13} 12 |11 110/07] 06] 05)04]03]02 101 |00
In PC memory, the words are arranged as shown above. However, when the KE/KF module transmits data over its RS-232-C link, it transmits one byte at a time. The module always transmits the low byte (bits 00 through 07) of a word before the high byte (bits 10 through 17) of the same word. Also, UART transmits the low bit first within a byte. Thus, when a PC word is traveling over the RS-232-C link, it will look like this:
First Byte Second Byte
Bits | 00]01|02] 03] 04) 05| 06) 07 10} 11] 121/13] 14)15]16) 17
Time - - - - - This does not present a problem at PC stations on the link because PCs always store and retrieve their data in this same order of low byte first. It can, however, require you to do some extra computer application programming to maintain the proper byte and word order in PC data stored in the computer.
Page 146
Page 6-6 Data Manipulation
6.2 Addressing
6.2.1 Logical Addressing
Three factors that can influence the ability of your computer to handle PC data are:
e The size of words in your computer’s memory e The left-to-right or right-to-left ordering of bits within a word in your computer’s memory
@ Whether the computer considers the low order byte of a word to have an even or an odd address
If your computer uses something other than 2-byte, 16-bit words, you should design your application programs to make the proper conversions from PC word addresses to computer word addresses. When stored in a computer, each PC word should start on an even byte boundary.
Figure 6.6a shows a 16-bit word in PC memory.
Figure 6.6b shows a 16-bit computer word with right-to-left byte and bit order (as in DEC PDP-11/34 or VAX 11/780). It also represents a 16-bit word in an 8-bit processor (such as Zilog Z-80 or Intel 8086 microprocessor). If your computer has this type of word order, the conversion is straighforward.
Figure 6.6c shows a 16-bit computer word with left-to-right byte and bit order (as in IBM Series 1). If your computer has this type of word order, the conversion is more complex. You will have to swap bytes into and out of buffers.
Figure 6.6d shows a 16-bit computer word with left-to-right byte order and right-to-left bit order (as in Zilog Z 8000 or Motorola 68000 microprocessors). If your computer has this type of word order, your communication driver must handle the task of byte swapping as it loads data into a buffer. Successive bytes received from the PC must be stored in the following order:
1,0,3,2,5,4,7,6,9,8,...
There are three types of addressing a computer can use in command messages that it transmits to PC stations:
e Logical e Physical e Symbolic
Logical addressing refers to the type of addressing that a PC uses in its ladder diagram program to access its own data table memory. This is the same type of addressing you would use in non-privileged commands (that is, in commands that access only PC data table memory). Because of the differences in PC memory organization, the logical addressing scheme varies with controller type.
Page 147
Page 6-7 Data Manipulation a PC Word Bit Number (octal) 17 16 15 14 13 12 11 10 O07 06 05 04 03 02 01 00 dhofifposvotrizbopripoprptgrpopyrgr1 yo Value A576 hex
\ / f VO VO Odd, high byte Even, low byte b 16-Bit Computer Word with Right-to-Left Byte and Bit Order Bit number (decimal) 15 14 1312 1110 9 8 7 6 5 4 3 2 1 0 tToli J ofolifolafofrt rf afof rps] of vatue asz6 nex \ /\ / VO V Odd, high byte Even, low byte c 16-Bit Computer Word with Left-to Right Byte and Bit Order Bit number
(decimal) 01 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ofililiadotlidrpotr1poprfp of} of 1] of] 14 Value A576 hex (after byte swapping)
\, _/ \ / V Vv
Even, high byte Odd, low byte d 16-Bit Computer Word with Left-to Right Byte Order and Right-to-Left Bit Order Bit number (decimal) 15 1418 12 1110 9 8 7 6 5 4 3 2 1 =90 ofilidtifvoyraprapotrpogpripoyorps1gog1 fy Value A576 hex (after byte swapping)
\ /\ _/ Vv Vo
Even, high byte Odd, low byte
11396
Figure 6.6 a, b, c, & d, Results of Transmitting Low Byte First
6.2.1.1 PLC and PLC-2 Family controllers access their data tables by PLC/PLC-2 using an octal word address. In PLC/PLC-2 command messages, this type of logical word address must be represented as an equivalent byte address. This byte address appears in the 2-byte field labeled ADDR in the message block formats (chapter 5).
To encode a logical PLC/PLC-2 address, convert the octal word address to whatever number system you are using in your computer application programs. Next, double this converted word address to get the corresponding byte address. Place the result in the ADDR field, low byte first.
Page 148
Page 6-8 Data Manipulation
6.2.1.2 PLC-3
For example, to address PLC word 020, you would first convert the octal value 20 to the desired base. In this example, lets use hexadecimal values. Octal 20 is 10 hex. Doubling this value gives 20 hex for the byte address. You would then code the value 0020 hex in the ADDR field of the message, low byte first. In binary format, ADDR would look like:
ADDR
First Byte Second Byte
OFO}T{OJOJOJOJO] JO;OfOlOJOjOIOIO
Low Byte High Byte (value 20 hex) (value 00 Hex)
NOTE: PLC and PLC-2 Family controllers use this same logical addressing format when they transmit command messages to another station. If you plan to transmit a command message to your computer from one of these PCs, you should set up a buffer space in your computer to simulate PC memory. You would then have to write computer application programs to accept and execute commands from the PC stations and to translate the ADDR value into the corresponding address in the simulated PC memory.
PLC-3 controllers use a form of logical addressing known as extended addressing. With extended addressing, you specify the address for each level (or subdivision) of PLC-3 memory, down to the smallest subdivision you want to access. You can use this method to specify up to 6 levels of PLC-3 extended addressing, which is enough to give the address of a particular word in PLC-3 memory.
To send a command message to a PLC-3 station, you would put the extended address in the field labeled “PLC-3 extended addr” in the message block formats (chapter 5). Figure 6.7 shows an example of how to enter a PLC-3 extended address in this message field.
The first byte in the extended address field is a set of bit flags that indicate which addressing levels are specified in the bytes following the bit flags. If a flag bit is set to 1, the address bytes must contain a specification for the corresponding level of the extended address. If a flag bit is zero, the address bytes should not contain a specification for that addressing level; instead, a default value is assumed.
For level: The default address is:
1 3 (data table) 2 Current context All others 0
Page 149
Page 6-9 Data Manipulation
You must always specify the value for the last level of the desired extended address, even if it is the default value.
If the address values can be specified in one byte each, then you can code the values directly. If it takes two bytes to specify an address, then you must use a delimiter byte of value FF hex before each 2-byte address. Any 2-byte value should be encoded low byte first.
PLC-3 Extended Address
Level 1 Levei 2 Level 3 Level 4 Level 5 Level 6
Logical Addressing Format
Always zero
Byte 1
Byte 2 Byte 3 Byte 4 Byte 5 Byte 6
Byte 1, is the flag byte. In this case it indicates that the addresses for levels 3, 5, and 6are specified inthe bytes that follow. Default values are used for the levels 1, 2, and 4.
Byte 2, is the value of the level-3 address. Byte 3, is a delimeter that says the next two bytes are one address. Byte 4, is the low byte of the level-5 address.
Byte 5, is the high byte of the level-5 address. Note that bytes 4 and 5 together give a value of 260 for the level-5 address.
Byte 6, is the value of the level-6 address. Even though it is the default value, it must be speccified because it is the last level in the desired extended address.
E3.1.2.0.260.0
(lt
Flag bit for level: 6543 2 1
Lofolsfsfolsfofo] cevei2 (Betautt=1 for current context)
aolo}o}ojoloa]1]o / - Level 3 (Value=2) Level 4 (Default=0)
TP ataypqrya}ayq dd
Q0};0/0)/0]/011)0]0 Level 5 (Value=260)
0; O10; 01/0 o}1
O,0];0]0]0 040 j~e - Level 6 (Value-0}
11261
Figure 6.7, Example of PLC-3 Logical Addressing Format
Page 150
Page 6-10 Data Manipulation
6.2.1.3 PLC-4 Microtrol
In Figure 6.7, the first byte contains the bit flags to indicate which addressing levels are specified. In this example, only levels 3, 5, and 6 are specified; default values are used for the other levels.
In Figure 6.7, the level-5 address is 260 (decimal), which is too large to fit in one byte. Therefore, a byte of all 1’s is used to delimit the 2-byte address value for this level. The value 260 is then coded low byte first. Note that the last level (level 6 in this example) must be specified in the address field even though it is equal to the default value of zero.
NOTE: PLC-3 controllers can also accept PLC/PLC-2 type command messages with the PLC/PLC-2 logical addressing format. Before sending this type of command to a PLC-3 station, you must first allocate a PLC-3 input file to simulate PLC/PLC-2 memory (refer to publication 1775-802). In addition, PLC-3 controllers can transmit both PLC-3 and PLC/PLC-2 type command messages, each with its appropriate logical addressing format. Therefore, if you plan to transmit commands from a PLC-3 to your computer, you should set up a computer buffer to simulate a PLC-3 file and write computer application programs that are capable of interpreting all the types of addressing formats that will appear in the command messages.
PLC-4 Microtrol controllers use a form of logical addressing that specifies the identification number of the controller in the loop, the section of memory, and the bit address. To specify a PLC-4 logical address in a command message, you would use the appropriate binary code listed in Table 6.A. Note that these binary codes let you address only PLC-4 words, not bits.
PLC-4 controllers can accept only PLC/PLC-2 type non-privileged commands. The binary code for the PLC-4 logical address goes in the 2-byte field labeled ADDR in the PLC/PLC-2 message block formats (chapter 5). Put the low byte (bits 0 through 7) of the binary address code into the first byte of ADDR.
For example, suppose we want to address storage word 4 in controller 3 in a PLC-4 Microtrol loop. The binary code for this address is:
00000000 00110100
In the command message that accesses this storage word, the ADDR field would be:
ADDR
First Byte Second Byte
O;O;T{OLO;O/O]O]} fOla;olo;olojolo