Verilog Descriptions of Digital Systems. Electronic Lock // // Electronic combinational lock // module lock(seg7,key, valid_key, col, row, mclk, resetL)

Slides:



Advertisements
Similar presentations
//HDL Example 8-2 // //RTL description of design example (Fig.8-9) module Example_RTL (S,CLK,Clr,E,F,A);
Advertisements

Counters Discussion D8.3.
Traffic light contoller using FSM
Sequential logic examples
Verilog in transistor level using Microwind
CDA 3100 Recitation Week 11.
Verilog.
Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Synchronous Sequential Logic
Combinational Logic.
Verilog Modules for Common Digital Functions
Table 7.1 Verilog Operators.
Verilog. 2 Behavioral Description initial:  is executed once at the beginning. always:  is repeated until the end of simulation.
FSM Revisit Synchronous sequential circuit can be drawn like below  These are called FSMs  Super-important in digital circuit design FSM is composed.
//HDL Example 6-1 // //Behavioral description of //Universal shift register // Fig. 6-7 and Table 6-3 module shftreg.
FSM examples.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 4 - Sequential Design.
Pulse-Width Modulated DAC
Conditional Statements  if and else if statements if (expression) if (expression) statements statements { else if (expression) { else if (expression)
Ring Counter Discussion 11.3 Example 32.
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.
Counters Discussion 12.1 Example 33. Counters 3-Bit, Divide-by-8 Counter 3-Bit Behavioral Counter in Verilog Modulo-5 Counter An N-Bit Counter.
2-to-1 Multiplexer: if Statement Discussion D7.1 Example 4.
ELEN 468 Advanced Logic Design
7-Segment Display DIO1 Board Verilog.
Sequential Logic in Verilog
1 Verilog Digital System Design Z. Navabi, 2006 Digital Design Flow  Digital Design Flow begins with specification of the design at various levels of.
Chapter 4: Behavioral Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 4-1 Ders – 4: Davranışsal Modelleme.
ECE 551 Digital System Design & Synthesis Fall 2011 Midterm Exam Overview.
ECE 551 Digital Design And Synthesis
8279 KEYBOARD AND DISPLAY INTERFACING
Slide 1 6. VHDL/Verilog Behavioral Description. Slide 2 Verilog for Synthesis: Behavioral description Instead of instantiating components, describe them.
ECE/CS 352 Digital System Fundamentals© 2001 C. Kime 1 ECE/CS 352 Digital Systems Fundamentals Spring 2001 Chapters 3 and 4: Verilog – Part 2 Charles R.
Traffic Lights Discussion D8.3a. Recall Divide-by-8 Counter Use Q2, Q1, Q0 as inputs to a combinational circuit to produce an arbitrary waveform. s0 0.
Final Project. System Overview Description of Inputs reset: When LOW, a power on reset is performed. mode: When LOW, NORMal mode selected When HIGH,
Finite State Machine (FSM) Nattha Jindapetch December 2008.
M.Mohajjel. Structured Procedures Two basic structured procedure statements always initial All behavioral statements appear only inside these blocks Each.
8279 KEYBOARD AND DISPLAY INTERFACING
1 Arithmetic, ALUs Lecture 9 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Digital Electronics.
 A test bench is an HDL program used for applying stimulus to an HDL design in order to test it and observe its response during simulation.  In addition.
Chapter 8: Combinational Logic Modules Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 8-1 Chapter 8: Combinational.
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part4: Verilog – Part 2.
Lab5-1 張明峰 交大資工系 Lab 5: FSM and BCD counters Implement the vending machine of lab 2 A two-digit BCD counter –two BCD counters –can load data in parallel.
1 (c) W. J. Dally Digital Design: A Systems Approach Lecture 7: Data Path State Machines.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
EMT 351/4 DIGITAL IC DESIGN Verilog Behavioral Modeling  Finite State Machine -Moore & Mealy Machine -State Encoding Techniques.
Pusat Pengajian Kejuruteraan Mikroelektronik EMT 351/4 DIGITAL IC DESIGN Verilog Behavioural Modeling (Part 4) Week #
Lecture 5. Verilog HDL #3 Prof. Taeweon Suh Computer Science & Engineering Korea University COSE221, COMP211 Logic Design.
Figure Implementation of an FSM in a CPLD..
Overview Logistics Last lecture Today HW5 due today
Supplement on Verilog for Algorithm State Machine Chart
Verilog Modules for Common Digital Functions
Lecture L5.1 Mealy and Moore Machines
Supplement on Verilog Sequential circuit examples: FSM
Sequential logic examples
Digital Logic Design Digital Design, M. Morris Mano and Michael D
FSM MODELING MOORE FSM MELAY FSM. Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-2]
Supplement on Verilog Sequential circuit examples: FSM
Dr. Tassadaq Hussain Introduction to Verilog – Part-3 Expressing Sequential Circuits and FSM.
The Verilog Hardware Description Language
Supplement on Verilog combinational circuit examples
332:437 Lecture 9 Verilog Example
332:437 Lecture 9 Verilog Example
Dr. Tassadaq Hussain Introduction to Verilog – Part-4 Expressing FSM in Verilog (contd) and FSM State Encoding Dr. Tassadaq Hussain.
Verilog Synthesis & FSMs
332:437 Lecture 9 Verilog Example
Lecture 7: Verilog Part II
Presentation transcript:

Verilog Descriptions of Digital Systems

Electronic Lock // // Electronic combinational lock // module lock(seg7,key, valid_key, col, row, mclk, resetL) ; output [0:6] seg7; output [0:3] col ; output [3:0] key ; output valid_key ; input resetL,mclk ; input [0:3] row ; wire clk ; // Divide master clock down to 100 Hz // clock_divider u0(clk, mclk, resetL) ; assign clk = mclk ; // Keyboard scan // When valid_key goes active, the key register contains last key entered kb_scan u1(key, valid_key, col, row, clk, resetL) ; // Has someone entered a valid combination? // User interface is a seven segment display validate u2(seg7, key, valid_key, clk, resetL) ; endmodule

Keyboard Scanner Module

Kb_scan // // Module to scan matrix keyboard // FSM to scan the keyboard // module kb_scan(key, valid_key, col, row, clk, resetL) ; output [3:0] key ; output valid_key ; output [0:3] col ; input [0:3] row ; input clk, resetL ; reg [0:3] row_reg; reg [2:0] nstate, pstate ; reg valid, valid_key ; reg [3:0] key, key_code ; reg [0:3] col ; wire kd ; parameter st_0 = 3'd0, st_1 = 3'd1, st_2 = 3'd2, st_3 = 3'd3, st_4 = 3'd4, st_5 = 3'd5, st_6 = 3'd6 ; // synchronize row info with the clock clk or negedge resetL) begin if (~resetL) row_reg <= 4'b0000 ; else row_reg <= row ; end

Kb_scan (Continued) // if any key is down, the kd signal will be high assign kd = | row_reg ; // state register process for FSM clk or negedge resetL) begin if (~resetL) pstate <= st_0 ; else pstate <= nstate ; end // state transition and output process or pstate) begin valid = 0 ; col = 4'b1111 ; case (pstate) st_0: if (~kd) nstate = st_0 ; else begin nstate = st_1 ; col = 4'b1000 ; end st_1: if (~kd) begin nstate = st_2 ; col = 4'b0100 ; end else begin nstate = st_5 ; col = 4'b1000 ; valid = 1 ; end

Kb_scan (Continued, more) st_2: if (~kd) begin nstate = st_3 ; col = 4'b0010 ; end else begin nstate = st_5 ; col = 4'b0100 ; valid = 1 ; end st_3: if (~kd) begin nstate = st_4 ; col = 4'b0001 ; end else begin nstate = st_5 ; col = 4'b0010 ; valid = 1 ; end st_4: if (~kd) nstate = st_0 ; else begin nstate = st_5 ; col = 4'b0001 ; valid = 1 ; end st_5: if (kd) nstate = st_5 ; else nstate = st_0 ; default: nstate = st_0 ; endcase end

Kb_scan (Continued, even more) // Encode key using row and col info or col) begin casex ({row_reg, col}) 8'b1xxx_1000 : key_code = 4'b0001 ; 8'b1xxx_0100 : key_code = 4'b0010 ; 8'b1xxx_0010 : key_code = 4'b0011 ; 8'b1xxx_0001 : key_code = 4'b1010 ; 8'b01xx_1000 : key_code = 4'b0100 ; 8'b01xx_0100 : key_code = 4'b0101 ; 8'b01xx_0010 : key_code = 4'b0110 ; 8'b01xx_0001 : key_code = 4'b1011 ; 8'b001x_1000 : key_code = 4'b0111 ; 8'b001x_0100 : key_code = 4'b1000 ; 8'b001x_0010 : key_code = 4'b1001 ; 8'b001x_0001 : key_code = 4'b1100 ; 8'b0001_1000 : key_code = 4'b1110 ; 8'b0001_0100 : key_code = 4'b0000 ; 8'b0001_0010 : key_code = 4'b1111 ; 8'b0001_0001 : key_code = 4'b1101 ; default: key_code = 4'd0 ; endcase end // Register the key_code clk or negedge resetL) begin if (~resetL) key <= 4'b0000; else if (valid) key <= key_code ; end // Delay valid_key signal clk or negedge resetL) begin if (~resetL) valid_key <= 0 ; else valid_key <= valid ; end

Validate Module

Validate // // Module to validate entry code being entered // module validate(seg7, key, valid_key, clk, resetL) ; output [0:6] seg7 ; input valid_key, resetL, clk ; input [3:0] key ; wire pound_sign, Z, AeqB, EQ ; reg eqQ ; reg [1:0] pstate, nstate ; reg [0:6] seg7 ; reg [1:0] digit_sel ; reg [2:0] cnt ; reg [3:0] B ; reg [0:6] display_reg_inp ; // control signals for data path reg init, dec_cnt, ld_eq, ld_display ; reg [1:0] display_sel ; // some useful constants parameter st_0 = 2'b00, st_1 = 2'b01, st_2 = 2'b10, st_3 = 2'b11 ;

Validate (Continued) parameter two = 4'b0010, zero = 4'b0000, eight = 4'b1000, one = 4'b0001 ; parameter blank = 7'b , open = 7'b , error = 7'b ; // generate pound_sign present signal assign pound_sign = (key == 4'b1111) ; // mux stored digits in combination to be checked begin case (digit_sel) 2'b00 : B = one ; 2'b01 : B = eight ; 2'b10 : B = zero ; 2'b11 : B = two ; endcase end // Magnitude comparator assign AeqB = (key == B) ;

