Finite-State Machine (FSM) Design

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

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

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

RealDigital. Problem Set #7 S1 S2 S3 Y Z X Y + Y Z X Z

Finite State Machines

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

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

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

Mealy and Moore examples

ECE 551: Digital System *

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

Sequential Logic Implementation. Mealy vs. Moore Machines. Specifying Outputs for a Mealy Machine. Specifying Outputs for a Moore Machine

Debouncing a Switch. A Design Example. Page 1

Chapter 5 Registers & Counters

Modeling of Finite State Machines. Debdeep Mukhopadhyay

Modeling Sequential Circuits in Verilog

Parallel versus serial execution

Digital Integrated Circuits

Writing Circuit Descriptions 8

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

Digital Design with FPGAs. By Neeraj Kulkarni

One and a half hours. Section A is COMPULSORY UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

Control in Digital Systems

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

PDHonline Course G349. State Machines. Mark A. Strain, P.E. PDH Online PDH Center

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

Federal Urdu University of Arts, Science and Technology, Islamabad VLSI SYSTEM DESIGN. Prepared By: Engr. Yousaf Hameed.

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

Verilog for Synthesis Ing. Pullini Antonio

Finite State Machines

CSE 140L Final Exam. Prof. Tajana Simunic Rosing. Spring 2008

N-input EX-NOR gate. N-output inverter. N-input NOR gate

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

ENEE245 Digital Circuits and Systems Lab Manual

Recitation Session 6

FSM and Efficient Synthesizable FSM Design using Verilog

Sequential Logic Design

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

Midterm Exam Thursday, October 24, :00--2:15PM (75 minutes)

CSE 140L Final Exam. Prof. Tajana Simunic Rosing. Spring 2008

Finite State Machines

Laboratory Exercise 3 Davide Rossi DEI University of Bologna AA

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

Designing Safe Verilog State Machines with Synplify

ENEE245 Digital Circuits and Systems Lab Manual

ARM 64-bit Register File

ECE 353 Lab 4. Verilog Review. Professor Daniel Holcomb UMass Amherst Fall 2017

Digital Circuit Design and Language. Datapath Design. Chang, Ik Joon Kyunghee University

Quick Introduction to SystemVerilog: Sequental Logic

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

In this lecture, we will focus on two very important digital building blocks: counters which can either count events or keep time information, and

PART B. 3. Minimize the following function using K-map and also verify through tabulation method. F (A, B, C, D) = +d (0, 3, 6, 10).

Control and Datapath 8

Digital Circuits and Systems NOC, Spring 2015 Quiz 6 Solutions

Behavioral Modeling and Timing Constraints

Verilog Sequential Logic. Verilog for Synthesis Rev C (module 3 and 4)

DIGITAL LOGIC DESIGN VHDL Coding for FPGAs Unit 6

Lecture 32: SystemVerilog

General FSM design procedure

FSM Components. FSM Description. HDL Coding Methods. Chapter 7: HDL Coding Techniques

Laboratory Exercise 7

v HDL Compiler for Verilog Reference Manual Examples

DIGITAL SYSTEM DESIGN

Chap 6 Introduction to HDL (d)

(ii) Simplify and implement the following SOP function using NOR gates:

Introduction to Verilog HDL. Verilog 1

ENEE 245 Lab 1 Report Rubrics

Why Should I Learn This Language? VLSI HDL. Verilog-2

VHDL: RTL Synthesis Basics. 1 of 59

Date Performed: Marks Obtained: /10. Group Members (ID):. Experiment # 11. Introduction to Verilog II Sequential Circuits

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

A Brief Introduction to Verilog Hardware Definition Language (HDL)

DIGITAL LOGIC WITH VHDL (Fall 2013) Unit 6

ECE 353 Lab 3 (Verilog Design Approach)

Verilog Tutorial. Introduction. T. A.: Hsueh-Yi Lin. 2008/3/12 VLSI Digital Signal Processing 2

RTL Design (Using ASM/SM Chart)

One and a half hours. Section A is COMPULSORY UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Sciences

EECS 270 Verilog Reference: Sequential Logic

One and a half hours. Section A is COMPULSORY

Synthesizable Verilog

Homework deadline extended to next friday

First Name: Last Name: PID: CSE 140L Exam. Prof. Tajana Simunic Rosing. Winter 2010

C A R L E T O N U N I V E R S I T Y. FINAL EXAMINATION April Duration: 3 Hours No. of Students: 108

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

General FSM design procedure

Verilog 1 - Fundamentals

EECS 151/251A: SRPING 2017 MIDTERM 1

ECE 353 Lab 4. Verilog Review. Professor Daniel Holcomb With material by Professor Moritz and Kundu UMass Amherst Fall 2016

University of Toronto Faculty of Applied Science and Engineering Edward S. Rogers Sr. Department of Electrical and Computer Engineering

