Lecture 4: Continuation of SystemVerilog

Slides:



Advertisements
Similar presentations
FSM and Efficient Synthesizable FSM Design using Verilog
Advertisements

//HDL Example 8-2 // //RTL description of design example (Fig.8-9) module Example_RTL (S,CLK,Clr,E,F,A);
Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Synchronous Sequential Logic
Combinational Logic.
Table 7.1 Verilog Operators.
//HDL Example 5-1 // //Description of D latch (See Fig.5-6) module D_latch (Q,D,control); output Q; input.
Verilog. 2 Behavioral Description initial:  is executed once at the beginning. always:  is repeated until the end of simulation.
//HDL Example 6-1 // //Behavioral description of //Universal shift register // Fig. 6-7 and Table 6-3 module shftreg.
Specifies combinational logic (unclocked) always stmt. should use “=“ (called “blocking” assignment) in comb. logic always statements. RHS just takes output.
ECE 551 Digital System Design & Synthesis Lecture 09 Synthesis of Common Verilog Constructs.
CSE Spring Verilog for Sequential Systems - 1 Today: Verilog and Sequential Logic zFlip-flops yrepresentation of clocks - timing of state.
FSM examples.
Verilog Sequential Circuits Ibrahim Korpeoglu. Verilog can be used to describe storage elements and sequential circuits as well. So far continuous assignment.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Senior Design I Lecture 4 - Verilog 2 (Sequential.
Sequential Logic in Verilog
ECE 551 Digital System Design & Synthesis Fall 2011 Midterm Exam Overview.
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Ders 8: FSM Gerçekleme ve.
DLD Lecture 26 Finite State Machine Design Procedure.
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
Finite State Machine (FSM) Nattha Jindapetch December 2008.
Digital System Design using VHDL
Chapter 11: System Design Methodology Digital System Designs and Practices Using Verilog HDL and 2008, John Wiley11-1 Chapter 11: System Design.
EMT 351/4 DIGITAL IC DESIGN Verilog Behavioral Modeling  Finite State Machine -Moore & Mealy Machine -State Encoding Techniques.
1 Lecture 3: Modeling Sequential Logic in Verilog HDL.
Figure Implementation of an FSM in a CPLD..
Overview Logistics Last lecture Today HW5 due today
SystemVerilog.
Chapter 4 Digital Design and Computer Architecture: ARM® Edition
Project 2: Byte Rotation
Verilog Tutorial Fall
Supplement on Verilog FF circuit examples
Supplement on Verilog for Algorithm State Machine Chart
Figure 8.1. The general form of a sequential circuit.
Last Lecture Talked about combinational logic always statements. e.g.,
SR Flip-Flop Negative Edge Triggered Flip-Flops The SR Flip-Flop
© Copyright 2004, Gaetano Borriello and Randy H. Katz
EMT 351/4 DIGITAL IC DESIGN Week # Synthesis of Sequential Logic 10.
Chapter 4 Digital Design and Computer Architecture, 2nd Edition
Chapter 4 Digital Design and Computer Architecture, 2nd Edition
Sequential Logic Counters and Registers
Asynchronous Inputs of a Flip-Flop
These 19 words are given and fixed
Example Best and Median Results
Buttons and Debouncing Finite State Machine
HDL Compiler Unsupport (Do NOT use in your verilog code)
COMP541 State Machines Montek Singh Feb 4, 2010.
SYNTHESIS OF SEQUENTIAL LOGIC
CSE 370 – Winter Sequential Logic-2 - 1
FSM MODELING MOORE FSM MELAY FSM. Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-2]
SystemVerilog Implementation of GCD
CSE 370 – Winter Sequential Logic-2 - 1
332:437 Lecture 8 Verilog and Finite State Machines
Lecture 17 Logistics Last lecture Today HW5 due on Wednesday
COE 202 Introduction to Verilog
Register-Transfer Level Components in Verilog
Figure 8.1. The general form of a sequential circuit.
Dr. Tassadaq Hussain Introduction to Verilog – Part-3 Expressing Sequential Circuits and FSM.
The Verilog Hardware Description Language
Lecture 17 Logistics Last lecture Today HW5 due on Wednesday
332:437 Lecture 9 Verilog Example
332:437 Lecture 9 Verilog Example
Lecture 22 Logistics Last lecture Today HW7 is due on Friday
Dr. Tassadaq Hussain Introduction to Verilog – Part-4 Expressing FSM in Verilog (contd) and FSM State Encoding Dr. Tassadaq Hussain.
332:437 Lecture 8 Verilog and Finite State Machines
Lecture 22 Logistics Last lecture Today HW7 is due on Friday
Announcements Assignment 7 due now or tommorrow Assignment 8 posted
332:437 Lecture 9 Verilog Example
Lecture 7: Verilog Part II
Presentation transcript:

Lecture 4: Continuation of SystemVerilog

The double circle indicates the reset state Last Lecture: Divide by 3 FSM Output should be “1” every 3 clock cycles The double circle indicates the reset state Slide derived from slides by Harris & Harris from their book

Finite State Machines (FSMs) A simple Moore machine looks like the following Slide derived from slides by Harris & Harris from their book

FSM Example in SystemVerilog module divideby3FSM (input logic clk, reset_n, output logic q); enum logic [1:0] {S0=2’b00, S1=2’b01, S2=2’b10} state; // declare states as enum // next state logic and state register always_ff @(posedge clk, negedge reset_n) begin if (!reset_n) state <= S0; else begin case (state) S0: state <= S1; S1: state <= S2; S2: state <= S0; endcase end // output logic assign q = (state == S0); endmodule state transition graph is the same thing as a state transition table, which can be specify as a case statement output is “1” every clock cycles when we are in state S0

FSM Example in SystemVerilog module divideby3FSM (input logic clk, reset_n, output logic q); enum logic [1:0] {S0=2’b00, S1=2’b01, S2=2’b10} state; // declare states as enum // next state logic and state register always_ff @(posedge clk, negedge reset_n) begin if (!reset_n) state <= S0; else begin case (state) S0: state <= S1; S1: state <= S2; S2: state <= S0; endcase end // output logic assign q = (state == S0); endmodule compiler recognizes this “template” should use positive edge-triggered flip-flops w/ negative edge asynchronous reset should be used. compiler knows this “if” part defines the reset values for flip-flops. state next state logic output logic FF q

What asynchronous reset means “Negative-edge asynchronous reset” means the following: flip-flops get reset on this negedge transition reset_n clk

Continuing with the FSM Example What if we want to design the “Divide by 3 FSM” example with just one “always_ff” statement (no separate “assign” statement)? Let’s assume we still want “q” to be “1” when we are in state “S0”. Can we put the logic for “q” instead the “always_ff” statement? Yes, but a flip-flop will be created for “q”!

