plc numbers - 13.1 Encoded values; BCD and ASCII Error detection; parity, gray code and checksums



Similar documents
EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Memory is implemented as an array of electronic switches

The string of digits in the binary number system represents the quantity

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Systems I: Computer Organization and Architecture

ASCII Code. Numerous codes were invented, including Émile Baudot's code (known as Baudot

2011, The McGraw-Hill Companies, Inc. Chapter 3

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Chapter 1. Binary, octal and hexadecimal numbers

Chapter 4: Computer Codes

Chapter 5. Binary, octal and hexadecimal numbers

Xi2000 Series Configuration Guide

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Voyager 9520/40 Voyager GS9590 Eclipse 5145

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Binary, Hexadecimal, Octal, and BCD Numbers

The ASCII Character Set

Chapter 1: Digital Systems and Binary Numbers

Numbering Systems. InThisAppendix...

BAR CODE 39 ELFRING FONTS INC.

URL encoding uses hex code prefixed by %. Quoted Printable encoding uses hex code prefixed by =.

Digital codes. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

Lecture 11: Number Systems

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Base Conversion written by Cathy Saxton

Number Representation

=

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

BARCODE READER V 2.1 EN USER MANUAL

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

DEBT COLLECTION SYSTEM ACCOUNT SUBMISSION FILE

HOMEWORK # 2 SOLUTIO

The Answer to the 14 Most Frequently Asked Modbus Questions

CPEN Digital Logic Design Binary Systems

ESPA Nov 1984 PROPOSAL FOR SERIAL DATA INTERFACE FOR PAGING EQUIPMENT CONTENTS 1. INTRODUCTION 2. CHARACTER DESCRIPTION

Useful Number Systems

This is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor.

Digital Logic Design. Introduction

Model 200 / 250 / 260 Programming Guide

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Binary Numbers. Binary Octal Hexadecimal

Section 1.4 Place Value Systems of Numeration in Other Bases

NUMBER SYSTEMS. 1.1 Introduction

CSI 333 Lecture 1 Number Systems

BINARY CODED DECIMAL: B.C.D.

Applied Data Communication Lecture 14

BI-300. Barcode configuration and commands Manual

TELOCATOR ALPHANUMERIC PROTOCOL (TAP)

INTERNATIONAL STANDARD

Decimal Number (base 10) Binary Number (base 2)

Barcode Magstripe. Decoder & Scanner. Programming Manual

ASCII CODES WITH GREEK CHARACTERS

Number and codes in digital systems

3. Convert a number from one number system to another

Representação de Caracteres

COMBINATIONAL CIRCUITS

Command Emulator STAR Line Mode Command Specifications

DL910 SERIES. Instruction Manual

Technical Support Bulletin Nr.18 Modbus Tips

COMPSCI 210. Binary Fractions. Agenda & Reading

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 TUTORIAL OUTCOME 2 Part 1

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

Symbols in subject lines. An in-depth look at symbols

Computer Science 281 Binary and Hexadecimal Review

Binary Representation

Security Protection of Software Programs by Information Sharing and Authentication Techniques Using Invisible ASCII Control Codes

Create!form Barcodes. User Guide

Solution for Homework 2

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

ASCII Characters. 146 CHAPTER 3 Information Representation. The sign bit is 1, so the number is negative. Converting to decimal gives

Index...1. Introduction...3. Installation- Keyboard Wedge...3 RS USB...3. Default Setting for each barcode shown as below:...

United States Naval Academy Electrical and Computer Engineering Department. EC262 Exam 1

Digital Electronics Detailed Outline

Experiment # 9. Clock generator circuits & Counters. Eng. Waleed Y. Mousa

CS201: Architecture and Assembly Language

A Step towards an Easy Interconversion of Various Number Systems

CHAPTER 8 BAR CODE CONTROL

Characters & Strings Lesson 1 Outline

IBM Emulation Mode Printer Commands

Sheet 7 (Chapter 10)

CHAPTER 3 Boolean Algebra and Digital Logic

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

Counting in base 10, 2 and 16

PROPERTY MANAGEMENT SYSTEM

SECTION C [short essay] [Not to exceed 120 words, Answer any SIX questions. Each question carries FOUR marks] 6 x 4=24 marks

Scanner Configuration

Chapter 7 Lab - Decimal, Binary, Octal, Hexadecimal Numbering Systems

