Вы находитесь на странице: 1из 62

Digital Logic

Habib Hamam (P.Eng. Ph.D. HDR.)

2007-2008
Habib.Hamam@umoncton.ca
Habib@cud.ac.ae

1
Table of contents - 1
Textbook ………...……………………………..……….…………………………..… 6
Learning outcomes ………...………………..……….…………………………..… 7
Chapter 1: Numerical systems ……………..……………….……………........…. 8
Learning outcomes ….…………………………………...……..…..…………….………… 9
4 commonly used systems …………………………….………………………..……….… 11
Conversions ……………………………….……………………………………………….. 17
Interest of these codes …………………….……………………….………………...…..... 30
BCD code ……………………………………...……….……………………………..….…. 35
Gray code …………………………………………..……….………………………………. 40
Other codes …………………………………………..……….……….……………...……. 45
Error detection …………………………………………..……….……….…………..……. 48
Quiz …………………………………………..……….……….…………………..…..……. 55
Chapter 2: Arithmetic and logic operations ……………...…..……….….….... 61
Learning outcomes ………………………………......…………………….………....….. 62
Binary operations ……………………...………………..…………………………..….…. 64
Octal operations ……………………………………….…………………………….……. 72
Hexadecimal operations …………………………..…...………………………..….……. 75
Quiz ………………………………………………….………………………...…….… ….. 79

Computer Network Fundamentals Habib Hamam Canadian University of Dubai 2


Table of contents - 2
Chapter3: Basic Logic ……………………………..……………….………..….... 85
Learning outcomes ……………………..…………...………......……………………….. 86
Example ……………………...…………………………..……………………………..…. 89
Truth Table ……………………...…………………………………..……………….……. 96
Basic hardware component …………….……………..…...………………..…….……. 99
Logic gates ………………………………………………….……..………………….….. 103
Case study ……………………………………………..……………….…..…………..... 111
Chapter 4 : Boolean Variables ……………………………………..…........…… 116
Learning outcomes ………………………………………..…..……….…………….…... 117
Boolean variables …………….……………………………..…..……….….……….…... 120
Truth Tables ……………………………………..……….……………………..…….…... 122
Or operation …………………………………………..…..………….….…………….…... 125
And operation ………………………………………..…..…………….………..…….…... 129
Not operation ………………………………………………....……….………..…….…... 132
Algebraic representation …………………..…..……………………………..…….…..... 136
NAND and NOR …………………..…..…………..…………………………..…….…..... 143
Theorems …………………..…..……………………………………………...…….…..... 147
Alternate representations …………………..…..……………………………..…….….... 153
Description Languages …………………..…..………………………………..…….….... 162
Computer Network Fundamentals Habib Hamam Canadian University of Dubai 3
Table of contents - 3
Chapter 5 : Combinatory logic ……………………...………….……… 173
Learning outcomes ………………………………......……………….……………....….. 174
Two forms: SOP & POS ….……………………………..…..…………….……….…..… 176
Algebra simplification …………………………..…………….…………………...…..… 183
Karnaugh Diagram ……………………………….……………………….…………….... 195
Karnaugh Diagram principle ………………….…………………………………....…..... 204
Plotting Functions on the K-map: SOP Form ……………………………...………...…. 210
Simplification of Switching Functions using K-MAPS …………………...……….....…. 215
Typical circuits ……………………………………………………………..…..…….....…. 227
Basic Characteristics of Ics ………………………………………………...……….....…. 237
PLD …………………………………………………………………………...……….....…. 251
Representing data in HDL …………………………………………….…...……….....…. 256
Chapter 6 : Flip-Flops and Related Devices ……………………........…….…. 267
Learning outcomes ………………………………......……………………………....….. 268
NAND Gate Latch ……………………...……………………………………………..…. 272
NOR Gate Latch ……………………...…………………………..………………..……. 282
Digital pulses ……………………...…………………..………………..…………..……. 288
Clock signal ……………………...…………………………..………….…………….…. 292
Clocked S-R Flip-Flop ……………………...…………………………..………….……. 297
Computer Network Fundamentals Habib Hamam Canadian University of Dubai 4
Table of contents - 4
Clocked J-K Flip-Flop ….………..…………………..…..…………………………….… 303
D Flip-Flop …………………………..…………………………….…..…………....…..… 309
Flip-Flop applications …………………………..………………………….……....…..… 317
Using HDL …………………………..………………………….……....……………….… 331
Chapter 7 : Arithmetic logic ………………………...………………..….….….... 338
Learning outcomes ………………………………......……………………………....….. 340
1’s and 2’s complement ……………………...……………………….…………..….…. 342
Half and Full –Adder ……………………...…………………………..……..….….……. 347
Negative numbers …………………………..…...…………………………..…..….….... 362
Multiplexer and Demultiplexer ………………………………………….…………..… … 367
Coder and decoder …………………………………….………………..…………..…..... 374
ALU ………………………………………….……………………………………..…..…... 377
VHDL ……………..…………..……….………………………………………………….… 382
Chapter 9 : IP ………………………………….…………………..…..…........…… 387
Learning outcomes ………………………………………..………….….…………..…... 388
Basic counters ………………………………………..………….………………….…..... 390
Frequency division ………………………………………..……….…….………………... 393
VHDL ………………………………………..……….…….………………..……………... 412

