Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeContact

The text of a manual · part 24 of 31

DF1 Protocol and Command Set Reference Manual: 11 - Data Encoding

Pages 197 to 203 of 251, from DF1 Protocol and Command Set Reference Manual

The original document is the PDF (2.1 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.

Filed in the catalog under the Allen-Bradley 5250-LP and Allen-Bradley 5250-MLP1

Page 197

Chapter

11

Data Encoding This chapter provides:

• definitions of numbering systems you can use in your application • a message packet’s order of transmission It contains these sections: Section

Page

Numbering Systems

11-2

Order of Transmission

11-6

Publication 1770-6.5.16 - October 1996

Page 198

11–2

Data Encoding

Numbering Systems

In general, PLC processors store binary data (1s and 0s) 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 numbering systems to represent data in your computer application programs: Numbering System decimal

Page 11-2 binary

11-3 binary coded decimal

11-3 hexadecimal

11-4 octal

11-5 binary floating point

11-5

Important: You must design your computer application programs to make any necessary conversions from one numbering system to another. Once you have selected the numbering system that is best for your applications, use that numbering system and convert all data values to that base.

Decimal The decimal numbering system is easy to use because it is most familiar. It uses the digits 0 through 9, and each digit has a place value that is a power of 10. Despite the convenience of decimal numbers, it is often easier to convert binary data to a numbering system other than decimal. Decimal Representation, Number 239 2

2 x 10 = 200 1

3 x 10 = 30 0

9 x 10 = 2

3

239 10

9 10

Publication 1770-6.5.16 - October 1996

9

Page 199

Data Encoding

11–3

Binary The binary numbering system is a simple method for computer and PLC applications because it is the most natural way to represent data bits. However, since the binary system uses the digits 0 and 1, it is cumbersome to show values in binary format. Each digit in a binary number has a place value expressed as a power of 2. You 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. Binary Representation, Number 239 1 x 27 = 128 1 x 26 = 64 1 x 25 = 32 1 x 24 = 0 1 x 23 = 8 1 x 22 = 4 1 x 21 2 1 x 20 1 Bit:

1

1

1

0

1

1

1

1

7

6

5

4

3

2

1

0

23910

Binary Coded Decimal PLC data is often represented in binary coded decimal (BCD) form. In this system, each group of four bits in a PLC 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. Many PLCs use only a three-digit BCD (12 bits). The upper digit (3 bits) is used for information such as timer or counter status. BCD Representation of Decimal 239 0 x 23 = 0 0 x 22 = 0 1 x 21 = 2 0 x 20 = 0

= 210 0 x 23 = 0 0 x 22 = 0 1 x 21 = 2 1 x 20 = 1

= 310 1 x 23 = 8 0 x 22 = 0 0 x 21 = 0 1 x 20 = 1

0

0 first digit

1

0

0

0

1 second digit

1

1

0

0

1

= 910

= 23910 third digit

Publication 1770-6.5.16 - October 1996

Page 200

11–4

Data Encoding

Hexadecimal The hexadecimal (hex) numbering system is the most compact way to represent binary data and allows for the easiest conversion to and from binary. Hex uses 16 digits, numbers 0 to 9 and letters A to F. (Letters A to F are equivalent to the decimal numbers 10 to 15, respectively.) Each group of four data bits represents one hex digit between 0 and F. Thus, each 16-bit data word can have a hex value between 0 and FFFF. Each digit of a hex number has a place value that is a 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. Hexadecimal Representation of Decimal 423 0 x 163 = 0

0 x 23 = 0 0 x 22 = 0 0 x 21 = 0 0 x 20 = 0

1 x 162 = 256

0 x 23 = 0 0 x 22 = 0 0 x 21 = 0 1 x 20 = 1

10 x 161 = 160

1 x 23 = 8 0 x 22 = 0 1 x 21 = 2 0 x 20 = 0 0x2=0 1 x 22 = 4 1 x 21 = 2 0 x 20 = 1

0

0

0 0

Publication 1770-6.5.16 - October 1996

0

0

0

0 1

1

1

0

1 A

0

0

1

1 7

7 x 160 = 7

1 = 01A716 42310

Page 201

Data Encoding

11–5

Octal The octal number system is another 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. 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. Octal Representation of Decimal 239 1 x 21 = 2 1 x 20 = 1

1

1

1

0

3 x 82 = 192 1 x 22 = 4 0 x 21 = 0 1 x 20 = 1

1

1

1

1 x 22 = 4 1 x 21 = 2 1 x 20 = 1 1

5 x 81 =

40

7 x 80 =

7

= 3578 23910

Binary Floating-point Use the binary floating-point numbering system when you want to manipulate numbers outside of the range –32768 to +32768 or for a resolution finer than one unit, for example 2.075. SLC 5/03 OS300, SLC 5/04 OS400, and PLC-5 classic processors do not support unnormalized, Not a Number (NaN), and infinity; PLC-5 enhanced processors support both NaN and infinity. The valid range for a binary floating-point number is $3.402824 x 1038 to $1.1754944 x 10–38.

Publication 1770-6.5.16 - October 1996

Page 202

11–6

Data Encoding

Order of Transmission

PLC processors store data in 16-bit (2-byte) words. The bits in these words are numbered (addressed) 0 through 17 octal, going from right to left within a word, as follows: PLC Word Bits:

17

16 15

14

13

12

11

10

07

06

05

04

02

03

01

00

When a module transmits data over its asynchronous 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, the Universal Asynchronous Receiver/Transmitter (UART) transmits the low bit first within a byte. First Byte Bits: 00

01 02

Second Byte 03

04

05

06

07

10

11 12 13

14

15

16

17

This does not present a problem at PLC nodes on the link because PLC processors store and retrieve their data in this same order of low byte first. Depending on the type of computer, however, you may have to do some extra computer application programming to maintain the proper byte and word order in PLC data stored in the computer. Three factors that can influence the ability of your computer to handle PLC data are: • the size of words in your computer’s memory • 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, design your application programs to make the proper conversions from PLC word addresses to computer word addresses. When stored in a computer, each PLC word should start on an even byte boundary. The following figures show 16-bit words in PLC and computer memory. (In all cases, the address of a word is the address of the even byte - assuming that each word is properly aligned on an even boundary.)

Publication 1770-6.5.16 - October 1996

Page 203

Data Encoding

11–7

A 16-Bit Word in PLC Memory Bit (Octal)

17

16

15

14

13

12

11

10

7

6

5

4

3

2

1

0

1

0

1

0

0

1

0

1

0

1

1

1

0

1

1

0

Odd, high byte

Even, low byte

Value - A576 hex

A 16-Bit Computer Word with Left-to-Right Byte and Bit Order This figure 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 8088 microprocessor). If your computer has this type of word order, the conversion is straightforward. Bit (Decimal)

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

1

0

1

0

0

1

0

1

0

1

1

1

0

1

1

0

Odd, high byte

Even, low byte

Value - A576 hex

A 16-Bit Computer Word with Right-to-Left Byte and Bit Order This figure 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. Bit 0 (Octal)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

0

1

1

1

0

1

1

0

1

0

1

0

0

1

0

0

Even, low byte

Odd, high byte Value - A576 hex (after byte swapping)

A 16-Bit Computer Word with Left-to-Right Byte Order and Right-to-Left Bit Order This figure 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 PLC must be stored in the following order: 1,0,3,2,5,4,7,6,9,8. . . Bit (Decimal)

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

0

1

1

1

0

1

1

0

1

0

1

0

0

1

0

0

Even, low byte

Odd, high byte Value - A576 hex (after byte swapping)

Publication 1770-6.5.16 - October 1996