Cyber Security Workshop Encryption Reference Manual

Process Control and Automation using Modbus Protocol

TAP Interface Specifications

NUMBER SYSTEMS. William Stallings

7-Bit coded Character Set

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Karnaugh Maps & Combinational Logic Design. ECE 152A Winter 2012

Part No. : MUL PROGRAMMING GUIDE

Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6

3.Basic Gate Combinations

Transcription:

plc numbers - 3. Topics: Number bases; binary, octal, decimal, hexadecimal Binary calculations; s compliments, addition, subtraction and Boolean operations Encoded values; BCD and ASCII Error detection; parity, gray code and checksums Objectives: To be familiar with binary, octal and hexadecimal numbering systems. To be able to convert between different numbering systems. To understand s compliment negative numbers. To be able to convert ASCII and BCD values. To be aware of basic error detection techniques. Base 0 (decimal) numbers developed naturally because the original developers (probably) had ten fingers, or 0 digits. Now consider logical systems that only have wires that can be on or off. When counting with a wire the only digits are 0 and, giving a base numbering system. Numbering systems for computers are often based on base numbers, but base 4, 8, 6 and 3 are commonly used. A list of numbering systems is give in Figure 3.. An example of counting in these different numbering systems is shown in Figure 3.. Figure 3. Base 8 0 6 Numbering Systems Name Binary Octal Decimal Hexadecimal Data Unit Bit Nibble Digit Byte 3. NUMBERS AND DATA 3. INTRODUCTION

decimal 0 binary 000 octal 4 plc numbers - 3. hexadecimal c 4 Note: As with all numbering systems Figure 3. Numbers in Decimal, Binary, Octal and Hexadecimal The effect of changing the base of a number does not change the actual value, only how it is written. The basic rules of mathematics still apply, but many beginners will feel disoriented. This chapter will cover basic topics that are needed to use more complex programming instructions later in the book. These will include the basic number systems, conversion between different number bases, and some data oriented topics. Binary numbers are the most fundamental numbering system in all computers. A single binary digit (a bit) corresponds to the condition of a single wire. If the voltage on the wire is true the bit value is. If the voltage is off the bit value is 0. If two or more wires are used then each new wire adds another significant digit. Each binary number will have an equivalent digital value. Figure 3.3 shows how to convert a binary number to a decimal equivalent. Consider the digits, starting at the right. The least significant digit is, and 0 3 4 5 6 7 8 9 0 3 4 5 6 7 8 9 0 0 00 0 0 000 00 00 0 00 0 0 0000 000 000 00 0 3 4 5 6 7 0 3 4 5 6 7 0 3 0 3 4 5 6 7 8 9 a b d ef 0 3 most significant digits are at left, least significant digits are at right. 3. NUMERICAL VALUES 3.. Binary

plc numbers - 3.3 is in the 0th position. To convert this to a decimal equivalent the number base () is raised to the position of the digit, and multiplied by the digit. In this case the least significant digit is a trivial conversion. Consider the most significant digit, with a value of in the 6th position. This is converted by the number base to the exponent 6 and multiplying by the digit value of. This method can also be used for converting the other number system to decimal. 6 = 64 5 = 3 4 = 6 3 = 8 0 0 0 0( ) = 0 0( ) = 0 ( 0 ) = 3 = 4 = 0 = Figure 3.3 Conversion of a Binary Number to a Decimal Number Decimal numbers can be converted to binary numbers using division, as shown in Figure 3.4. This technique begins by dividing the decimal number by the base of the new number. The fraction after the decimal gives the least significant digit of the new number when it is multiplied by the number base. The whole part of the number is now divided again. This process continues until the whole number is zero. This method will also work for conversion to other number bases. ( 6 ) = ( 5 ) = ( 4 ) = 0( 3 ) = 64 3 6 0

start with decimal number 93 for binary (base ) plc numbers - 3.4 93 -------- = 466.0 (0.0) = 0 466 -------- = 33.0 (0.0) = 0 33 -------- = 6.5 (0.5) = 6 -------- = 58.0 (0.0) = 0 58 ----- = 9.0 (0.0) = 0 9 ----- = 4.5 (0.5) = 4 ----- = 7.0 (0.0) = 0 7 -- = 3.5 (0.5) = 3 -- =.5 (0.5) = -- = 0.5 (0.5) = 00000 done multiply places after decimal by division base, in this case it is because of the binary. * This method works for other number bases also, the divisor and multipliers should be changed to the new number bases. Figure 3.4 Conversion from Decimal to Binary Most scientific calculators will convert between number bases. But, it is important to understand the conversions between number bases. And, when used frequently enough the conversions can be done in your head. Binary numbers come in three basic forms - a bit, a byte and a word. A bit is a single binary digit, a byte is eight binary digits, and a word is 6 digits. Words and bytes are