Computer Network Fundamentals Habib Hamam Canadian University of Dubai 5


Table of contents - 5
Chapter 9: Convolution code ………………………...……………..….….….... 419
Learning outcomes ………………………………......……………………………....….. 420
Coding ……………………...……………………….……………………….……..….…. 422
Decoding ……………………...…………………………..……..….……………….……. 431
Viterbi algorithm …………………………..…...………………………….....…..….….... 434
Performances ……………………………………………………….………………..… … 443

Computer Network Fundamentals Habib Hamam Canadian University of Dubai 6


Text book
R. Tocci, N. Widmer
and G. Moss, Digital
Systems: Principles
and Applications,
tenth edition, Prentice
Hall, Canadian Edition,
2007, ISBN-13:
9780131725799

Computer Network Fundamentals Habib Hamam Canadian University of Dubai 7


Learning outcomes
Upon successful completion of this course,
students will able to:
1. Demonstrate knowledge of number systems and
complement arithmetic.
2. Demonstrate knowledge of logic functions, their
minimization and implementation.
3. Design using standard logic devices such as
decoders and multiplexers.
4. Compose technical reports

Digital Logic Habib Hamam Canadian University of Dubai 8


Chapter 1

Numerical systems

9
Section 1

Learning outcomes

10
Learning outcomes
Upon successful completion of this chapter,
students will able to:
1. understand the typical numerical bases :
decimal, binary, hexadecimal and octal
2. master conversion between bases
3. Understand the principle of BCD and Gray
coding
4. understand a typical method for error detections

Digital Logic Habib Hamam Canadian University of Dubai 11


Section 2

4 commonly used systems

12
Bases of calculus
Different bases and systems

base system Example


1 fingers, stones, notches
2 binairy Symbolic logic, computers
5 quinairy aztecs
7 Music notes, days
8 octal computers
10 decimal Adopted by human being
12 notes, money, measures, months
16 hexadecimal computers
20 mayas
24 hours
60 sexagesimal degrees, minutes

Digital Logic Habib Hamam Canadian University of Dubai 13


4 bases
Base 10 (decimal)
Base 2 (binary):
The only digit values are 0 and 1
Used internally in all modern computers

Base 8 (octal):
Digits are 0, 1, 2, 3, 4, 5, 6, 7
Each octal digit represents a sequence of 3 bits

Base 16 (hexadecimal or just “hex”):


Digits are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Where A=ten, B=eleven, …, F=fifteen.
Each hex digit represents a sequence of 4 bits
Digital Logic Habib Hamam Canadian University of Dubai 14
Decimal system
Decimal basis:
Composed of symbols (digits) : 0, 1, 2, 3, 4, 5, 6,
7, 8 and 9
102 101 100 10-1 10-2 10-3

