State machines and large designs

Similar documents
Digital Design with VHDL

FINITE STATE MACHINE: PRINCIPLE AND PRACTICE

if-then else : 2-1 mux mux: process (A, B, Select) begin if (select= 1 ) then Z <= A; else Z <= B; end if; end process;

VHDL programmering H2

ECE 3401 Lecture 7. Concurrent Statements & Sequential Statements (Process)

Finite State Machine Design and VHDL Coding Techniques

Using Xilinx ISE for VHDL Based Design

State Machines in VHDL

Step : Create Dependency Graph for Data Path Step b: 8-way Addition? So, the data operations are: 8 multiplications one 8-way addition Balanced binary

Finite State Machine. RTL Hardware Design by P. Chu. Chapter 10 1

Digital Design with Synthesizable VHDL

LAB #3 VHDL RECOGNITION AND GAL IC PROGRAMMING USING ALL-11 UNIVERSAL PROGRAMMER

12. A B C A B C A B C 1 A B C A B C A B C JK-FF NETr

CNC FOR EDM MACHINE TOOL HARDWARE STRUCTURE. Ioan Lemeni

(1) D Flip-Flop with Asynchronous Reset. (2) 4:1 Multiplexor. CS/EE120A VHDL Lab Programming Reference

Lenguaje VHDL. Diseño de sistemas digitales secuenciales

VHDL GUIDELINES FOR SYNTHESIS

Registers & Counters

Lecture 8: Synchronous Digital Systems

ECE232: Hardware Organization and Design. Part 3: Verilog Tutorial. Basic Verilog

An Example VHDL Application for the TM-4

More Verilog. 8-bit Register with Synchronous Reset. Shift Register Example. N-bit Register with Asynchronous Reset.

A New Paradigm for Synchronous State Machine Design in Verilog

VGA video signal generation

ETEC 2301 Programmable Logic Devices. Chapter 10 Counters. Shawnee State University Department of Industrial and Engineering Technologies

Modeling Latches and Flip-flops

In this example the length of the vector is determined by D length and used for the index variable.

Digital Systems Design. VGA Video Display Generation

A CPLD VHDL Introduction

Computer organization

7. Latches and Flip-Flops

Flip-Flops and Sequential Circuit Design. ECE 152A Winter 2012

Flip-Flops and Sequential Circuit Design

Register File, Finite State Machines & Hardware Control Language

EE 42/100 Lecture 24: Latches and Flip Flops. Rev B 4/21/2010 (2:04 PM) Prof. Ali M. Niknejad

Quartus II Introduction for VHDL Users

Sprites in Block ROM

Asynchronous Counters. Asynchronous Counters

CPE 462 VHDL: Simulation and Synthesis

Combinational Logic Design Process

Modeling Sequential Elements with Verilog. Prof. Chien-Nan Liu TEL: ext: Sequential Circuit

Designing Digital Circuits a modern approach. Jonathan Turner

Combinational-Circuit Building Blocks

Chapter 5. Sequential Logic

Technical Note. Micron NAND Flash Controller via Xilinx Spartan -3 FPGA. Overview. TN-29-06: NAND Flash Controller on Spartan-3 Overview

Napier University. School of Engineering. Electronic Engineering A Module: SE42205 Digital Design

INTRODUCTION TO DIGITAL SYSTEMS. IMPLEMENTATION: MODULES (ICs) AND NETWORKS IMPLEMENTATION OF ALGORITHMS IN HARDWARE

DDS. 16-bit Direct Digital Synthesizer / Periodic waveform generator Rev Key Design Features. Block Diagram. Generic Parameters.

To design digital counter circuits using JK-Flip-Flop. To implement counter using 74LS193 IC.

CHAPTER 3 Boolean Algebra and Digital Logic

Academic year: 2015/2016 Code: IES s ECTS credits: 6. Field of study: Electronics and Telecommunications Specialty: -

Below is a diagram explaining the data packet and the timing related to the mouse clock while receiving a byte from the PS-2 mouse:

EC313 - VHDL State Machine Example

Digital Logic Design. Basics Combinational Circuits Sequential Circuits. Pu-Jen Cheng

Engr354: Digital Logic Circuits

Lab 7: VHDL 16-Bit Shifter

ECE 451 Verilog Exercises. Sept 14, James Barnes

Sequential Logic Design Principles.Latches and Flip-Flops

Latches, the D Flip-Flop & Counter Design. ECE 152A Winter 2012

Aims and Objectives. E 3.05 Digital System Design. Course Syllabus. Course Syllabus (1) Programmable Logic

A Second Undergraduate Course in Digital Logic Design: The Datapath+Controller-Based Approach