plc numbers - 3.5 shown in Figure 3.5. Notice that on both numbers the least significant digit is on the right hand side of the numbers. And, in the word there are two bytes, and the right hand one is the least significant byte. Figure 3.5 Bytes and Words Binary numbers can also represent fractions, as shown in Figure 3.6. The conversion to and from binary is identical to the previous techniques, except that for values to the right of the decimal the equivalents are fractions. binary: Figure 3.6 MSB 0.0 BYTE LSB 00 0 = 4 + 0 + + 0 + -- + -- = 5.375 4 8 decimal A Binary Decimal Number MSB ( ) 0 WORD 00 0 000 000 most significant byte ( ) 4 -- LSB least significant byte ( ) = 8 -- 3... - Boolean Operations In the next chapter you will learn that entire blocks of inputs and outputs can be used as a single binary number (typically a word). Each bit of the number would correspond to an output or input as shown in Figure 3.7. ( ) = 4 0( ) = 0 ( 0 ) = 0 = = 3

plc numbers - 3.6 There are three motors M, M and M 3 represented with three bits in a binary number. When any bit is on the corresponding motor is on. Figure 3.7 Motor Outputs Represented with a Binary Number We can then manipulate the inputs or outputs using Boolean operations. Boolean algebra has been discussed before for variables with single values, but it is the same for multiple bits. Common operations that use multiple bits in numbers are shown in Figure 3.8. These operations compare only one bit at a time in the number, except the shift instructions that move all the bits one place left or right. Name AND OR NOT EOR NAND shift left shift right etc. Figure 3.8 00 = Motor is the only one on = All three motors are on in total there are n or 3 possible combinations of motors on. Example 000 * 00 000 + 00 000 000 eor 00 000 * 00 000 000 Boolean Operations on Binary Numbers Result 000 00 0 000 0 000 (other results are possible) 000 (other results are possible) 3... - Binary Mathematics Negative numbers are a particular problem with binary numbers. As a result there are three common numbering systems used as shown in Figure 3.9. Unsigned binary numbers are common, but they can only be used for positive values. Both signed and s compliment numbers allow positive and negative values, but the maximum positive values is reduced by half. s compliment numbers are very popular because the hardware and software to add and subtract is simpler and faster. All three types of numbers will be found in PLCs.

Type unsigned signed s compliment plc numbers - 3.7 Description binary numbers can only have positive values. the most significant bit (MSB) of the binary number is used to indicate positive/negative. negative numbers are represented by complimenting the binary number and then adding. Range for Byte 0 to 55-7 to 7-8 to 7 Figure 3.9 Binary (Integer) Number Types Examples of signed binary numbers are shown in Figure 3.0. These numbers use the most significant bit to indicate when a number is negative. decimal binary byte 0000000 0000000 0 00000000-0 0000000-000000 - 000000 Note: there are two zeros Figure 3.0 Signed Binary Numbers An example of s compliment numbers are shown in Figure 3.. Basically, if the number is positive, it will be a regular binary number. If the number is to be negative, we start the positive number, compliment it (reverse all the bits), then add. Basically when these numbers are negative, then the most significant bit is set. To convert from a negative s compliment number, subtract, and then invert the number.

plc numbers - 3.8 decimal binary byte METHOD FOR MAKING A NEGATIVE NUMBER 0000000. write the binary number for the positive 0000000 for -30 we write 30 = 0000 0 00000000 -. Invert (compliment) the number - 0 0000 becomes 0000 3. Add 0000 + 0000000 = 0000 Figure 3. s Compliment Numbers Using s compliments for negative numbers eliminates the redundant zeros of signed binaries, and makes the hardware and software easier to implement. As a result most of the integer operations in a PLC will do addition and subtraction using s compliment numbers. When adding s compliment numbers, we don t need to pay special attention to negative values. And, if we want to subtract one number from another, we apply the twos compliment to the value to be subtracted, and then apply it to the other value. Figure 3. shows the addition of numbers using s compliment numbers. The three operations result in zero, positive and negative values. Notice that in all three operation the top number is positive, while the bottom operation is negative (this is easy to see because the MSB of the numbers is set). All three of the additions are using bytes, this is important for considering the results of the calculations. In the left and right hand calculations the additions result in a 9th bit - when dealing with 8 bit numbers we call this bit the carry C. If the calculation started with a positive and negative value, and ended up with a carry bit, there is no problem, and the carry bit should be ignored. If doing the calculation on a calculator you will see the carry bit, but when using a PLC you must look elsewhere to find it.