7 1 5 3 6 4
Most Significant Digit Lowest Significant Digit
MSD LSD

715.363 = 7x102 + 1x101 + 5x100 + 3x10-1 + 6x10-2 + 4x10-3

With n digits we can count until 10n different


numbers.
Digital Logic Habib Hamam Canadian University of Dubai 15
Example : base 5
Small boxes in big boxes

113
16
Binary system
Binary basis
Composed of two digits 1 & 0

22 21 20 2-1 2-2 2-3

1 0 1 1 0 1
Most Significant Bit Lowest Significant Bit
MSB LSB

101.101 = 1x22 + 0x21 + 1x20 + 1x2-1 + 0x2-2 + 1x2-3


= 4 + 0 + 1 + 0.5 + 0 + 0.125
(101.101)2 = (5.625)10

With n bits we can count until 2n different numbers.


Digital Logic Habib Hamam Canadian University of Dubai 17
Octal & Hexadecimal
Octal system: Basis 8 (23)
Hexadecimal system: Basis 16 (24)

Decimal Binary Octal Hexadecimal


1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
16 1 0000 20 10
... ... ... ...

Digital Logic Habib Hamam Canadian University of Dubai 18


Section 3

Conversions

19
Binary to decimal Conversion
To convert binary numbers into decimal
numbers, we only need to sum powers with non
zero weights (with power ‘1’) :

11012 = 1x23 + 1x22 + 0x21 + 1x20


= 8 + 4 + 0 + 1 = 1310

Digital Logic Habib Hamam Canadian University of Dubai 20


Decimal to binary Conversion
To convert decimal numbers to binary numbers
the method is little bit complicated:

Successive substractions of powers of 2 Sussessive Divisions by 2

2510 = 1 1 0 0 12 2510 = 1 1 0 0 1 2
25 0 0
24 11 1 25| 2
- 16 1 | 12 | 2
= 9 23 0|6 |2
- 8
0 |3 |2
= 1 1 |1 |2
20
- 1
1 |0
= 0

Digital Logic Habib Hamam Canadian University of Dubai 21


Exercices
Exercice 1:
Convert the following decimal numbers into
binary equivalents: 127 and 1024.

Exercice 2:
What is the biggest decimal number that can be
represented by a binary number of
8 bits (1 byte)?
16 bits (2 bytes)?

Digital Logic Habib Hamam Canadian University of Dubai 22


Solutions
Exercice 1:

12710 = 111 1111 2 = 27 -1

102410 = 100 0000 0000 2 = 210 (what is the Kb )

Exercice 2:

28 - 1 = 255

216 - 1 = 65 535 = 26 x 210  ( 64 Kb)


Digital Logic Habib Hamam Canadian University of Dubai 23
Octal to decimal conversion
To convert octal numbers into decimal numbers,
we only need to add powers of 8 with non zero
weights

12348 = 1x83 + 2x82 + 3x81 + 4x80


= 512 + 2 x 64 + 3x8 + 4
= 66810

Digital Logic Habib Hamam Canadian University of Dubai 24


Hexadecimal to decimal conversion
To convert hexadecimal numbers into decimal
numbers, we only need to add powers of 16 with
non zero weights (do not forget to replace each
letter by its corresponding number which is
either 10, 11 … or 15)

A12316 = 10x163 + 1x162 + 2x161 + 3x160


= 10x4096 + 1 x 256 + 2x16 + 3
= 4125110

Digital Logic Habib Hamam Canadian University of Dubai 25


Octal to binary conversion
To convert octal numbers into binary numbers,
we only need to convert each digit separately to
its binary form (3bits)
Example: convert 472.318 into binary

4 7 2 . 3 1 (Octal)
100 111 010 . 011 001 (Binaire)

Thus: 472.318 = 100 111 010.011 0012

Digital Logic Habib Hamam Canadian University of Dubai 26