Lab 1: Introduction to Xilinx ISE Tutorial

Asynchronous & Synchronous Reset Design Techniques - Part Deux

NOT COPY DO NOT COPY DO NOT COPY DO NOT COPY DO NOT COPY DO NOT COPY

VHDL Test Bench Tutorial

Digital Controller for Pedestrian Crossing and Traffic Lights

Memory Elements. Combinational logic cannot remember

Design: a mod-8 Counter

The 104 Duke_ACC Machine

(1) /30 (2) /30 (3) /40 TOTAL /100

Implementation of Web-Server Using Altera DE2-70 FPGA Development Kit

Modeling Registers and Counters

Decimal Number (base 10) Binary Number (base 2)

IE1204 Digital Design F12: Asynchronous Sequential Circuits (Part 1)

Chapter 7. Registers & Register Transfers. J.J. Shann. J. J. Shann

From UML to HDL: a Model Driven Architectural Approach to Hardware-Software Co-Design

Digital Electronics Detailed Outline

An Integer Square Root Algorithm

AES (Rijndael) IP-Cores

CS311 Lecture: Sequential Circuits

Start Active-HDL by double clicking on the Active-HDL Icon (windows).

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

DIGITAL COUNTERS. Q B Q A = 00 initially. Q B Q A = 01 after the first clock pulse.

Using SystemVerilog Assertions for Creating Property-Based Checkers

Lesson 12 Sequential Circuits: Flip-Flops

Hardware Implementation of the Stone Metamorphic Cipher

Using Altera MAX Series as Microcontroller I/O Expanders

8-ch RAID0 Design by using SATA Host IP Manual Rev1.0 9-Jun-15

A Verilog HDL Test Bench Primer Application Note

Lecture 11: Sequential Circuit Design

CSE140: Components and Design Techniques for Digital Systems

Finite State Machine Design A Vending Machine

Lecture 10: Sequential Circuits

Introduction to the Altera Qsys System Integration Tool. 1 Introduction. For Quartus II 12.0

Introduction to Programmable Logic Devices. John Coughlan RAL Technology Department Detector & Electronics Division

Take-Home Exercise. z y x. Erik Jonsson School of Engineering and Computer Science. The University of Texas at Dallas

SVA4T: SystemVerilog Assertions - Techniques, Tips, Tricks, and Traps

Transcription:

FYS4220/9220 State machines and large designs Lecture #4 Reading: chapter 5, 9-9.1.2, 9.2 and 3.5 in Zwolinski J. K. Bekkeng, 3.7.2011

FSMs- Finite State Machines

Traditional method: 1) Make the state diagram 2) Make the output table

3) Make the state table from the state diagram and the output table Present state and input Next state and output

Write the Boolean equations from the state table Use Karnaugh diagrams to simplify the Boolean equations

FSM design with VHDL Algorithmic state machine (ASM) chart (Flytskjema/Flowchart) State diagram or Code the FSM in VHDL Easy to code the FSM (from the ASM) using VHDL!

Flowchart elements (State box) (decision box) (Conditional output box)

State diagram vs ASM chart

Eksempel Styring av trafikklys See example in chapter 5.3

The ASM chart contains implicit timing information!

ASM chart guidelines Yes/No (1/0) labels together with decision boxes Arrows to show the program flow State names in top right/left corner of the state boxes Selected outputs listed in conditional output boxes and inside the state boxes Test condition listed in the decision boxes

State machines in VHDL An ASM chart (or a state diagram) can easily be translated to a VHDL description! In VHDL the state machine can be described in two different ways: 1-process FSM 2-process FSM One process describes the combinational logic, and another describes synchronization of state transitions to the clock Recommended!

Example II The state S0 can be realized when state S4 is asserted and the input CONT is low, or it remains at state S0 if all four inputs A, B, C, and D are low. Similarly, state S1 can be achieved when state S0 is asserted and any one of the four inputs A, B, C, or D is high, or it remains at the same state (S1) if the input PBGNT is low

VHDL code Example II 2-process FSM Synchronization to the clock combinational logic

Example: 2 process FSM library ieee; use ieee.std_logic_1164.all; entity memory_controller is port ( reset, read_write, ready, burst, clk : in std_logic; bus_id : in std_logic_vector(7 downto 0); oe, we : out std_logic; addr : out std_logic_vector(1 downto 0)); end memory_controller; architecture state_machine of memory_controller is type StateType is (idle, decision, read1, read2, read3, read4, write); signal present_state, next_state : StateType; begin state_comb:process(reset, bus_id, present_state, burst, read_write, ready) begin if (reset = '1') then oe <= '-'; we <= '-'; addr <= "--"; next_state <= idle; else case present_state is end case; end if; end process state_comb; state_clocked:process(clk) begin if rising_edge(clk) then present_state <= next_state; end if; end process state_clocked; end; Combinational logic Synchronous logic