0000000 = + = - C+00000000 = 0 ignore the carry bits plc numbers - 3.9 0000000 = 0000000 = + 0 = - + = - = - C+0000000 = Note: Normally the carry bit is ignored during the operation, but some additional logic is required to make sure that the number has not overflowed and moved outside of the range of the numbers. Here the s compliment byte can have values from -8 to 7. Figure 3. Adding s Compliment Numbers The integers have limited value ranges, for example a 6 bit word ranges from - 3,768 to 3,767. In some cases calculations will give results outside this range, and the Overflow O bit will be set. (Note: an overflow condition is a major error, and the PLC will probably halt when this happens.) For an addition operation the Overflow bit will be set when the sign of both numbers is the same, but the sign of the result is opposite. When the signs of the numbers are opposite an overflow cannot occur. This can be seen in Figure 3.3 where the numbers two of the three calculations are outside the range. When this happens the result goes from positive to negative, or the other way. 0 = 7 + 000000 = 3 000000 = -6 C = 0 O = (error) 000000 = -7 + = - 0000000 = -8 C = O = 0 (no error) 000000 = -7 + 0 = - 0 = 7 C = O = (error) Note: If an overflow bit is set this indicates that a calculation is outside and acceptable range. When this error occurs the PLC will halt. Do not ignore the limitations of the numbers. Figure 3.3 Carry and Overflow Bits These bits also apply to multiplication and division operations. In addition the PLC will also have bits to indicate when the result of an operation is zero Z and negative N.

plc numbers - 3.0 Other number bases are typically converted to and from binary for storage and mathematical operations. Hexadecimal numbers are popular for representing binary values because they are quite compact compared to binary. (Note: large binary numbers with a long string of s and 0s are next to impossible to read.) Octal numbers are also popular for inputs and outputs because they work in counts of eight; inputs and outputs are in counts of eight. An example of conversion to, and from, hexadecimal is shown in Figure 3.4 and Figure 3.5. Note that both of these conversions are identical to the methods used for binary numbers, and the same techniques extend to octal numbers also. Figure 3.4 Figure 3.5 6 3 = 4096 6 = 56 6 = 6 f 8 a 3 5(6 3 ) = 8(6 ) = 0(6 ) = 3(6 0 ) = 6440 048 60 3 6365 6 0 = Conversion of a Hexadecimal Number to a Decimal Number 574 ----------- = 357.75 6(0.75) = c 6 357 -------- =.35 6(0.35) = 5 6 ----- =.375 6(0.375) = 6 6 ----- = 0.065 6(0.065) = 6 Conversion from Decimal to Hexadecimal 6 5 c 3.. Other Base Number Systems

plc numbers - 3. Binary Coded Decimal (BCD) numbers use four binary bits (a nibble) for each digit. (Note: this is not a base number system, but it only represents decimal digits.) This means that one byte can hold two digits from 00 to 99, whereas in binary it could hold from 0 to 55. A separate bit must be assigned for negative numbers. This method is very popular when numbers are to be output or input to the computer. An example of a BCD number is shown in Figure 3.6. In the example there are four digits, therefore 6 bits are required. Note that the most significant digit and bits are both on the left hand side. The BCD number is the binary equivalent of each digit. 63 decimal 000 000 00 00 BCD Note: this example shows four digits in two bytes. The hex values would also be 63. Figure 3.6 A BCD Encoded Number Most PLCs store BCD numbers in words, allowing values between 0000 and 9999. They also provide functions to convert to and from BCD. It is also possible to calculations with BCD numbers, but this is uncommon, and when necessary most PLCs have functions to do the calculations. But, when doing calculations you should probably avoid BCD and use integer mathematics instead. Try to be aware when your numbers are BCD values and convert them to integer or binary value before doing any calculations. When dealing with non-numerical values or data we can use plain text characters and strings. Each character is given a unique identifier and we can use these to store and interpret data. The ASCII (American Standard Code for Information Interchange) is a very common character encryption system is shown in Figure 3.7 and Figure 3.8. The table includes the basic written characters, as well as some special characters, and some control codes. Each one is given a unique number. Consider the letter A, it is readily recognized by most computers world-wide when they see the number 65. 3..3 BCD (Binary Coded Decimal) 3.3 DATA CHARACTERIZATION 3.3. ASCII (American Standard Code for Information Interchange)