Binary to octal conversion
To convert binary numbers into octal numbers,
we only need to convert each 3 bits separately to
their 0ctal form (1 digit) by starting by the lowest
significant bit

Example: convert 1101110.011012 into octal

Trick: try to have a multiple of 3 bits before and


after the point: 001 101 110 . 011 0102

Digital Logic Habib Hamam Canadian University of Dubai 27


Hexadecimal to binary conversion
In a similar way to octal numbers, to convert
hexadecimal numbers into binary numbers, we
only need to convert each digit separately to its
binary form (4bits)
Example: convert E1A3E916 into binary

E 1 A 3 E 9
1110 0001 1010 0011 1110 1001

Thus: E1A3E916 = 1110 0001 1010 0011 1110 1001 2

Digital Logic Habib Hamam Canadian University of Dubai 28


Binary to hexadecimal conversion
In a similar way, to convert binary numbers into
hexadecimal numbers, we only need to convert
each 4 bits separately to their hexadecimal form
(1 digit) by starting by the lowest significant bit

Example: convert 101101110.0110112 into octal

Trick: try to have a multiple of 4 bits before and


after the point: 0001 0110 1110 . 0110 11002

Digital Logic Habib Hamam Canadian University of Dubai 29


Examples
Table

Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

Example of hex to binary conversion:

9F216 = 9 F 2
1001 1111 0010 = 1001111100102

Digital Logic Habib Hamam Canadian University of Dubai 30


Octal to hexadecimal conversion
For octal/hexadecimal conversion, we can use
the binary basis as an intermediate step:
Example:
Convert E1A3E916 into the octal system

E 1 A 3 E 9

1110 0001 1010 0011 1110 1001

7 0 3 2 1 7 5 1
Digital Logic Habib Hamam Canadian University of Dubai 31
Section 4

Interest of these codes

32
Why hexadecimal coding
Digital circuits and computers use binary
numbers to represent data, memory addresses
and I/O, instructions, state indicators, etc.
The hexadecimal code simplifies the
representation and easily compares binary
numbers.
Conversion is very easy.

Digital Logic Habib Hamam Canadian University of Dubai 33


Example
One microprocessor has a bus (line) of 16 bits
addresses.
Every value on the bus is comprised between
000016 and FFFF16 to select one memory cell of 8
bits (1 byte)
What is the size of the memory that the
microprocessor can address ?
Response:

A memory of 64 Kbytes (216 bytes).

Digital Logic Habib Hamam Canadian University of Dubai 34


Why Bits (Binary Digits)?
As we’ll learn, computers represent all
information using bits.
A bit means a binary (i.e., base 2) digit, 0 or 1.

This is done for several reasons:


Two states (digit values) is all that is really needed.
Any desired information can be represented using sequences of
bits.
Encoding information using 2-state systems offers the best
noise immunity for a given energy/information ratio.
Computers based on bits tend to be the most energy-efficient.

Digital Logic Habib Hamam Canadian University of Dubai 35