Asynchronous reset in 2-process FSM

1-process FSM Functionally identical to the 2-process FSM, and the same logic is produced

Example: use of state machine for ADC (Analog to Digital Converter) control ADC data sheet VHDL code

Output from a state machine Recommended! 1) 2) 3) FSM: process (reset, clk) begin if (reset = 1 ) then state <= idle; FSM: process (reset, clk) begin if (reset = 1 ) then state <= idle; FSM: process (reset, clk) begin if (reset = 1 ) then state <= idle; elsif rising_edge (clk) then case state is when idle => oe <= 1 ; if (input1 = 1 ) then state <= s1; else state <= idle; end if; when s1 => oe <= 0 ;... elsif rising_edge (clk) then elsif rising_edge (clk) then oe <= 1 ; -- Default value case state is case state is when idle => when idle => if (input1 = 1 ) then if (input1 = 1 ) then state <= s1; state <= s1; else else state <= idle; state <= idle; end if; end if; when s1 => when s1 =>... oe <= 0 ; end process; with state select... oe <= 1 when idle, 0 when S1; end state_machine;

Example: Use of default values in FSMs

State encoding and enumeration type If the number of states is not 2 n there will be undefined states! Seven states Added state; 2 3 = 8

FSM fault tolerance If the state machine gets into an undefined (illegal) state it will be unpredictable (can e.g. stay in the illegal state forever) In safety critical systems it is absolutely necessary to always get to known states Demands additional logic to get out of illegal states type StateType is (idel, decision, read1, read2, read3, read4, write, undefined); Include a state name in the enumerated type for each undefined state Specify the state transition to get out of illegal states

Example with 3 undefined states

One-Hot encoding of FSM Uses one bit for each state A state machine with n states needs n flip-flops to store the states Only one flip-flop (bit) assigned to 1, indicating present state Output logic and next state logic is very simple Used in FPGAs (due to many flip-flops)

State machine with 18 states 5 18

One-Hot encoding setup in Quartus II No change in the VHDL code Setup in Quartus II before synthesis (Assignments Settings Analysis & Synthesis Settings More Settings)

Large designs - Hierarchy

Block diagrams

Hvordan gå frem for å skrive VHDL kode Tegn et forenklet blokkskjema ytre grensesnittet, i form av innsignaler og utsignaler, tilsvarer entitydeklarasjonen indre strukturen tilsvarer VHDL-beskrivelsens architecture-del. Det er ofte hensiktsmessig å dele opp den indre strukturen i en dataveistruktur og en kontrollstruktur. Dataveistrukturen inneholder elementer som registre, addere, multipleksere, som er sammenkoblet med databusser. Denne strukturen er velegnet til å beskrives i blokkskjema. Hvis strukturen er kompleks, lønner det seg å dele den opp i mindre blokker Kontrollogikkens innsignaler og utsignaler kan beskrives i blokkskjema sammen med dataveistrukturen. Den indre oppbyggingen beskrives best i form av: sannhetsverditabeller, boolske ligninger og ASM flytskjema/tilstandsdiagrammer Deretter kodes den strukturerte løsningen i VHDL Med utgangspunkt i en veldokumentert struktur skal det normalt være en grei jobb å lage en fungerende kode.

Example of a block diagram

Library library IEEE Building blocks use IEEE.std_logic_1164.all; Packages use work.my_package.all; -- your own package work is the directory where the design files are located Components An entity used in another entity To make the library visible Needs a component declaration to make the component visible Needs a component instantiation to connect the component to the top entity using port map()

Component declarations in a package A component declaration can be placed in a package To use the component in the design the package must be included in the design The package must have its own library and use The package is usually in a separate file, (e.g. my_package.vhd), and the components are in separate files as well (e.g. dflop.vhd) Without using a package:

Package example end regs_pkg;

A larger design using a package Component declaration Component instantiation (Komponenttilordninger)

Generics The width of a signal can be specified using a parameter Useful for registers and counters with different number of bits; only necessary to make one component Default value

Generic counter

Using Generic components generic map is used to assign a value to a generic component If the generic map is not specified the default value which is specified in the component is used Example: Name of the component Set the value of the CounterSize parameter U1: ascount generic map (3) -- or generic map (CounterSize => 3) port map (clk, areset, sreset, enable, count);

Generics Example The width of a signal can be specified using a parameter Useful for registers and counters with different number of bits; only necessary to make one component Entity using a generic How to use this component with a generic