Last Lecture: Divide by 3 FSM

Similar documents
Last Lecture. Talked about combinational logic always statements. e.g., module ex2(input logic a, b, c, output logic f); logic t; // internal signal

Quick Introduction to SystemVerilog: Sequental Logic

Example Best and Median Results

Laboratory Exercise 3 Davide Rossi DEI University of Bologna AA

ECE 551: Digital System *

!== vs.!= and === vs. ==

Testbenches for Sequential Circuits... also, Components

ECE 2300 Digital Logic & Computer Organization. More Finite State Machines

ECE 2300 Digital Logic & Computer Organization. More Verilog Finite State Machines

Lecture 32: SystemVerilog

Sequential Logic Design

CSE 502: Computer Architecture

MCMASTER UNIVERSITY EMBEDDED SYSTEMS

Chapter 4. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 4 <1>

Chapter 4. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 4 <1>

SystemVerilog HDL - a programming language

Graduate Institute of Electronics Engineering, NTU. Lecturer: Chihhao Chao Date:

ECE 4514 Digital Design II. Spring Lecture 15: FSM-based Control

University of Technology

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

CSCB58 - Lab 3. Prelab /3 Part I (in-lab) /2 Part II (in-lab) /2 TOTAL /8

ECE 2300 Digital Logic & Computer Organization. More Verilog Finite State Machines

Chapter 4 :: Topics. Introduction. SystemVerilog. Hardware description language (HDL): allows designer to specify logic function only.

In the previous lecture, we examined how to analyse a FSM using state table, state diagram and waveforms. In this lecture we will learn how to design

In the previous lecture, we examined how to analyse a FSM using state table, state diagram and waveforms. In this lecture we will learn how to design

Finite State Machines

Digital Design with SystemVerilog

FSM and Efficient Synthesizable FSM Design using Verilog

EE 231 Fall EE 231 Homework 8 Due October 20, 2010

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

EE178 Lecture Verilog FSM Examples. Eric Crabill SJSU / Xilinx Fall 2007

EECS150 - Digital Design Lecture 10 Logic Synthesis

Blocking(=) vs Nonblocking (<=) Assignment. Lecture 3: Modeling Sequential Logic in Verilog HDL. Procedural assignments

Modeling Sequential Circuits in Verilog

EECS 270 Verilog Reference: Sequential Logic

ECE 2300 Digital Logic & Computer Organization. More Sequential Logic Verilog

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

Control in Digital Systems

Laboratory Exercise 7

ECE 4514 Digital Design II. Spring Lecture 2: Hierarchical Design

Recommended Design Techniques for ECE241 Project Franjo Plavec Department of Electrical and Computer Engineering University of Toronto

EECS150 - Digital Design Lecture 10 Logic Synthesis

CSE140L: Components and Design Techniques for Digital Systems Lab

EN164: Design of Computing Systems Lecture 07: Lab Foundations / Verilog 3

Introduction to Verilog and ModelSim. (Part 6 State Machines)

ECE 4514 Digital Design II. Spring Lecture 13: Logic Synthesis

CSE140L: Components and Design

FPGA for Software Engineers

Digital Design and Computer Architecture

Building Bigger Systems: Interfacing

HDLs and SystemVerilog. Digital Computer Design

Finite State Machines

Mealy and Moore examples

Verilog Behavioral Modeling

EEL 4783: HDL in Digital System Design

Logic Circuits II ECE 2411 Thursday 4:45pm-7:20pm. Lecture 3

ARM 64-bit Register File

Synthesis vs. Compilation Descriptions mapped to hardware Verilog design patterns for best synthesis. Spring 2007 Lec #8 -- HW Synthesis 1

EECS150 - Digital Design Lecture 7 - Computer Aided Design (CAD) - Part II (Logic Simulation) Finite State Machine Review

Synthesizable Verilog

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

HDL Design Cube. Synthesis and VHDL

VERILOG: FLIP-FLOPS AND REGISTERS

