18
Codes by Dr. Amin Danial Asham

Codes by Dr. Amin Danial Asham. References Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

Embed Size (px)

Citation preview

Page 1: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

Codes

by

Dr. Amin Danial Asham

Page 2: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

References

Programmable Controllers-Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

Page 3: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

IV. BINARY CODES An important requirement of programmable controllers is communication with

various external devices that either supply information to the controller or receive information from the controller. This input/output function involves the transmission, manipulation, and storage of binary data that, at some point, must be interpreted by humans. Although machines can easily handle this binary data, we require that the data be converted to a more interpretable form.

One way of satisfying this requirement is to assign a unique combination of 1s and 0s to each number, letter, or symbol that must be represented. This technique is called binary coding.

In general, there are two categories of codes:a) those that represent numbers only b) and those that represent letters, symbols, and decimal numbers.

Several codes for representing numbers, symbols, and letters are standard throughout the industry. Among the most common are the following:a) ASCIIb) BCDc) Gray

Page 4: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

IV. BINARY CODES(continue)a) ASCII Alphanumeric codes (which use a combination of letters, symbols, and

decimal numbers) are used when information processing equipment, such as printers and displays, must process the alphabet along with numbers and special symbols.

These alphanumeric characters—26 letters (uppercase), 10 numerals (0-9), plus mathematical and punctuation symbols— can be represented using a 6-bit code (i.e., 26 = 64 possible characters).

The most common code for alphanumeric representation is ASCII (the American Standard Code for Information Interchange).

An ASCII (pronounced as-kee) code can be 6, 7, or 8 bits. Although a 6-bit code (64 possible characters) can accommodate the basic

alphabet, numbers, and special symbols, standard ASCII character sets use a 7-bit code (27 = 128 possible characters), which provides room for lower case and control characters, in addition to the characters already mentioned.

This 7-bit code provides all possible combinations of characters used when communicating with peripherals and interfaces.

Page 5: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

IV. BINARY CODES(continue)

a) ASCII (continue) An 8-bit ASCII code is used when parity check is added to

a standard 7-bit code for error-checking purposes (note that all eight bits can still fit in one byte). shows the binary ASCII code representation of the letter Z (1328).

This letter is generally sent and received in serial form between the PLC and other equipment.

Page 6: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

IV. BINARY CODES(continue)

a) ASCII (continue)

A typical ASCII transmission, again using the character Z as an example.

Note that extra bits have been added to the beginning and end of the character to signify the start and stop of the ASCII transmission.

Page 7: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

IV. BINARY CODES(continue)

a) ASCII (continue)7-bit ASCII Code

Page 8: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

IV. BINARY CODES(continue)

b) BCD The binary coded decimal (BCD) system was introduced as a convenient way for

humans to:i. handle numbers that must be input to digital machines and ii. interpret numbers that are output from machines.

The decimal system uses the numbers 0 through 9 as its digits, whereas BCD represents each of these numbers as a 4-bit binary number. The following table illustrates the relationship between the BCD code and the binary and decimal number systems.

Page 9: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

IV. BINARY CODES(continue)

b) BCD (continue) The BCD representation of a decimal number is obtained by replacing each

decimal digit with its BCD equivalent. The BCD representation of decimal 7493 is shown here as an example:

Typical PLC applications of BCD codes include data entry (time, volume, weight, etc.)

o Via thumbwheel switches (TWS),

o Data display via seven-segment

displays,

o Input from absolute encoders, and analog input/output

instructions

Page 10: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

IV. BINARY CODES(continue)

c) GRAY

The Gray code is suited primarily for position transducers. It is basically a binary code that has been modified in such a way

that only one bit changes as the counting number increases.

1-digits change

4-digits change

In standard binary, as many as four digits can change when counting with as few as four binary digits.

This drastic change is seen in the transition from binary 7 to 8.

Page 11: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

IV. BINARY CODES(continue)

c) GRAY (continue) The Gray code is used in applications in which the normal sequence of

binary numbers may produce an error or ambiguity during the transition from one number to the next.

If binary numbers are used. A change. for example from 0111 to 1000 may produce an intermediate erroneous number 1001 if the value of the rightmost bit takes longer to change than do the values of the other three bits

Page 12: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

IV. BINARY CODES (continue)

b) GRAY (continue) An example of a Gray code application is an optical absolute encoder. In this

encoder, the rotor disk consists of opaque and transparent segments arranged in a Gray code pattern and illuminated by a light source that shines through the transparent sections of the rotating disk. The transmitted light is received at the other end in Gray code form and is available for input to the PLC in either Gray code or BCD code, if converted.

Page 13: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

V. REGISTER WORD FORMATS As previously mentioned, a programmable controller performs all of its

internal operations in binary format using 1s and 0s. In addition, the status of I/O field devices is also read and written, in binary

form, to and from the PLC’s CPU. Each binary piece of data is a bit. Eight bits make up one byte. One or

more bytes make up a word depending on the processor type. A PLC word is also called a register or location. Although the data stored in a register is represented by binary 1s and 0s,

the format in which this binary data is stored may differ from one programmable controller to another. Generally, data is represented in either straight (non-coded) binary or binary coded decimal (BCD) format.

ByteWord(16-bit register)

Page 14: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

V.REGISTER WORD FORMATS1) BINARY FORMAT Data stored in binary format can be directly converted to its

decimal equivalent without any special restrictions. In this format, a 16-bit register can represent a maximum

value of 6553510.

The value 6553510 in binary format all bits are 1.

Page 15: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

V. REGISTER WORD FORMATS

1) BINARY FORMAT (continue) The binary format represents the status of a device as either

0 or 1, which is interpreted by the programmable controller as ON or OFF.

Hence, 16-bits word may store the statuses of sixteen devices.

If the most significant bit of the register is used as a sign bit, then the maximum decimal value that the 16-bit register can store is +3276710 or –3276710 in 2’s complement.

Page 16: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

V. REGISTER WORD FORMATS (continue)

2) BCD FORMAT The BCD format uses four bits to represent a single decimal digit. The

only decimal numbers that these four bits can represent are 0 through 9. In BCD format, a 16-bit register can hold up to a 4-digit decimal value,

with the decimal values that can be represented ranging from .

In a PLC, the BCD values stored in a register or word can be the result of BCD data input from a thumbwheel switch. A 4-digit thumbwheel switch will use a 16-bit register to store the

BCD output.

0110

Page 17: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

V. REGISTER WORD FORMATS (continue)2) BCD FORMAT (continue)

Example:Illustrate how a PLC’s 16-bit register containing the BCD number 7815 would connect to a 4-digit, seven-segment display. Indicate the most significant digit and the least significant digit of the seven-segment display.

SolutionThe BCD output from the PLC register or word is sent to the seven-segment indicator through an output interface during the write section of the scan

Page 18: Codes by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan

Thanks