EEE303-Week01 - Number Systems, Verilog
EEE303-Week01 - Number Systems, Verilog
Introduction
Week 01
Introduction to OBE
• In this course, we are going to follow the approach of Outcome Based Education
(OBE) (Not to be confused with Order of the British Empire)!
• Outcome-based education (OBE) is an educational theory that bases each
part of an educational system around goals (outcomes). By the end of the
educational experience, each student should have achieved the goal.
• Prerequisite for accreditation!
PO2
Problem Analysis: Identify, formulate, research literature, interpret data, and analyze complex electrical and electronic engineering problems
using principles ofmathematical, natural and engineering sciences. (K1 to K4).
Design/development Solution: Design solutions to complex engineering problems and design systems, components, or processes that meet
PO3 the needs relevant to electrical and electronic engineering with appropriate considerations to public health and safety, cultural, societal, and
environmental considerations. (K5).
PO4 Investigation: Conduct investigations of complex problems using research-based knowledge and research methods including design of
experiments, analysis and interpretation of data, and synthesis of information to provide valid conclusions. (K8).
PO5 Modern tool usage: Use techniques, skills, and modern engineering tools to solve complex and practical engineering problems related
to electrical and electronic engineering with understanding of the limitations. (K6).
PO6 The Engineer and Society: Apply reasoning to assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to professional engineering practice and solutions to complex engineering problems. (K7).
Environment and sustainability: Understand and evaluate the sustainability and impact of professional engineering work in the
PO7 solution of
complex engineering problems in societal and environmental contexts. (K7).
PO8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of engineering practice. (K7).
PO9
Individual work and team work: Function effectively as an individual, and as a member or leader in diverse teams and in multi-
disciplinary settings.
Communication: Communicate effectively on complex engineering activities with the electrical and electronic engineering and other inter-
PO10 disciplinary communities and with society at large, such as being able to comprehend and write effective reports and design documentation, make
effective presentations, and give and receive clear instructions.
PO11 Project management and finance: Demonstrate knowledge and understanding of engineering management principles and economic
decision-making and apply these to one's own work, as a member and leader in a team, to manage projects and in multidisciplinary environments.
EEE 303
PO12 Life-long – Digital
Learning Electronics
: Recognize the need for, and ability to engage in life-long learning
Dr. Sajid Muhaimin Choudhury 10
Department of EEE, BUET https://eee.buet.ac.bd/academics/undergraduate/peo-po
5
10
11/23/2022
No obvious solution
Knowledge K3-K6, K8
Level of Interaction
Eng. Specialization
Eng. Fundamentals
Range of resources
Course EEE 416
Many components
Outside problems
Infrequent Issues
Diverse groups
Consequences
Technology
Familiarity
Innovation
Research
Science
Society
Design
Math
🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸
13
2. Continuous Assessment –
• 1 assignment (20) – Mandatory
• 3 Class tests, best 2 counted (20)
3. Final Examination – A comprehensive term final examination will be held at the end of the Term following
the guideline of the Academic Council
Distribution of Marks
Class Attendance – 10%
Continuous Assessment – 20%
Final Examination – 70%
Textbooks
Class/Lecture Schedule
EEE 303 – Digital Electronics Resolution of Academic Council Meeting 474, Date 11.01.2022,
Dr. Sajid Muhaimin Choudhury 20
Department of EEE, BUET Resolution no 220148
10
20
11/23/2022
Distribution of Marks
programs
• PHY 165 Electricity and Magnetism,
CSE / Comp Engg Modern Physics and Mechanics
device drivers • EEE 101 - Electrical Circuits I
• EEE 105 - Electrical Circuits II
instructions
registers • EEE 201 - Electronic Circuits I
EEE 415
datapaths • EEE 203 - Energy Conversion I
controllers
• EEE 207 - Electronic Circuits II
adders
AND gates
•
•
EEE 209 - Engineering Electromagnetics
EEE 303 - Digital Electronics
NOT gates
• EEE 313 Solid State Devices
amplifiers
EEE 101, 105, 207, 315, 465* filters • EEE 315 Power Electronics
transistors • EEE 415 Microprocessors and
EEE 201, 313 diodes
Embedded Systems
PHY 165, 209, 461* electrons • EEE 465* Analog Integrated Circuits
EEE 303 – Digital Electronics • EEE 467* VLSI Circuits and Design
Dr. Sajid Muhaimin Choudhury 27
Department of EEE, BUET
27
Digital Electronics
Why Digital?
Why Analog?
• Reproducibility
• Not affected by noise (better quality)
• Ease of design
• Data protection
• Programmable
• Speed
• Economy
How it is made
Digital System
Discrete
Discrete Information Discrete
Input Processing Output
System
System
States
Takes discrete input, has discrete system
states and gives discrete output
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 37
Department of EEE, BUET
37
Information Representation
• CPU: Voltage
• HDD: Magnetic Field Direction
• CD: Physical shape of pits
• DRAM: Electric Charge
• Optical Fiber: Light intensity
Time
Analog
Digital
Asynchronous
Synchronous
Digital clock
Input: Time set
Output: Current time Digital computer
State: Current time Covered in EEE 416
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 42
Department of EEE, BUET
21
42
11/23/2022
- Ian Stewart
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 46
Department of EEE, BUET
23
46
11/23/2022
7 6 5 1|10
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 47
Department of EEE, BUET
47
Decimal Numbers
• Base 10 (our everyday number system)
1000's column
10's column
1's column
100's column
5374 10 =
Base 10
Decimal Numbers
• Base 10 (our everyday number system)
1000's column
10's column
1's column
100's column
537410 = 5 × 103 + 3 × 102 + 7 × 101 + 4 × 100
five three seven four
thousands hundreds tens ones
Base 10
Number of Fingers
Symbols:
Binary: Bi (two) 01, TF
Each subsequent digit a
multiplier of 2 N/2 Q R
Base: 2 13/2 6 1
6/2 3 0
3/2 1 1
1/2 0 1
13|10 = 1101|2
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 51
Department of EEE, BUET
51
10's column
1's column
100's column
2's column
1's column
4's column
1101 2 =
Base 2
• Base-8 • Base-16
• Octal • Hexadecimal
• Symbols: 01234567 • Symbols:
0123456789ABCDEF
• F|16 = 15|10
1000's column
10's column
1's column
100's column
537410 = 5 × 103 + 3 × 102 + 7 × 101 + 4 × 100
five three seven four
thousands hundreds tens ones
2's column
1's column
4's column
1101 2 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 = 1310
one one no one
eight four two one
Base 2
Powers of Two
• 20 = • 28 =
• 21 = • 29 =
• 22 = • 210 =
• 23 = • 211 =
• 24 = • 212 =
• 25 = • 213 =
• 26 = • 214 =
• 27 = • 215 =
Powers of Two
• 20 = 1 • 28 = 256
• 21 = 2 • 29 = 512
• 22 = 4 • 210 = 1024 Handy to
• 23 = 8 • 211 = 2048 memorize
9
• 24 = 16 • 212 = 4096 up to 2
• 25 = 32 • 213 = 8192
• 26 = 64 • 214 = 16384
• 27 = 128 • 215 = 32768
Number Conversion
• Binary to decimal conversion:
– Convert 100112 to decimal
Number Conversion
• Binary to decimal conversion:
– Convert 100112 to decimal
– 16×1 + 8×0 + 4×0 + 2×1 + 1×1 = 1910
Number Conversion
• Binary to decimal conversion:
– Convert 111012 to decimal
– 16×1 + 8×1 + 4×1 + 2×0 + 1×1 = 2910
Binary Numbers
𝐴: {𝑎 ,𝑎 ,…𝑎 ,𝑎 }
𝐴= 𝑎2
Example:
11012 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20
=8 + 4 + 0 + 1
= 13
Hexadecimal Numbers
Hex Digit Decimal Equivalent Binary Equivalent
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
A 10
B 11
C 12
D 13
E 14
F 15
Hexadecimal Numbers
Hex Decimal Equivalent Binary Equivalent
Digit
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
A 10 1010
B 11 1011
C 12 1100
D 13 1101
E 14 1110
F 15 1111
Hexadecimal Numbers
• Base 16
• Shorthand for binary
Hexadecimal to Binary
Conversion
• Hexadecimal to binary conversion:
– Convert 4AF16 (also written 0x4AF) to
binary
Hexadecimal to Binary
Conversion
• Hexadecimal to binary conversion:
– Convert 4AF16 (also written 0x4AF) to
binary
– 0100 1010 11112
byte
• Bytes
– MSB: most significant byte
– LSB: least significant byte
byte
• Bytes
– MSB: most significant byte CEBF9AD7
– LSB: least significant byte most least
– Each hex digit represents significant significant
byte byte
a nibble (4 bits)
230|10
Octal Hexadecimal
N/8 Q R N/16 Q R
230/8 28 3 230/16 14 3
28/8 3 1 14/16 0 14(E)
3/8 0 3
230|8 1F4|16
Octal Hexadecimal
0 ✕ 80 = 0 4 ✕ 160 = 4
3 ✕ 81 = 24 15 ✕ 161 = 240
2 ✕ 82 = 128 1 ✕ 162 = 256
152 500
001101010|2
Addition
• Decimal
3734
+ 5168
• Binary
1011
+ 0011
Addition
• Decimal
11 carries
3734
+ 5168
8902
• Binary 11 carries
1011
+ 0011
1110
numbers
1001
+ 0101
Overflow
• Digital systems operate on a fixed number of bits
• Overflow: when the result is too big to fit in the available
number of bits
• See previous example of 11 + 6
111
1011
+ 0110
10001
Overflow!
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 93
Department of EEE, BUET
93
Signed number
• A signed binary number consists of both sign and
magnitude information.
• Three formats:
• sign-magnitude
• 1’s complement
• 2’s complement.
Sign/Magnitude Numbers
• 1 sign bit, N-1 magnitude bits
• Sign bit is the most significant (left-most) bit
– Positive number: sign bit = 0
– Negative number: sign bit = 1
Sign/Magnitude Numbers
• 1 sign bit, N-1 magnitude bits
• Sign bit is the most significant (left-most) bit
– Positive number: sign bit = 0
– Negative number: sign bit = 1
Sign/Magnitude Numbers
• 1 sign bit, N-1 magnitude bits
• Sign bit is the most significant (left-most) bit
– Positive number: sign bit = 0 𝑨: {𝒂𝑵 𝟏 , 𝒂𝑵 𝟐 , … 𝒂𝟏 , 𝒂 𝟎 )
𝑨= (−𝟏)𝒂𝑵 𝟏 𝒂 𝒊 𝟐𝒊
𝒊 𝟎
𝐴= 𝑎2
Example:
11012 = 1 × 23 + 1 × 22 + 0 × 21 + 1
× 20
=8 + 4 + 0 + 1
= 13
Sign/Magnitude Numbers
𝐴: {𝑎 ,𝑎 ,…𝑎 ,𝑎 }
𝐴 = (−1) 𝑎2
Example:
11012 = (-1)1 × (1 × 22 + 0 × 21 + 1 × 20)
= -1 × (4 + 0 + 1)
= -5
Sign/Magnitude Numbers
Problems:
• Addition doesn’t work, for example -6 + 6:
1110
+ 0110
10100 (wrong!)
Value = -8 + 2 + 1 = -5
(We’ll show another way to find this value in a moment.)
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 103
Department of EEE, BUET
103
𝐴= 𝑎2
Example:
11012 = 1 × 23 + 1 × 22 + 0 × 21 + 1
× 20
=8 + 4 + 0 + 1
= 13
𝐴=𝑎 −2 + 𝑎2
Example:
11012 = 1 × (-23) + [ 1 × 22 + 0 × 21 + 1 × 20 ]
= -8 + [4 + 0 + 1]
= -3
0110
+ 1010
1110
+ 0011
Sign-Extension
• Sign bit copied to msb’s
• Number value is same
• Example 1:
– 4-bit representation of 3 = 0011
– 8-bit sign-extended value: 00000011
• Example 2:
– 4-bit representation of -5 = 1011
– 8-bit sign-extended value: 11111011
Zero-Extension
• Zeros copied to msb’s
• Value changes for negative numbers
• Example 1:
– 4-bit value = 0011 = 310
– 8-bit zero-extended value: 00000011 = 310
• Example 2:
– 4-bit value = 1011 = -510
– 8-bit zero-extended value: 00001011 = 1110
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Unsigned 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111 Two's Complement
0000
1111 1110 1101 1100 1011 1010 1001 0001 0010 0011 0100 0101 0110 0111 Sign/Magnitude
1000
Overview
A Hardware Description Language (HDL) is a language used to describe a
digital system, for example, a computer or a component of a computer.
A digital system can be described at several levels:
Switch level: wires, resistors and transistors
Gate level: logical gates and flip flops
Register Transfer Level (RTL): registers and the transfers of information
between registers.
125
Verilog
Was introduced in 1985 by Gateway Design System Corporation, now a part of
Cadence Design Systems, Inc.'s Systems Division.
Was made an IEEE Standard in 1995
Syntax based on C programming language.
Design examples using Verilog HDL
◦ Intel Pentium, AMD K5, K6, Atheon, ARM7, etc
◦ Thousands of ASIC designs using Verilog HDL
127
Design Methodology
129
Numbers
Numbers are specified using the following form
<size><base format><number>
Examples:
◦ x = 347 // decimal number
◦ x = 4'b101 // 4- bit binary number 0101
◦ x = 16'h87f7 // 16-bit hex number h87f7
◦ x = 2'b101010
◦ x = 2'd83
operators
Bitwise Operators
~ NOT
& AND
| OR
^ XOR
~| NOR
~& NAND
^~ or ~^ XNOR
Logical & Relational Operators
!, &&, | |, ==, !=, >=, <=, >, <
131
Ports
There are three different port types: U1
• Input A(7:0) A(7:0) B(7:0) B(7:0)
• Output
• Inout C C
Port definition:
• <port type> <portwidth> <port name> my_module
• Example:
Note: Fub1
• reg should only be used with always and initial blocks (to be presented …)
• The reg variables store the last value that was procedurally assigned to them whereas
the wire variables represent physical connections between structural entities such as
gates.
133
Continuous Assignment
Continuous statement is used to model combinational logic.
A continuous assignment statement is declared as follows:
assign <net_name> = variable;
assign corresponds to a connection.
Target is never a reg variable.
Examples:
Continuous Assignment
Verilog code for a 4 bit adder:
135
Procedural Assignment
Used for modeling sequential circuits.
A procedural assignment statement is declared as follows:
Always @(event list) begin
<reg_name> <= variable;
end
The assignment will be performed whenever one of the events in “event_list”
occurs.
Procedural Assignment
Example: D-FF
D Out
clk
137
Interconnecting Modules
In order to use a module, it should be
instantiated:
<Module_name> <Instant_name> (<port mapping>)
mux2
Primitives
No declaration required (predefined)
Can only be instantiated
Example: and a1 (C, A, B); //instance name
• Usually better to provide instance name for debugging.
Example: or o1 (SET, ~A, C ),
o2(N, ABC,SET );
Example: and #(10) a2(o, i1, i2); // name + delay
139
1
4
0
Test Bench
Test bench
EEE 303 – Digital Electronics VERILOG OVERVIEW Dr. Sajid Muhaimin Choudhury 140
Department
12/20/2015 of EEE, BUET
70
140
11/23/2022
Verilog Code - 1
input [3:0] d;
output [3:0] q;
wire [3:0] d;
assign q = ~d + 4'b0001;
endmodule
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 143
Department of EEE, BUET
143
Verilog Code - 1
input [3:0] d;
output [3:0] q;
wire [3:0] d;
assign q = ~d + 4'b0001;
endmodule
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 144
Department of EEE, BUET
72
144
11/23/2022
Verilog Code - 1
input [3:0] d;
output [3:0] q;
wire [3:0] d;
assign q = ~d + 4'b0001;
endmodule
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 145
Department of EEE, BUET
145
Verilog Code - 1
input [3:0] d;
output [3:0] q;
wire [3:0] d;
assign q = ~d + 4'b0001;
endmodule
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 146
Department of EEE, BUET
73
146
11/23/2022
Verilog Code - 1
input [3:0] d;
output [3:0] q;
wire [3:0] d;
assign q = ~d + 4'b0001;
endmodule
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 147
Department of EEE, BUET
147
Verilog Code - 1
input [3:0] d;
output [3:0] q;
No storage – continuously pass value
wire [3:0] d;
assign q = ~d + 4'b0001;
endmodule
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 148
Department of EEE, BUET
74
148
11/23/2022
Verilog Code - 1
input [3:0] d;
output [3:0] q;
wire [3:0] d;
assign q = ~d + 4'b0001;
Complement Add 1
endmodule
EEE 303 – Digital Electronics Dr. Sajid Muhaimin Choudhury 149
Department of EEE, BUET
149
Intel Quartus
Tools
11/23/2022
144
j jnn jnhjnv00f
Simulation result is shown. The code converts
input into 2’s complement
Icarus Verilog
Icarus Verilog
EDA Playground
Icarus Verilog
Output
87