R07

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

Verilog Coding Guideline

Topics. Midterm Finish Chapter 7

COE 405, Term 062. Design & Modeling of Digital Systems. HW# 1 Solution. Due date: Wednesday, March. 14

Chapter 9: Sequential Logic Modules


University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences. Spring 2010 May 10, 2010

Using Programmable Logic and the PALCE22V10

Transcription:

1 Finite-State Machine (FSM) Design FSMs, an important category of sequential circuits, are used frequently in designing digital systems. From the daily used electronic machines to the complex digital systems, FSMs are used everywhere. For example, in a station the ving machine which dispatches ticket uses a simple FSM. In the complex digital systems the controlling part is most of the times implemented using FSMs. FSMs are generally of two types. 1. MEALY Machine: MEALY circuits are named after G. H, Mealy, one of the leading personalities in designing digital systems. The basic property of Mealy circuits is that the output is a function of the present input conditions and the present state (PS) of the circuit. 2. MOORE Machine: MOORE circuits are named after E. F. Moore, another leading personality in designing digital systems. The basic property of Moore circuits is that the output is strictly a function of the present state (PS) of the circuit. Most of the digital systems use either Moore or Mealy machine but both machines also can be used together. In initial days of digital system design when HDL languages are not discovered, Mealy or Moore machines are realized using K-Map optimization technique. The K-map optimization technique provides an optimized solution but it is a rigorous and lengthy process. On the contrary HDL provides an easy solution to the design of FSMs by saving design time. In this tutorial we will discuss design of some of the digital systems using both Mealy and Moore machine. We will up with a comparison between these two machines. Mealy based Sequence Detector Sequence detector is good example to describe FSMs. It produces a pulse output whenever it detects a predefined sequence. In this tutorial we have considered a 4-bit sequence 1010. The first step of an FSM design is to draw the state diagram. The sequence detectors can be of two types: with overlapping and without overlapping. For example consider the input sequence as 11010101011. Then in without overlapping style the output y will be 00001000100 and the output y in with overlapping style will be 00001010100. The with overlapping style also considers the overlapping sequences. The state diagram of the 1010 sequence detector using Mealy machine in without overlapping style is shown below.

2 Figure 1: Mealy based 1010 sequence detector without overlapping. The drawing of the correct state diagram is very crucial in designing FSMs. Though there is no fixed rule of drawing state diagrams but some comments can be made. In present state S 0, if input is 1 then the next state is S 1 and if input 0 then the next state is the current state. It is similar for present state S 1. In present state S 2 if there is a false bit, the next state is S 0 and in present state S 3 if there is a false bit, the next state is S 1. From the above statement it can be said that if there is a false input, the next state will be the nearest similar state. It is to remember that for any combinations we have to reach the branch where output is 1. For example consider input sequence (din) as 011010. The sequence of next states will be S 0 S 1 S 1 S 2 S 3 S 0. The 1010 sequence detector using Mealy machine without overlapping is realized using Verilog. The Verilog code is given below. module melfsm(din, reset, clk, y); input din; input clk; input reset; output reg y; reg [1:0] cst, nst; parameter S0 = 2'b00, //all states S1 = 2'b01, S2 = 2'b10, S3 = 2'b11;

3 always @(cst or din) /// use posedge clk to avoid glitch case (cst) S0: if (din == 1'b1) nst = S1; else nst = cst; S1: if (din == 1'b0) nst = S2; else nst = cst; S2: if (din == 1'b1)