Validate (Continued, more) // Equality checker assign EQ = AeqB & eqQ ; clk or negedge resetL) begin if (~resetL) eqQ <= 1 ; else if (init) eqQ <= 1 ; else if (ld_eq) eqQ <= EQ ; end // seven segment display MUX and register begin case (display_sel) 2'b00 : display_reg_inp = blank ; 2'b01 : display_reg_inp = open ; 2'b10 : display_reg_inp = error ; default: display_reg_inp = blank ; endcase end clk or negedge resetL) begin if (~resetL) seg7 <= blank ; else if (ld_display) seg7 <= display_reg_inp ; end // 3-bit counter and terminal count output resetL or posedge clk) begin if (~resetL) cnt <= 4 ; else if (dec_cnt) cnt <= cnt - 1 ; else if (init) cnt <= 4 ; end assign Z = (cnt == 3'b000) ;

Validate (Continued, even more) // Create digit select from cnt output begin case (cnt) 4 : digit_sel = 2'b00 ; 3 : digit_sel = 2'b01 ; 2 : digit_sel = 2'b10 ; 1 : digit_sel = 2'b11 ; default: digit_sel = 2'b00 ; endcase end // state register process for FSM clk or negedge resetL) begin if (~resetL) pstate <= st_0 ; else pstate <= nstate ; end // state transition process for FSM or valid_key) begin init = 0 ; ld_eq = 0 ; dec_cnt = 0 ; ld_display = 0 ; display_sel = 0 ; case (pstate) st_0 : begin nstate = st_1 ; ld_display = 1 ; init = 1 ; end