plc numbers - 3. Figure 3.7 ASCII Character Table 0 3 4 5 6 7 8 9 0 3 4 5 6 7 8 9 0 3 4 5 6 7 8 9 30 3 0 3 4 5 6 7 8 9 A B C D E F 0 3 4 5 6 7 8 9 A B C D E F 00000000 0000000 0000000 000000 0000000 000000 000000 00000 0000000 000000 000000 00000 000000 00000 00000 0000 0000000 000000 000000 00000 000000 00000 00000 0000 000000 00000 00000 0000 00000 0000 0000 000 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR S0 S DLE DC DC DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US decimal hexadecimal binary ASCII 3 33 34 35 36 37 38 39 40 4 4 43 44 45 46 47 48 49 50 5 5 53 54 55 56 57 58 59 60 6 6 63 0 3 4 5 6 7 8 9 A B C D E F 30 3 3 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 0000000 000000 000000 00000 000000 00000 00000 0000 000000 00000 00000 0000 00000 0000 0000 000 000000 00000 00000 0000 00000 0000 0000 000 00000 0000 0000 000 0000 000 000 00 space! # $ % & ( ) * +, -. / 0 3 4 5 6 7 8 9 : ; < = >? decimal hexadecimal binary ASCII

64 65 66 67 68 69 70 7 7 73 74 75 76 77 78 79 80 8 8 83 84 85 86 87 88 89 90 9 9 93 94 95 plc numbers - 3.3 40 0000000 @ 96 60 000000 4 000000 A 97 6 00000 a 4 000000 B 98 6 00000 b 43 00000 C 99 63 0000 c 44 000000 D 00 64 00000 d 45 00000 E 0 65 0000 e 46 00000 F 0 66 0000 f 47 0000 G 03 67 000 g 48 000000 H 04 68 00000 h 49 00000 I 05 69 0000 i 4A 00000 J 06 6A 0000 j 4B 0000 K 07 6B 000 k 4C 00000 L 08 6C 0000 l 4D 0000 M 09 6D 000 m 4E 0000 N 0 6E 000 n 4F 000 O 6F 00 o 50 000000 P 70 00000 p 5 00000 Q 3 7 0000 q 5 00000 R 4 7 0000 r 53 0000 S 5 73 000 s 54 00000 T 6 74 0000 t 55 0000 U 7 75 000 u 56 0000 V 8 76 000 v 57 000 W 9 77 00 w 58 00000 X 0 78 0000 x 59 0000 Y 79 000 y 5A 0000 Z 7A 000 z 5B 000 [ 3 7B 00 { 5C 0000 yen 4 7C 000 5D 000 ] 5 7D 00 } 5E 000 ^ 6 7E 00 r arr. 5F 00 _ 7 7F 0 l arr. Figure 3.8 ASCII Character Table This table has the codes from 0 to 7, but there are more extensive tables that contain special graphics symbols, international characters, etc. It is best to use the basic codes, as they are supported widely, and should suffice for all controls tasks. decimal hexadecimal binary ASCII decimal hexadecimal binary ASCII

plc numbers - 3.4 An example of a string of characters encoded in ASCII is shown in Figure 3.9. e.g. The sequence of numbers below will convert to A W e e T e s t A 65 space 3 W 87 e 0 e 0 space 3 T 84 e 0 s 5 t 6 Figure 3.9 A String of Characters Encoded in ASCII When the characters are organized into a string to be transmitted and LF and/or CR code are often put at the end to indicate the end of a line. When stored in a computer an ASCII value of zero is used to end the string. Errors often occur when data is transmitted or stored. This is very important when transmitting data in noisy factories, over phone lines, etc. Parity bits can be added to data as a simple check of transmitted data for errors. If the data contains error it can be retransmitted, or ignored. A parity bit is normally a 9th bit added onto an 8 bit byte. When the data is encoded the number of true bits are counted. The parity bit is then set to indicate if there are an even or odd number of true bits. When the byte is decoded the parity bit is checked to make sure it that there are an even or odd number of data bits true. If the parity bit is not satisfied, then the byte is judged to be in error. There are two types of parity, even or odd. These are both based upon an even or odd number of data bits being true. The odd parity bit is true if there are an odd number of bits on in a binary number. On the other hand the Even parity is set if there are an even number of true bits. This is illustrated in Figure 3.0. 3.3. Parity