Why Bits (Binary Digits)? - continue
This is done for several reasons (continue:
….

A bit conveniently can represent the truth value of any
given proposition in Boolean logic.
That is, “true” (1) or “false” (0).
Bits can be simply and easily manipulated by simple
hardware elements called “logic gates.”
These implementing the basic operators of Boolean logic.

Digital Logic Habib Hamam Canadian University of Dubai 36


Section 5

BCD code

37
BCD
Binary Coded Decimal (BCD) is another way to
present decimal numbers in binary form.
BCD is widely used and combines features of
both decimal and binary systems.
Each digit is converted to a binary equivalent.

Digital Logic Habib Hamam Canadian University of Dubai 38


BCD coding
BCD : Binary Coded Decimal
It is used to facilitate the binary/decimal
conversion, which becomes very heavy for big
numbers
Each decimal digit is represented by its binary
equivalent using 4 bits.
This technique is used in digital instruments
using decimal inputs or outputs such as :
Voltmeters, digital clocks and watches, numerical
calculators, …

Digital Logic Habib Hamam Canadian University of Dubai


Example
Each decimal digit is represented by its binary
equivalent using 4 bits.

4 7 2 (decimal)
0100 0111 0010 (BCD)

Comparison between binary and BCD

13710 = 1000 1001 (binary)

13710 = 0001 0011 0111 (BCD)


Digital Logic Habib Hamam Canadian University of Dubai
Another example
To convert the number 87410 to BCD:

8 74
0100 0111 0100 = 010001110100BCD

Each decimal digit is represented using 4 bits.


Each 4-bit group can never be greater than 9.
Reverse the process to convert BCD to decimal.

Ronald Tocci/Neal Widmer/Gregory Moss


Digital Systems: Principles and Copyright ©2007 by Pearson Education, Inc.
Applications, 10e Columbus, OH 43235
All rights reserved.

Digital Logic Habib Hamam Canadian University of Dubai 41


Remarks
BCD is not a number system.
BCD is a decimal number with each digit
encoded to its binary equivalent.
A BCD number is not the same as a straight
binary number.
The primary advantage of BCD is the relative
ease of converting to and from decimal.

Ronald Tocci/Neal Widmer/Gregory Moss


Digital Systems: Principles and Copyright ©2007 by Pearson Education, Inc.
Applications, 10e Columbus, OH 43235
All rights reserved.

Digital Logic Habib Hamam Canadian University of Dubai 42


Section 6

Gray Code

43
Gray Code
The gray code is used in applications where
numbers change rapidly.
In the gray code, only one bit changes from each
value to the next.

Digital Logic Habib Hamam Canadian University of Dubai 44


2-5 Gray Code
Binary Gray Code
000 000
001 001
010 011
011 010
100 110
101 111
110 101
111 100

Digital Logic Habib Hamam Canadian University of Dubai 45


All Together

Decimal Binary Hexadecimal BCD Gray


0 0 0 0 0
1 1 1 0001 0001
2 10 2 0010 0011
3 11 3 0011 0010
4 100 4 0100 0110
5 101 5 0101 0111
6 110 6 0110 0101
7 111 7 0111 0100
8 1000 8 1000 1100
9 1001 9 1001 1101
10 1010 A 0001 0000 1111
11 1011 B 0001 0001 1110
12 1100 C 0001 0010 1010
13 1101 D 0001 0011 1011
14 1110 E 0001 0100 1001
15 1111 F 0001 0101 1000

Digital Logic Habib Hamam Canadian University of Dubai 46


Section 7

Other codes

47
2-8 Alphanumeric Codes
Represents characters and functions found on a
computer keyboard.
ASCII – American Standard Code for Information
Interchange.
Seven bit code: 27 = 128 possible code groups
Table 2-4 lists the standard ASCII codes
Examples of use are: to transfer information between
computers, between computers and printers, and for
internal storage.

Digital Logic Habib Hamam Canadian University of Dubai 48


Code ASCII
Table
character ASCII Hexadec
0

SOH 1 01 ! 33 21 A 65 41 a 97 61
STX 2 02 " 34 22 B 66 42 b 98 62
ETX 3 03 # 35 23 C 67 43 c 99 63
EOT 4 04 $ 36 24 D 68 44 d 100 64
ENQ 5 05 % 37 25 E 69 45 e 101 65
ACK 6 06 & 38 26 F 70 46 f 102 66
BEL 7 07 ' 39 27 G 71 47
g 103 67
BS 8 08 ( 40 28 H 72 48
TAB 9 09 h 104 68
) 41 29 I 73 49
LF 10 0A i 105 69
* 42 2A J 74 4A
VT 11 0B j 106 6A
+ 43 2B K 75 4B
FF 12 0C , 44 2C L 76 4C
k 107 6B ASCII code extended
CR 13 0D l 108 6C
SO 14 0E
-
.
45
46
2D
2E
M
N
77
78
4D
4E m 109 6D to 8 bits
SI 15 0F / 47 2F O 79 4F n 110 6E
DLE 16 10 0 48 30 P 80 50 o 111 6F
DC1 17 11 1 49 31 Q 81 51 p 112 70
DC2 18 12 2 50 32 R 82 52 q 113 71
DC3 19 13 3 51 33 S 83 53 r 114 72
DC4 20 14 4 52 34 T 84 54 s 115 73
NAK 21 15 5 53 35 U 85 55 t 116 74
SYN 22 16 6 54 36 V 86 56
u 117 75
ETB 23 17 7 55 37 W 87 57
v 118 76
CAN 24 18 8 56 38 X 88 58
w 119 77
EM 25 19 9 57 39 Y 89 59
SUB 26 1A x 120 78
: 58 3A Z 90 5A
ESC 27 1B ; 59 3B [ 91 5B y 121 79
FS 28 1C < 60 3C \ 92 5C z 122 7A
GS 29 1D = 61 3D ] 93 5D { 123 7B
RS 30 1E > 62 3E ^ 94 5E | 124 7C
US 31 1F ? 63 3F _ 95 5F } 125 7D
Espace 32 20 @ 64 40 ` 96 60 ~ 126 7E

Digital Logic Habib Hamam Canadian University of Dubai


Section 8

Error detection

50
Parity Method for Error Detection
Binary data and codes are frequently moved
between locations. For example:
Digitized voice over a microwave link.
Storage and retrieval of data from magnetic and optical
disks.
Communication between computer systems over
telephone lines using a modem.

Electrical noise can cause errors during


transmission.
Many digital systems employ methods for error
detection (and sometimes correction).
Digital Logic Habib Hamam Canadian University of Dubai 51
Transmission of data with error
noise causing an error in the transmission

Signal initial:

Signal received: threshold

Recovered signal
right decision
wrong
Digital Logic Habib Hamam Canadian University of Dubai 52
Parity Method for Error Detection
The parity method of error detection requires the
addition of an extra bit to a code group.
This extra bit is called the parity bit.
The bit can be either a 0 or 1, depending on the
number of 1s in the code group.
There are two methods, even and odd.

Digital Logic Habib Hamam Canadian University of Dubai 53


Even parity
Even parity method – the total number of bits in a
group including the parity bit must add up to an
even number.
The binary group 1 0 1 1 would require the addition of a
parity bit 1 1 0 1 1
Note that the parity bit may be added at either end of a group.

Digital Logic Habib Hamam Canadian University of Dubai 54


Odd parity
Odd parity method – the total number of bits in a
group including the parity bit must add up to an
odd number.
The binary group 1 1 1 1 would require the addition of a
parity bit 1 1 1 1 1

Digital Logic Habib Hamam Canadian University of Dubai 55


Parity Method for Error Detection
The transmitter and receiver must “agree” on the
type of parity checking used.
Two bit errors would not indicate a parity error.
Both odd and even parity methods are used, but
even seems to be used more often.

Digital Logic Habib Hamam Canadian University of Dubai 56


Section 9

Quiz

57
1. Binary base
What is the biggest number that one can obtain
with 5 binary bits

1. 31
2. 32
3. 63
4. 64

Digital Logic Habib Hamam Canadian University of Dubai 58


2. Octal base
What is the biggest number that one can obtain
with 3 octal digits

1. 63
2. 127
3. 255
4. 511

Digital Logic Habib Hamam Canadian University of Dubai 59


3. Hexadecimal base
How can we represent the green color in the
RGB

1. (FF,FF,00)
2. (00,99,00)
3. (00,FF,00)
4. (00,EE,00)
5. (00,00,EE)

Digital Logic Habib Hamam Canadian University of Dubai 60


4. Error detection with even parity
What is the real decimal value sent when we
receive 110011

1. 19
2. 51
3. 10011
4. 110011

Digital Logic Habib Hamam Canadian University of Dubai 61


Reponses
In the order of the slides

1
4
3
1

Digital Logic Habib Hamam Canadian University of Dubai 62

Вам также может понравиться