FSM Example in SystemVerilog module fsm2 (input logic clk, reset_n, output logic q); enum logic [1:0] {S0=2'b00, S1=2'b01, S2=2'b10} state; // declare states as enum always_ff @(posedge clk, negedge reset_n) begin if (!reset_n) begin state <= S0; q <= 1; end else begin case (state) S0: begin state <= S1; q <= 0; end S1: begin state <= S2; S2: begin endcase endmodule synthesis will generate D-FFs for both “state” and “q” in order to have the output “q” = 1 when “state” is in S0, have to set the D-FF for “q” in S2 so that the output “q” = 1 when “state” gets to S0.

FSM Example in SystemVerilog module fsm2 (input logic clk, reset_n, output logic q); enum logic [1:0] {S0=2'b00, S1=2'b01, S2=2'b10} state; // declare states as enum always_ff @(posedge clk, negedge reset_n) begin if (!reset_n) begin state <= S0; q <= 1; end else begin case (state) S0: begin state <= S1; q <= 0; end S1: begin state <= S2; S2: begin endcase endmodule compiler knows this “if” part defines the reset values for flip-flops. state next state logic FF logic for “q” FF q

RTL Example module rtl_example (input logic clk, reset_n, input logic [7:0] a, b, output logic [7:0] f, count); // default encoding: s0=2’b00, s1=2’b01, s2=2’b10 enum logic [1:0] {s0, s1, s2} state; logic [7:0] c, t; function logic [7:0] myinc(input logic [7:0] x); logic [7:0] sum; logic c; // this is an internal c begin c = 1; for (int i = 0; i < 8; i++) begin sum[i] = x[i] ^ c; c = c & x[i]; end myinc = sum; endfunction always_comb t = c << 1; f = t + 1; always_ff@(posedge clk, negedge reset_n) if (!reset_n) begin count <= 0; c <= 0; // this c is different than function state <= s0; end else begin case (state) s0: begin c <= 0; state <= s1; end s1: begin count <= count + 1; c <= a + b; state <= s2; s2: begin count <= myinc(count); c <= a – b; endcase endmodule

RTL Example reset_n clk module rtl_example clocked always block c logic always block 00 01 10 11 a + 8 c t <<1 +1 f 8 8 8 – b 8 count 00 01 10 11 +1 count 8 myinc s1 00 01 10 11 state s2 state 2 s0

Fibonacci Calculator F(0) = 0, F(1) = 1 F(n) = F(n – 1) + F(n – 2), when n > 1 Examples:

Fibonacci Calculator Design a FSM with the interface below. input_s is “n”, and fibo_out is “F(n)”. Wait in IDLE state until begin_fibo. When testbench sees done==1, it will check if fibo_out== F(input_s). module fibonacci_calculator (input logic clk, reset_n, input logic [4:0] input_s, input logic begin_fibo, output logic [15:0] fibo_out, output logic done); ... always_ff @(posedge clk, negedge reset_n) begin end endmodule fibonacci_ calculator clk fibo_out reset_n input_s done begiin_fibo

Fibonacci Calculator Basic idea is to introduce 3 registers: logic [4:0] counter; logic [15:0] R0, R1; Set loop counter to “n” counter <= input_s; Repeat as long as counter is greater than 1 since we already know what F(0) and F(1) are: counter <= counter – 1; R0 <= R0 + R1; R1 <= R0; Finally, set output to “F(n)” done <= 1; fibo_out <= R0;

Fibonacci Calculator module fibonacci_calculator (input logic clk, reset_n, input logic [4:0] input_s, input logic begin_fibo, output logic [15:0] fibo_out, output logic done); enum logic [1:0] {IDLE=2'b00, COMPUTE=2'b01, DONE=2'b10} state; logic [4:0] count; logic [15:0] R0, R1; always_ff @(posedge clk, negedge reset_n) begin if (!reset_n) begin state <= IDLE; done <= 0; end else case (state) IDLE: if (begin_fibo) begin count <= input_s; R0 <= 1; R1 <= 0; state <= COMPUTE; end COMPUTE: if (count > 1) begin count <= count - 1; R0 <= R0 + R1; R1 <= R0; end else begin state <= DONE; done <= 1; fibo_out <= R0; end DONE: state <= IDLE; endcase endmodule in clocked always stmts, D-FFs keep track of previous value, so the missing “else” part will just keep “state” at IDLE.

Fibonacci Calculator A three state solution is provided. Design it using only 2 states (or fewer) w/o creating flip-flops for fibo_out or done, and should work for n ≥ 1. Hint: use “assign” statements for fibo_out and done. Use provided “tb_fibonacci_calculator.sv” to verify your design using ModelSim. Synthesize your 2-state “fibonacci_calculator.sv” design using Quartus.

Fibonacci Calculator: 2 States module fibonacci_calculator (...); enum logic {IDLE=1'b0, COMPUTE=1'b1} state; logic [4:0] count; logic [15:0] R0, R1; assign done = ...; // no FF will be generated assign fibo_out = ...; // no FF will be generated // just update count, R0, R1, state in always_ff always_ff @(posedge clk, negedge reset_n) begin if (!reset_n) ... else case (state) IDLE: COMPUTE: endcase end endmodule