Odd Parity Even Parity plc numbers - 3.5 data bits parity bit Figure 3.0 Parity Bits on a Byte Parity bits are normally suitable for single bytes, but are not reliable for data with a number of bits. Note: Control systems perform important tasks that can be dangerous in certain circumstances. If an error occurs there could be serious consequences. As a result error detection methods are very important for control system. When error detection occurs the system should either be robust enough to recover from the error, or the system should fail-safe. If you ignore these design concepts you will eventually cause an accident. Parity bits are suitable for a few bits of data, but checksums are better for larger data transmissions. These are simply an algebraic sum of all of the data transmitted. Before data is transmitted the numeric values of all of the bytes are added. This sum is then transmitted with the data. At the receiving end the data values are summed again, and the total is compared to the checksum. If they match the data is accepted as good. An example of this method is shown in Figure 3.. 000 0000 0 00000 00 0 3.3.3 Checksums

DATA 4 43 55 9 7 47 CHECKSUM 505 plc numbers - 3.6 Figure 3. A Checksum Checksums are very common in data transmission, but these are also hidden from the average user. If you plan to transmit data to or from a PLC you will need to consider parity and checksum values to verify the data. Small errors in data can have major consequences in received data. Consider an oven temperature transmitted as a binary integer (03d = 0000 000 0000 0000b). If a single bit were to be changed, and was not detected the temperature might become (0000 00 0000 0000b = 535d) This small change would dramatically change the process. Parity bits and checksums are for checking data that may have any value. Gray code is used for checking data that must follow a binary sequence. This is common for devices such as angular encoders. The concept is that as the binary number counts up or down, only one bit changes at a time. Thus making it easier to detect erroneous bit changes. An example of a gray code sequence is shown in Figure 3.. Notice that only one bit changes from one number to the next. If more than a single bit changes between numbers, then an error can be detected. ASIDE: When the signal level in a wire rises or drops, it induces a magnetic pulse that excites a signal in other nearby lines. This phenomenon is known as cross-talk. This signal is often too small to be noticed, but several simultaneous changes, coupled with background noise could result in erroneous values. 3.3.4 Gray Code

Figure 3. Gray Code for a Nibble plc numbers - 3.7 decimal gray code Binary, octal, decimal and hexadecimal numbers were all discussed. s compliments allow negative binary numbers. BCD numbers encode digits in nibbles. ASCII values are numerical equivalents for common alphanumeric characters. Gray code, parity bits and checksums can be used for error detection.. Why are binary, octal and hexadecimal used for computer applications?. Is a word is 3 nibbles? 3. What are the specific purpose for Gray code and parity? 4. Convert the following numbers to/from binary 0 3 4 5 6 7 8 9 0 3 4 5 0000 000 00 000 00 0 00 000 00 0 0 00 0 00 000 3.4 SUMMARY 3.5 PRACTICE PROBLEMS

plc numbers - 3.8 a) from base 0: 54,3 b) from base : 000000 5. Convert the BCD number below to a decimal number, 00 000 0 00 6. Convert the following binary number to a BCD number, 000 0 7. Convert the following binary number to a Hexadecimal value, 000 0 8. Convert the following binary number to a octal, 000 0 9. Convert the decimal value below to a binary byte, and then determine the odd parity bit, 97 0. Convert the following from binary to decimal, hexadecimal, BCD and octal. a) 00 c) 000000000 b) 00 d) 000000