EECS150 - Digital Design Lecture 6 - Logic Simulation

Writing Circuit Descriptions 8

Verilog for High Performance

Sequential Circuit Design: Principle

CSE140L: Components and Design Techniques for Digital Systems Lab. FSMs. Instructor: Mohsen Imani. Slides from Tajana Simunic Rosing

Building Bigger Systems: Hardware Threads

A short introduction to SystemVerilog. For those who know VHDL We aim for synthesis

VHDL: RTL Synthesis Basics. 1 of 59

VHDL for Synthesis. Course Description. Course Duration. Goals

State Machine Descriptions

Verilog 1 - Fundamentals

Verilog for Synthesis Ing. Pullini Antonio

FPGA Design Challenge :Techkriti 14 Digital Design using Verilog Part 1

Chapter 9: Sequential Logic Modules

Parallel versus serial execution

Sequential Logic - Module 5

Digital Design Using Verilog EE Final Examination

TSEA44: Computer hardware a system on a chip

Debouncing a Switch. A Design Example. Page 1

Lecture 3. Behavioral Modeling Sequential Circuits. Registers Counters Finite State Machines

Graduate Institute of Electronics Engineering, NTU Design of Datapath Controllers

Synthesis of Language Constructs. 5/10/04 & 5/13/04 Hardware Description Languages and Synthesis

EECS150 - Digital Design Lecture 6 - Logic Simulation. Encoder Example

CprE 583 Reconfigurable Computing

Topics. Midterm Finish Chapter 7

[VARIABLE declaration] BEGIN. sequential statements

Sunburst Design - Comprehensive SystemVerilog Design & Synthesis by Recognized Verilog & SystemVerilog Guru, Cliff Cummings of Sunburst Design, Inc.

Chapter 9: Sequential Logic Modules

Sequential Circuit Design: Principle

Summary of FPGA & VHDL

ECE 545 Lecture 12. Datapath vs. Controller. Structure of a Typical Digital System Data Inputs. Required reading. Design of Controllers

Ripple Counters. Lecture 30 1

ECE 551 Digital System Design and Synthesis. Instructor: Kewal K. Saluja. Midterm Exam

ENGN1640: Design of Computing Systems Topic 02: Design/Lab Foundations

Verilog Execution Semantics

QUARTUS II Altera Corporation

Transcription:

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

Finite State Machines (FSMs) A simple Moore machine looks like the following inputs M next state logic k next state CLK k state output logic N outputs Slide derived from slides by Harris & Harris from their book 2

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; case state transition graph is the same thing as a state transition table, which can be specify as a case statement // output logic assign q = (state == S0); module output is 1 every clock cycles when we are in state S0 3

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; case compiler recognizes this template should use positive edge-triggered flip-flops w/ negative edge asynchronous reset should be used. next state logic state FF compiler knows this if part defines the reset values for flip-flops. output logic q // output logic assign q = (state == S0); module 4

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

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! 6

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; else begin case (state) S0: begin state <= S1; q <= 0; S1: begin state <= S2; q <= 0; S2: begin state <= S0; q <= 1; case module 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. 7

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; else begin case (state) S0: begin state <= S1; q <= 0; S1: begin state <= S2; q <= 0; S2: begin state <= S0; q <= 1; case module next state logic logic for q compiler knows this if part defines the reset values for flip-flops. state FF FF q 8

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

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... module clk reset_n input_s begiin_fibo fibonacci_ calculator fibo_out done 10

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; 11

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; else case (state) IDLE: if (begin_fibo) begin count <= input_s; R0 <= 1; R1 <= 0; state <= COMPUTE; in clocked always stmts, D-FFs keep track of previous value, so the missing else part will just keep state at IDLE. COMPUTE: if (count > 1) begin count <= count - 1; R0 <= R0 + R1; R1 <= R0; else begin state <= DONE; done <= 1; fibo_out <= R0; DONE: state <= IDLE; case module 12

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. 13

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:... case module 14