Designing Combinational Logic Circuits in Verilog - 2

Slides:



Advertisements
Similar presentations
Counters Discussion D8.3.
Advertisements

CDA 3100 Recitation Week 11.
CDA 3100 Recitation Week 10.
Logic Circuits Design presented by Amr Al-Awamry
Supplement on Verilog adder examples
Multiplication and Division
Table 7.1 Verilog Operators.
Figure 4.1. The function f (x1, x2, x3) =  m(0, 2, 4, 5, 6).
Company LOGO Edit your slogan here DKT 122/3 DIGITAL SYSTEM 1 WEEK #3 NUMBER SYSTEMS, OPERATION & CODES (PART 2)
Gray Code Converters Discussion D9.1 Example 16.
Binary-to-BCD Converter Lecture L6.2 Section 6.5 pp
Arithmetic Operations and Circuits
Codes and Code Converters
Code Converters Module M7.1 Section 6.5. Code Converters Binary-to-BCD Converters ABEL TRUTH_TABLE Command.
Arbitrary Waveform Discussion 12.2 Example 34. Recall Divide-by-8 Counter Use q2, q1, q0 as inputs to a combinational circuit to produce an arbitrary.
2-to-1 Multiplexer: if Statement Discussion D7.1 Example 4.
DIGITAL SYSTEMS TCE OTHER COMBINATIONAL LOGIC CIRCUITS WEEK 7 AND WEEK 8 (LECTURE 1 OF 3) COMPARATORS CODE CONVERTERS.
Logic Design Fundamentals - 2 Lecture L1.2. Logic Design Fundamentals - 2 Basic Gates Basic Combinational Circuits Basic Sequential Circuits.
ECE 331 – Digital System Design Logic Circuit Design (Lecture #7)
COE 202: Digital Logic Design Combinational Circuits Part 4
Binary-to-BCD Converter
Binary-to-BCD Converter
Quad 2-to-1 Multiplexer Discussion D7.4 Example 7.
Sequential Circuit Introduction to Counter
VHDL Examples Subra Ganesan Reference: Professor Haskell’s Notes,
ASCII & Gray Codes.
Engineering 100 Section 250 Combinational Logic -- Examples 9/13/2010.
Revision Introductory Lesson
Encoder Section Outline Review: Sum of Products Encoder Priority Decoder Application of Priority Decoder.
Advanced Instructions Most PLCs now support more advanced functions such as Floating point math, Boolean operations, Shifting, Sequencing, Program control.
Numbering systems.
Verilog Intro: Part 2. Procedural Blocks There are two types of procedural blocks in Verilog. – initial for single-pass behavior: initial blocks execute.
CS 151: Digital Design Chapter 3 3-8: Encoding. CS 151 Encoding Encoding - the opposite of decoding - the conversion of a maximum of 2 n input code to.
Circuit, State Diagram, State Table
CPSC 171 Introduction to Computer Science Boolean Logic, Gates, & Circuits.
Digital Electronics.
COE 202: Digital Logic Design Combinational Circuits Part 3 Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office: Ahmad Almulhem, KFUPM.
ECE 2372 Modern Digital System Design
Binary-to-BCD Converter
A little bit of exercise.. ;). Exercise Given to you are some binary to decimal examples : Given to you are some binary to decimal examples : Tens Units.
Registers CPE 49 RMUTI KOTAT.
Figure 5.1. Conversion from decimal to binary.. Table 5.1. Numbers in different systems.
Figure 5.1. Conversion from decimal to binary.. Table 5.1. Numbers in different systems.
1 Adders & Subtractors Adders –An adder is a combinational logic circuit that performs the addition of 2 binary numbers (A & B) to generate the sum (S)
1 Lecture 3 ENGRE 254 1/14/09. 2 Lecture 1 review Digital signals assume two values represented by “0” and “1”. Typically a “0” represents a voltage near.
CS151 Introduction to Digital Design
Digital Systems Digital Logic and Design Dr. Musab Bassam Zghool Text Book: Mano Morris M. “ Digital Logic And Computer Design ”
EKT 124 / 3 DIGITAL ELEKTRONIC 1
Digital Electronics.
Unit - 3 NUMBER SYSTEM AND CODES
Number Representation and Arithmetic Circuits
Multiplexers Section Topics Multiplexers – Definition – Examples – Verilog Modeling.
ECE 301 – Digital Electronics Logic Circuit Design (Lecture #9)
ECE/CS 352 Digital System Fundamentals© T. Kaminski & C. Kime 1 ECE/CS 352 Digital Systems Fundamentals Fall 2000 Chapter 5 – Part 2 Tom Kaminski & Charles.
SYEN 3330 Digital SystemsJung H. Kim 1 SYEN 3330 Digital Systems Chapter 7 – Part 2.
ECE 2110: Introduction to Digital Systems
ECE DIGITAL LOGIC LECTURE 2: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/14/2016.
Instructor: Alexander Stoytchev CprE 281: Digital Logic.
Decoders A decoder is a logic circuit that detects the presence of a specific combination of bits at its input. Two simple decoders that detect the presence.
Instructor: Alexander Stoytchev CprE 281: Digital Logic.
Instructor: Alexander Stoytchev CprE 281: Digital Logic.
Sequential Circuit: Counter
Chapter 4 Combinational Logic
Logic Design Review – 2 Basic Combinational Circuits
Digital Systems: Number Systems and Codes
Instructor: Alexander Stoytchev
Analog-to-Digital Converters
Binary-to-BCD Converter
Instructor: Alexander Stoytchev
Instructor: Alexander Stoytchev
Presentation transcript:

Designing Combinational Logic Circuits in Verilog - 2 Discussion 7.3

Designing Combinational Logic Circuits in Verilog - 2 Binary to Gray code converter Gray code to binary converter Binary-to-BCD converter

Gray Code Definition: An ordering of 2n binary numbers such that only one bit changes from one entry to the next. Binary coding {0...7}: {000, 001, 010, 011, 100, 101, 110, 111} Gray coding {0...7}: {000, 001, 011, 010, 110, 111, 101, 100} Not unique One method for generating a Gray code sequence: Start with all bits zero and successively flip the right-most bit that produces a new string.

Binary - Gray Code Conversions Gray code: G[i], i = n – 1 : 0 Binary code: B[i], i = n – 1 : 0 Binary coding {0...7}: {000, 001, 010, 011, 100, 101, 110, 111} Gray coding {0...7}: {000, 001, 011, 010, 110, 111, 101, 100} Convert Binary to Gray: Copy the most significant bit. For each smaller i G[i] = B[i+1] ^ B[i] Convert Gray to Binary: Copy the most significant bit. For each smaller i B[i] = B[i+1] ^ G[i]

Gray Code Binary B[2:0] Gray Code G[2:0] Note that the least significant bit that can be changed without repeating a value is the bit that is changed 000 000 001 001 010 011 011 010 100 110 101 111 110 101 111 100 Binary to Gray code G[2] = B[2]; G[1:0] = B[2:1] ^ B[1:0];

Binary to Gray code grayCode = binary ^ (binary >> 1) G(msb) = B(msb); for(j = msb-1; j >= 0; j=j-1) G(j) = B(j+1) ^ B(j); msb = 5 for 6-bit codes

bin2gray.v module bin2gray ( B ,G ); input [3:0] B ; wire [3:0] B ; output [3:0] G ; wire [3:0] G ; assign G[3] = B[3]; assign G[2:0] = B[3:1] ^ B[2:0]; endmodule Convert Binary to Gray: Copy the most significant bit. For each smaller i G[i] = B[i+1] ^ B[i]

Binary to Gray Code Conversion

Designing Combinational Logic Circuits in Verilog - 2 Binary to Gray code converter Gray code to binary converter Binary-to-BCD converter

Binary - Gray Code Conversions Gray code: G[i], i = n – 1 : 0 Binary code: B[i], i = n – 1 : 0 Binary coding {0...7}: {000, 001, 010, 011, 100, 101, 110, 111} Gray coding {0...7}: {000, 001, 011, 010, 110, 111, 101, 100} Convert Binary to Gray: Copy the most significant bit. For each smaller i G[i] = B[i+1] ^ B[i] Convert Gray to Binary: Copy the most significant bit. For each smaller i B[i] = B[i+1] ^ G[i]

Gray Code Binary B[2:0] Gray Code G[2:0] 000 000 001 001 010 011 011 010 100 110 101 111 110 101 111 100 Gray code to Binary B[2] = G[2]; B[1:0] = B[2:1] ^ G[1:0];

Gray code to Binary B(msb) = G(msb); for(j = msb-1; j >= 0; j--) B(j) = B(j+1) ^ G(j);

Gray code to Binary module gray2bin6 ( G ,B ); input [5:0] G ; wire [5:0] G ; output [5:0] B ; wire [5:0] B ; assign B[5] = G[5]; assign B[4:0] = B[5:1] ^ G[4:0]; endmodule B(msb) = G(msb); for(j = msb-1; j >= 0; j=j-1) B(j) = B(j+1) ^ G(j);

gray2bin.v module gray2bin ( G ,B ); input [3:0] G ; wire [3:0] G ; output [3:0] B ; reg [3:0] B ; integer i; always @(G) begin B[3] = G[3]; for(i=2; i >= 0; i = i-1) B[i] = B[i+1] ^ G[i]; end endmodule Convert Gray to Binary: Copy the most significant bit. For each smaller i B[i] = B[i+1] ^ G[i]

Gray Code to Binary Conversion

Designing Combinational Logic Circuits in Verilog - 2 Binary to Gray code converter Gray code to binary converter Binary-to-BCD converter

Shift and Add-3 Algorithm   S1. Shift the binary number left one bit. 22. If 8 shifts have taken place, the BCD number is in the Hundreds, Tens, and Units column. 33. If the binary value in any of the BCD columns is 5 or greater, add 3 to that value in that BCD column. 44. Go to 1.

Steps to convert an 8-bit binary number to BCD

Truth table for Add-3 Module A3 A2 A1 A0 C S3 S2 S1 S0

K-Map for S3 A1 A0 00 01 11 10 A3 A2 00 01 1 1 1 11 X X X X 10 1 1 X X S3 = A3 | A2 & A0 | A2 & A1

Binary-to-BCD Converter RTL Solution

1. Clear all bits of z to zero 2. Shift B left 3 bits z[8:3] = B[5:0]; Steps to convert a 6-bit binary number to BCD 1. Clear all bits of z to zero 2. Shift B left 3 bits z[8:3] = B[5:0]; 3. Do 3 times if Units >4 then add 3 to Units (note: Units = z[9:6]) Shift z left 1 bit 4. Tens = P[6:4] = z[12:10] Units = P[3:0] = z[9:6]

binbcd6.v module binbcd6(B,P); input [5:0] B; output [6:0] P; reg [6:0] P; reg [12:0] z; integer i; always @(B) begin for(i = 0; i <= 12; i = i+1) z[i] = 0; z[8:3] = B; for(i = 0; i <= 2; i = i+1) if(z[9:6] > 4) z[9:6] = z[9:6] + 3; z[12:1] = z[11:0]; end P = z[12:6]; endmodule

binbcd6.v

binbcd8.v module binbcd8(B,P); input [7:0] B; output [9:0] P; reg [9:0] P; reg [17:0] z; integer i; always @(B) begin for(i = 0; i <= 17; i = i+1) z[i] = 0; z[10:3] = B; for(i = 1; i <= 5; i = i+1) if(z[11:8] > 4) z[11:8] = z[11:8] + 3; if(z[15:12] > 4) z[15:12] = z[15:12] + 3; z[17:1] = z[16:0]; end P = z[17:8]; endmodule binbcd8.v

binbcd8.v

binbcd9.v module binbcd9(B,P); input [8:0] B; output [10:0] P; reg [10:0] P; reg [19:0] z; integer i; always @(B) begin for(i = 0; i <= 19; i = i+1) z[i] = 0; z[11:3] = B; for(i = 0; i <= 5; i = i+1) if(z[12:9] > 4) z[12:9] = z[12:9] + 3; if(z[16:13] > 4) z[16:13] = z[16:13] + 3; z[19:1] = z[18:0]; end P = z[19:9]; endmodule binbcd9.v

binbcd9.v

16-bit Binary-to-BCD Converter

binbcd16.v module binbcd16(B,P); input [15:0] B; output [18:0] P; reg [18:0] P; reg [31:0] z; integer i;

always @(B) begin for(i = 0; i <= 31; i = i+1) z[i] = 0; z[18:3] = B; for(i = 0; i <= 12; i = i+1) if(z[19:16] > 4) z[19:16] = z[19:16] + 3; if(z[23:20] > 4) z[23:20] = z[23:20] + 3; if(z[27:24] > 4) z[27:24] = z[27:24] + 3; if(z[31:28] > 4) z[31:28] = z[31:28] + 3; z[31:1] = z[30:0]; end P = z[31:16]; endmodule

binbcd16.v