4 nst = S3; else nst = S0; S3: if (din == 1'b0) nst = S0; y=1'b1; else nst = S1; default: nst = S0; case always@(posedge clk) if (reset) cst <= S0;

5 else module cst <= nst; The optimized logic architecture for 1010 sequence detector without overlapping using Mealy Machine is shown below. Here instead of giving the RTL schematic we have given the K-map optimized block diagram for better understanding. Figure 2: 1010 sequence detector without overlapping using Mealy machine

6 Sequence detector with overlapping Figure 3: State diagram for 1010 sequence detector using Mealy machine (with overlapping) The Verilog implementation of this FSM can be found in Verilog file in the download section. Moore based sequence detector The same 1010 sequence detector is designed also in Moore machine to show the differences. The state diagrams for 1010 sequence detector with overlapping and without overlapping are shown below. Figure 4: State diagram for 1010 sequence detector using Moore machine (without overlapping)

7 Figure 5: State diagram for 1010 sequence detector using Moore machine (with overlapping) The Moore machine can be designed same way as Mealy machine using Verilog. Only difference is that in case of Moore machine there are 5 states. Instead of output branch, there is a output state in case of Moore Machine. The objective is to reach the output state from any state. The Verilog codes for Moore implementations can be found in Verilog file in Download section. The logic diagram is shown below for 1010 sequence detector without overlapping. Figure 5: Block diagram for 1010 sequence detector using Moore machine (without overlapping)

8 A comparison can be drawn between Figure 3 and Figure 5. In Figure 3, which is the block diagram, of a Mealy machine, output deps on input and the current states or output of the flip-flops. Whereas in Figure 5, which is the block diagram of a Moore machine, output is function of only the present states or output of the flip-flops. And also there is an extra flip-flop used in case of Moore Machine. Serial Adder: Serial adder design using FSM is a popular design which is frequently used in literature. Here in this tutorial we will design a serial adder using Mealy machine. The state diagram for the serial full adder is shown below. There are two states defined based on carry. The state S 0 is for carry equal to zero and S 1 is for carry equal to 1. Figure 6: State diagram for serial full adder The state diagram can be understood clearly from the truth table of full adder which is shown below. Table 1: Truth table for full adder PS cin a b sum cout NS S 0 0 0 0 0 0 S 0 S 0 0 0 1 1 0 S 0 S 0 0 1 0 1 0 S 0 S 0 0 1 1 0 1 S 1 S 1 1 0 1 0 1 S 1 S 1 1 1 0 0 1 S 1 S 1 1 1 1 1 1 S 1 S 1 1 0 0 1 0 S 0

9 module serial_add(a,b,cin,reset,clk,sum,nst); output reg sum; input a,b,cin; input clk; input reset; reg cst; output reg nst; /// carry out initial cst = cin; /// state assignment parameter S0 = 1'b0, S1 = 1'b1; /// Synvhronous with clock always @(posedge clk) case (cst) S0 : sum=a^b; if(a&b) nst = S1; else nst = cst; S0 : sum=~(a^b); if(~a&~b) nst = S0;

10 else nst = cst; default: nst = S0; case /// reset facility always@(posedge clk) if (reset) cst <= S0; else cst <= nst; module Ving Machine Problem Ving Machine is a practical example where FSM is used. The ticket dispatcher unit at the stations, the can drinks dispatcher at the shops are some examples of Ving machines. Here in this tutorial we will try to understand a simple Ving machine which dispatches a can of coke after deposition of 15 rupees. The machine has only one hole to receive coins that means customers can deposit one coin at a time. Also the machine receives only 10 (T) or 5 (F) rupee coin and it doesn t give any change. So the input din can take values like 1. din = 00, no coin deposited. 2. din = 01, 5 rupee coin (F) deposited. 3. din = 10, 5 rupee coin (T) deposited. 4. din = 11, forbidden - Both coin can t be deposited at same time. Also a customer can deposit 15 rupees by the following ways 1. 10 + 5 = 15 2. 5 + 10 = 15 3. 5 + 5 + 5 = 15

11 If more money is deposited than 15 then the machine will be on the same state asking the customer to deposit right amount. The state diagram for the ving machine is shown below. Figure 7: The state diagram for the Ving machine The PS/NS and output table for the Ving machine problem discussed above is shown below. Table 2: PS/NS and output Present Next State Output State din = 00 din = 01 din = 10 din = 00 din = 01 din = 10 S0 S0 S1 S2 0 0 0 S1 S1 S2 S3 0 0 1 S2 S2 S3 S2 0 1 0 S3 S3 S1 S2 0 0 0 module ving(t,f,reset,clk,y); output reg y; input T,F;

12 input clk; input reset; wire [1:0] din; assign din = {T,F}; reg [2:0] cst, nst; parameter S0 = 2'b00, S1 = 2'b01, S2 = 2'b10, S3 = 2'b11; always @(posedge clk or din) case (cst) S0: if (din == 2'b00) nst = S0; else if (din == 2'b01) nst = S1; else if (din == 2'b10) nst = S2;

13 S1: if (din == 2'b00) nst = S1; else if (din == 2'b01) nst = S2; else if (din == 2'b10) nst = S3; y=1'b1; S2: if (din == 2'b00) nst = S2; else if (din == 2'b01) nst = S3;

14 y=1'b1; else if (din == 2'b10) nst = S2; S3: if (din == 2'b00) nst = cst; else if (din == 2'b01) nst = S1; else if (din == 2'b10) nst = S2; default: nst = S0;

15 case always@(posedge clk) if (reset) cst <= S0; else cst <= nst; module Comparison between Moore and Mealy Machine Mealy Machine Output deps on present input and present state of the circuit. Required less number of states Asynchronous output generation though the state changes synchronous to the clock Faster, output is generated on the same clock cycle. Glitches can be generated as output change deps on input transition. Moore Machine Output deps only on the present state of the circuit. Required more number of states than Mealy machine Both output and state change synchronous to the clock edge Output is generally produced in the next clock cycle Safer to use, because they change states on the clock edge Note: To avoid the glitches in Mealy machine, registered Mealy machine or synchronous Mealy or really Moore is used. Synchronous Mealy machines are nothing but a Moore machine without output state decoder.