plc numbers - 3.9. Convert the following from decimal to binary, hexadecimal, BCD and octal. a) c) 0456 b) 7 d) -0. Convert the following from hexadecimal to binary, decimal, BCD and octal. a) c) ABC b) 7 d) -A 3. Convert the following from BCD to binary, decimal, hexadecimal and octal. a) 00 c) 00 00 000 b) 00 00 d) 0000 00 0 000 4. Convert the following from octal to binary, decimal, hexadecimal and BCD. a) 7 c) 777 b) 7 d) 3634 5. a) Represent the decimal value thumb wheel input, 353, as a Binary Coded Decimal (BCD) and a Hexadecimal Value (without using a calculator). i) BCD ii) Hexadecimal b) What is the corresponding decimal value of the BCD value, 000000? 6. Add/subtract/multiply/divide the following numbers. a) binary 000 + 00000 b) hexadecimal 0 + ABC c) octal 3 + 777 d) binary 00-00 e) hexadecimal ABC - 3 f) octal 777-3 g) binary 00-00 h) hexadecimal 3-ABC i) octal 3-777 j) s complement bytes 00 + 000000 k) s complement bytes 000 + 000000 l) binary 000 * 00 m) octal 3 * 777 n) octal 777 / 3 o) binary 000 / 00 p) hexadecimal ABC / 3

plc numbers - 3.0 7. Do the following operations with 8 bit bytes, and indicate the condition of the overflow and carry bits. a) 00 + 000000 d) 00-00 b) 000 + 000000 e) 000 + 00 c) 00 + 0 f) 000-00 8. Consider the three BCD numbers listed below. 00 00 00 000 000 000 00 000 000 00 00 000 a) Convert these numbers to their decimal values. b) Convert the decimal values to binary. c) Calculate a checksum for all three binary numbers. d) What would the even parity bits be for the binary words found in b). 9. Is the nd bit set in the hexadecimal value F49? 0. Explain where grey code occurs when creating Karnaugh maps.. Convert the decimal number 000 to a binary number, and then to hexadecimal.. base, 4, 8, and 6 numbers translate more naturally to the numbers stored in the computer.. no, it is four nibbles 3. Both of these are coding schemes designed to increase immunity to noise. A parity bit can be used to check for a changed bit in a byte. Gray code can be used to check for a value error in a stream of continuous values. 4. a) 0 000 00 000, b) 37 5. 679 6. 0 00 7. 4B 8. 3 3.6 PRACTICE PROBLEM SOLUTIONS

plc numbers - 3. 9. 0000 odd parity bit = 0. binary 00 00 000000000 000000 BCD 000 00 000 000 00 000 0000 000 00 000 000 00 000 decimal 45 9 05 46 hex D 5D 40 5B5 octal 55 333 00 665. decimal 7 0456-0 BCD 000 000 0 000 0000 000 00 00-000 0000 binary 000 000 0 000 00 hex 4FE8 FFF6 octal 47750 77766. hex 7 ABC -A BCD 000 000 00 000 0 000 000-000 0000 binary 0 0000 00 0 00 00 decimal 3 748-0 octal 7 574 77766 3. BCD 00 00 00 00 00 000 0000 00 0 000 binary 00 0 0 00 00 0 00 0 decimal 9 93 36 0574 hex 9 5D 69 3E octal 35 55 076

4. octal binary decimal hex BCD plc numbers - 3. 5. a) 353 = 00 00 00 000 = DCC, b0 the number is not a valid BCD 6. 7. 7 7 777 3634 00 00 00 00 7 5 5 374 7 F FF 359C 0 000 00 00 000 000 000 00 0 000 000 a) 000 00 0 000 b) BBD c) d) 0000 000 000 000 e) 999 f) 654 g) 0 0 000 h) -999 a) 00 + 000000=0 0 b) 000 + 000000=00 0 c) 00 + 0=0 00+C+O i) -654 j) 0000 000 0 00 k) 0000 0000 00 0 l) 000 0 000 m) 655 n) 6 o) 0000 0000 000 000 p) 9 d) 00-00=00 000+C+O e) 000 + 00=0 00 f) 000-00=00 000 8. a) 965, 438, 435, b) 000 00 0 00, 0000 00 000 00, 000 0000, c) 6440, d), 0, 0 9. The binary value is 000 00, so the second bit is 0 0. when selecting the sequence of bit changes for Karnaugh maps, only one bit is changed at a time. This is the same method used for grey code number sequences. By using the code the bits in the map are naturally grouped.

. plc numbers - 3.3 000 0 = 0000 = 3e8 6. Why are hexadecimal numbers useful when working with PLCs? 3.7 ASSIGNMENT PROBLEMS