Validate (Continued, one more) st_1 : begin if (Z) begin nstate = st_3 ; ld_display = 1 ; if (eqQ) display_sel = 1 ; else display_sel = 2 ; end else begin if (valid_key) begin ld_eq = 1 ; nstate = st_2 ; end else nstate = st_1 ; end st_2 : begin nstate = st_1 ; dec_cnt = 1 ; end st_3 : if (pound_sign) nstate = st_0 ; else nstate = st_3 ; default: nstate = st_0 ; endcase end endmodule

Lock Testbench // // Testbench for electronic combinational lock // `timescale 1 ms / 1 us module lock_tb ; wire [0:6] seg7 ; wire [0:3] col ; wire [3:0] key ; reg [0:3] row ; reg mclk ; reg resetL ; // Instantiate the lock lock uut(seg7, key, valid_key, col, row, mclk, resetL) ; // Clock generator // Clock period is 10 msec initial begin mclk = 1 ; forever #10 mclk = ~mclk ; end

Lock Testbench (Continued) // Apply test vectors initial begin #0 begin resetL = 0 ; row = 4'b0000 ; end #10 resetL = 1 ; // key stroke is (row #, col #) // 1st key stroke (1,1) = "1" #200 wait(col == 4'b1111) row = 4'b1000 ; wait(col == 4'b1000) row = 4'b1000 ; #200 row = 4'b0000 ; // 2nd key stroke (3,2) = "8" #200 wait(col == 4'b1111) row = 4'b0010 ; wait(col == 4'b1000) row = 4'b0000 ; wait(col == 4'b0100) row = 4'b0010 ; #200 row = 4'b0000 ;

Lock Testbench (Continued, more) // 3rd key stroke (4,2) = "0" #200 wait(col == 4'b1111) row = 4'b0001 ; wait(col == 4'b1000) row = 4'b0000 ; wait(col == 4'b0100) row = 4'b0001 ; #200 row = 4'b0000 ; // 4th key stroke (1,2) = "2" #200 wait(col == 4'b1111) row = 4'b1000 ; wait(col == 4'b1000) row = 4'b0000 ; wait(col == 4'b0100) row = 4'b1000 ; #200 row = 4'b0000 ; // 5th key stroke (4,3) = "#" #200 wait(col == 4'b1111) row = 4'b0001 ; wait(col == 4'b1000) row = 4'b0000 ; wait(col == 4'b0100) row = 4'b0000 ; wait(col == 4'b0010) row = 4'b0001 ; #200 row = 4'b0000 ;

Lock Testbench (Continued, even more) // Log signal info // initial begin // $dumpfile("./lock.dmp") ; // $dumpflush ; // $dumpvars(3, lock_tb) ; // end // Print out key code whenver valid_key goes active valid_key) begin $strobe("Key is %b and seg7 is %b", key, seg7) ; end endmodule