Finite state machines (cont d)

Similar documents
FSM Optimization. Outline. FSM State Minimization. Some Definitions. Methods 10/14/2015

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

Lecture 20: Sequential Circuits. Sequencing

Realtime Regular Expressions for Analog and Mixed-Signal Assertions

Homing with MEI Motion Card and ASIC-100

Derivation of State Graphs and Tables UNIT 14 DERIVATION OF STATE GRAPHS AND TABLES. Designing a Sequential Circuit. Sequence Detectors

Delay Budgeting in Sequential Circuit with Application on FPGA Placement

MATH 112 Section 7.3: Understanding Chance

EE115C Spring 2013 Digital Electronic Circuits. Lecture 19: Timing Analysis

Lecture 8: Skew Tolerant Design (including Dynamic Circuit Issues)

Bits and Bit Patterns. Chapter 1: Data Storage (continued) Chapter 1: Data Storage

Physical Unclonable Functions (PUFs) and Secure Processors. Srini Devadas Department of EECS and CSAIL Massachusetts Institute of Technology

Solutions - Final Exam (December 7:30 am) Clarity is very important! Show your procedure!

Lecture 14: Basic Fixpoint Theorems (cont.)

Reconfigurable Acceleration for Monte Carlo based Financial Simulation

The Binomial Distribution

Data Dissemination and Broadcasting Systems Lesson 08 Indexing Techniques for Selective Tuning

Sequential Gates. Gate Level Design. Young Won Lim 3/15/16

PROCESS SPECIFICATION

FIGURE A1.1. Differences for First Mover Cutoffs (Round one to two) as a Function of Beliefs on Others Cutoffs. Second Mover Round 1 Cutoff.

Rewriting Codes for Flash Memories Based Upon Lattices, and an Example Using the E8 Lattice

PUF Design - User Interface

Enventive Monte Carlo Analysis Tutorial Version 4.1.x

Information Theory and Coding Prof. S. N. Merchant Department of Electrical Engineering Indian Institute of Technology, Bombay

Moving PUFs out of the lab

Practical SIS Design and SIL Verification

ITM1010 Computer and Communication Technologies

10-bit Pipeline ADC Design

Supersedes: 9/01/11 (Rev.5) Preparer: Owner: Approver: Team Member, North America Process Safety Center of Expertise

3.6V / 2600mAh Primary Lithium x 0.85 (60mm x 21mm) 1.0 oz (28 gr) -30 C to +77 C. Bluetooth Low Energy dBm. +5dBm. 1Mbit/s / 2Mbit/s*

Calcolatori Elettronici Anno Accademico 2001/2002. FSM in VHDL. Macchina a Stati Finiti (FSM) Tipo Moore. Esempio: Macchina di Moore a due stati

Linear functions Increasing Linear Functions. Decreasing Linear Functions

Pro Strategies Help Manual / User Guide: Last Updated March 2017

Unit 6: Amortized Analysis

10G BASE-T/Cat 6a Compliance Testing of Glenair SpeedMaster Contacts and 24AWG Aerospace Grade SF/UTP CAT 6a Cable

Advanced Verification Management and Coverage Closure Techniques

The Blockchain Trevor Hyde

Linear Modeling Business 5 Supply and Demand

CS 461: Machine Learning Lecture 8

10 5 The Binomial Theorem

Ibrahim Sameer (MBA - Specialized in Finance, B.Com Specialized in Accounting & Marketing)

Understanding the customer s requirements for a software system. Requirements Analysis

Harness the Super Powers for Super Profits!

Automatic Generation and Optimisation of Reconfigurable Financial Monte-Carlo Simulations

WHS FutureStation - Guide LiveStatistics

Westpac Smart ATMs. Simple, secure and always open

BAdIs in WCM. Release ERP 6.0, EhP3 + EhP5. Michael Lesk WCM GmbH. WCM Info Day October 2010 Amsterdam, Netherlands

Probability and Sample space

Lecture 12: MDP1. Victor R. Lesser. CMPSCI 683 Fall 2010

Test - Sections 11-13

Homework 1 posted, due Friday, September 30, 2 PM. Independence of random variables: We say that a collection of random variables

QUICK START GUIDE: THE WIZARD FOREX

Essays on Herd Behavior Theory and Criticisms

NASDAQ Futures, Inc. (NFX) Market Maker Protection & Self-Match Prevention Reference Guide. Version

Convenience Yield Calculator Version 1.0

Price Pattern Detection using Finite State Machines with Fuzzy Transitions

4.3 The money-making machine.

Markov Decision Processes: Making Decision in the Presence of Uncertainty. (some of) R&N R&N

Chapter 3 Discrete Random Variables and Probability Distributions

ECE 586GT: Problem Set 1: Problems and Solutions Analysis of static games

Basic Procedure for Histograms

MA 1125 Lecture 14 - Expected Values. Wednesday, October 4, Objectives: Introduce expected values.

Section 1.3 Problem Solving. We will begin by introducing Polya's 4-Step Method for problem solving:

Math 180A. Lecture 5 Wednesday April 7 th. Geometric distribution. The geometric distribution function is

CS221 / Spring 2018 / Sadigh. Lecture 7: MDPs I

Lecture 7: MDPs I. Question. Course plan. So far: search problems. Uncertainty in the real world

Copyright by Profits Run, Inc. Published by: Profits Run, Inc Beck Rd Unit F1. Wixom, MI

Lecture 8: Skew Tolerant Domino Clocking

edunepal_info

LTE RF Planning Training LTE RF Planning, Design, Optimization Training

Lesson 4: Why do Banks Pay YOU to Provide Their Services?

Max Registers, Counters and Monotone Circuits

Chapter 4: Commonly Used Distributions. Statistics for Engineers and Scientists Fourth Edition William Navidi

Lecture 12. Some Useful Continuous Distributions. The most important continuous probability distribution in entire field of statistics.

STAT 201 Chapter 6. Distribution

MiCOM P443-6/P543-7/P841

Section 1: Results for the Three Months Ended June 30, Section 2: Restructuring IAB Development and Production Centers.

(C). D-FF P:2 U3 D:4 U1 Q:5 U5 CLK:1 C:3. U2 100k P:2 U1 SN7474 Q:3 U4 0 L U5 1M CLK:1 U3 5 H CLK L H L H. L u 5.00u 7.50u 10.

Variation Aware Placement for Efficient Key Generation using Physically Unclonable Functions in Reconfigurable Systems

PUF RO (RING OSCILLATOR)

A.REPRESENTATION OF DATA

INTERNATIONAL STANDARD

Real Estate Private Equity Case Study 3 Opportunistic Pre-Sold Apartment Development: Waterfall Returns Schedule, Part 1: Tier 1 IRRs and Cash Flows

V. Lesser CS683 F2004

2D5362 Machine Learning

x is a random variable which is a numerical description of the outcome of an experiment.

Savings account conditions (inc cash ISAs)

Active and Passive Side-Channel Attacks on Delay Based PUF Designs

SMT and POR beat Counter Abstraction

COMP251: Amortized Analysis

Finite Memory and Imperfect Monitoring

1 Online Problem Examples

Fairport Public Library

Secure and Energy Efficient Physical Unclonable Functions

TEPZZ 858Z 5A_T EP A1 (19) (11) EP A1 (12) EUROPEAN PATENT APPLICATION. (43) Date of publication: Bulletin 2015/15

Technical indicators

Technical Whitepaper

Buyer's Guide To Fixed Deferred Annuities

GEK1544 The Mathematics of Games Suggested Solutions to Tutorial 3

IEC : Annex F

Transcription:

Finite state machines (cont d)! Another type of shift register " Linear-feedback shift register (LFSR)! Used to generate pseudo-random numbers! Some FSM examples Autumn 2014 CSE390C - VIII - Finite State Machines 2 1

Lets start with a shift register and scramble states! Basic shift register OUT1 OUT2 OUT3 OUT4 IN CLK! Mobius counter IN Q Q Q Q OUT1 OUT2 OUT3 OUT4 Q Q Q Q! LFSR CLK IN CLK 0000, 1000, 1100, 1110, 1111, 0111, 0011, 0001, OUT1 OUT2 OUT3 OUT4 Q Q Q Q 0000, 1000, 1100, 1110, 0111, 1011, 1101, 0110, 0011, 1001, 0100, 1010, 0101, 0010, 0001, 1000, Autumn 2014 CSE390C - VIII - Finite State Machines 2 2

LFSR in Verilog module LFSR (clk, reset, out); input clk, reset; output [0:3] out; reg [0:3] out; wire LFSRin; assign LFSRin = ~(out[2] ^ out[3]); always @(posedge clk) begin if (reset) out = 0; else out = {LFSRin, out [0:2]}; end endmodule Autumn 2014 CSE390C - VIII - Finite State Machines 2 3

Adding and overflow! Very simple: use +, e.g., sum[3:0] = a[3:0] + b[3:0]; " Representing positive and negative numbers! shortcut: 2s complement = bit-wise complement + 1 " 0111 -> 1000 + 0001 -> 1001 (representation of -7) " 1001 -> 0110 + 0001 -> 0111 (representation of 7) " Make sure addends and sum have same number of bits! Overflow " If only positive numbers then make sum 1 bit bigger! If that bit is 1 then there is overflow, e.g, sum[4:0] = a[3:0] + b[3:0]; " Add two positive numbers and end up with a negative number " Add two negative numbers and end up with a positive number Autumn 2014 CSE390C - VIII - Finite State Machines 2 4

Some simple synthesis examples wire [3:0] x, y, a, b, c, d; assign apr = ^a; assign y = a & ~b; assign x = (a == b)? a + c : d + a; a c + d + x a c d + x b == b == Autumn 2014 CSE390C - VIII - Finite State Machines 2 5

Example FSM: a vending machine! Release item after 15 cents are deposited! Single coin slot for dimes, nickels! No change Reset Coin Sensor N Vending Machine FSM Open Release Mechanism Clock Autumn 2014 CSE390C - VIII - Finite State Machines 2 6

Example: vending machine (cont d)! Suitable abstract representation " tabulate typical input sequences:! 3 nickels! nickel, dime! dime, nickel! two dimes " draw state diagram:! inputs: N,, reset! output: open chute " assumptions:! assume N and asserted for one cycle! each state has a self loop for N = = 0 (no coin) S1 N S0 Reset S2 Autumn 2014 CSE390C - VIII - Finite State Machines 2 7

Example: vending machine (cont d)! Suitable abstract representation " tabulate typical input sequences: Reset! 3 nickels! nickel, dime S0! dime, nickel N! two dimes " draw state diagram:! inputs: N,, reset N S1 N S2! output: open chute " assumptions:! assume N and asserted for one cycle! each state has a self loop for N = = 0 (no coin) N S7 [open] S3 S8 [open] S4 [open] S5 [open] S6 [open] Autumn 2014 CSE390C - VIII - Finite State Machines 2 8

Reuse equivalent states! When are states equivalent: same output AN transitions to equivalent states on every input combination! Redraw the state diagram using as few states as possible Reset Reset N S0 0 N S1 S2 5 N S7 [open] S3 N S8 [open] S4 [open] N S5 [open] S6 [open] 10 N 15 [open] N Autumn 2014 CSE390C - VIII - Finite State Machines 2 9

Verilog specification of vending machine module vending_machine(clk, reset, N,, open); input clk, reset, N, ; output open; reg [1:0] ps, ns; parameter zero = 2 b00; five = 2 b01, ten = 2 b10, fifteen = 2 b11; always @(*) begin case (ps): zero: if (N) ns = five; elseif () ns = ten; else ns = zero; five: if (N) ns = ten; elseif () ns = fifteen; else ns = five; ten: if (N ) ns = fifteen; else ns = ten; fifteen: ns = fifteen; default: ns = zero; end always @(posedge clk) begin if (reset) ps = zero; else ps = ns; end assign open = (ps == fifteen); endmodule Autumn 2014 CSE390C - VIII - Finite State Machines 2 10

Example: vending machine (cont d)! Minimize number of states - reuse states whenever possible 0 5 Reset N N 10 N + present inputs next output state N state open 0 0 0 0 0 0 1 5 0 1 0 10 0 1 1 5 0 0 5 0 0 1 10 0 1 0 15 0 1 1 10 0 0 10 0 0 1 15 0 1 0 15 0 1 1 15 15 1 15 [open] symbolic state table Autumn 2014 CSE390C - VIII - Finite State Machines 2 11

Example: vending machine (cont d)! Uniquely encode states then come up with logic for next state bits (1 and 0) and the output signal, open present state inputs next state output Q1 Q0 N 1 0 open 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 1 1 0 1 0 0 0 1 0 0 1 1 0 0 1 0 1 1 0 1 1 1 0 0 0 1 0 0 0 1 1 1 0 1 0 1 1 0 1 1 1 1 1 1 1 Autumn 2014 CSE390C - VIII - Finite State Machines 2 12

Implementation of vending machine! Mapping to logic (how many logic blocks in our FPGA?) 1 = Q1 + + Q0 N 0 = Q0 N + Q0 N + Q1 N + Q1 OPEN = Q1 Q0 Autumn 2014 CSE390C - VIII - Finite State Machines 2 13

Vending machine: Moore to synch. Mealy! OPEN = Q1Q0 creates a combinational delay after Q1 and Q0 change! This can be corrected by retiming, i.e., move flip-flops and logic through each other to improve delay pre-compute OPEN then store it in FF! OPEN.d = (Q1 + + Q0N)(Q0'N + Q0N' + Q1N + Q1) = Q1Q0N' + Q1N + Q1 + Q0'N + Q0N'! Implementation now is completely synchronous: outputs change on clock " another reason programmable devices have FF at end of logic Autumn 2014 CSE390C - VIII - Finite State Machines 2 14

ALM: adaptive logic module! The following types of functions can be realized in a single ALM: " Two independent 4-input functions " An independent 5-input function and an independent 3-input function " A 5-input function and a 4-input function, if they share one input " Two 5-input functions, if they share two inputs " An independent 6-input function " Two 6-input functions, if they share four inputs and share function " Some 7-input functions! An ALM also has 4 bits of memory " We ll discuss later when we talk about sequential logic Autumn 2014 CSE390C - VIII - Finite State Machines 2 15

Example: traffic light controller! Highway/farm road intersection farm road car sensors highway Autumn 2014 CSE390C - VIII - Finite State Machines 2 16

Example: traffic light controller (cont d)! A busy highway is intersected by a little used farmroad! etectors C sense the presence of cars waiting on the farmroad " with no car on farmroad, light remain green in highway direction " if vehicle on farmroad, highway lights go from Green to Yellow to Red, allowing the farmroad lights to become green " these stay green only as long as a farmroad car is detected but never longer than a set interval " when these are met, farm lights transition from Green to Yellow to Red, allowing highway to return to green " even if farmroad vehicles are waiting, highway gets at least a set interval as green! Assume you have an interval timer (a second state machine) that generates: " a short time pulse (TS) and " a long time pulse (TL), " in response to a set (ST) signal. " TS is to be used for timing yellow lights and TL for green lights Autumn 2014 CSE390C - VIII - Finite State Machines 2 17

Example: traffic light controller (cont d)! Tabulation of inputs and outputs inputs description outputs description reset place FSM in initial state HG, HY, HR assert green/yellow/red highway lights C detect vehicle on the farm road FG, FY, FR assert green/yellow/red highway lights inputs description outputs description ST start timing a short or long interval TS short time interval expired TL long time interval expired! Tabulation of unique states some light configurations imply others state description HG highway green (farm road red) HY highway yellow (farm road red) FG farm road green (highway red) FY farm road yellow (highway red) Autumn 2014 CSE390C - VIII - Finite State Machines 2 18

Add inputs/outputs to arcs! Inputs: C, TS, TL! Output: state and ST Reset HG HY FY FG Autumn 2014 CSE390C - VIII - Finite State Machines 2 19

Example: traffic light controller (cont d)! Completed state diagram (TL C)' Reset TL C / ST HG TS / ST TS' HY FY TS' TS / ST FG TL+C' / ST (TL+C')' Autumn 2014 CSE390C - VIII - Finite State Machines 2 20

Example: traffic light controller (cont )! Generate state table with symbolic states! Consider state assignments output encoding similar problem to state assignment (Green = 00, Yellow = 01, Red = 10) Inputs Present State Next State Outputs C TL TS ST H F 0 HG HG 0 Green Red 0 HG HG 0 Green Red 1 1 HG HY 1 Green Red 0 HY HY 0 Yellow Red 1 HY FG 1 Yellow Red 1 0 FG FG 0 Red Green 0 FG FY 1 Red Green 1 FG FY 1 Red Green 0 FY FY 0 Red Yellow 1 FY HG 1 Red Yellow SA1: HG = 00 HY = 01 FG = 11 FY = 10 SA2: HG = 00 HY = 10 FG = 01 FY = 11 SA3: HG = 0001 HY = 0010 FG = 0100 FY = 1000 (one-hot) SA4: HG = 001100 HY = 010100 FG = 100001 FY = 100010 (output-oriented) Autumn 2014 CSE390C - VIII - Finite State Machines 2 21

Logic for different state assignments! SA1 NS1 = C TL' PS1 PS0 + TS PS1' PS0 + TS PS1 PS0' + C' PS1 PS0 + TL PS1 PS0 NS0 = C TL PS1' PS0' + C TL' PS1 PS0 + PS1' PS0 ST = C TL PS1' PS0' + TS PS1' PS0 + TS PS1 PS0' + C' PS1 PS0 + TL PS1 PS0 H1 = PS1 H0 = PS1' PS0 F1 = PS1' F0 = PS1 PS0! SA2 NS1 = C TL PS1' + TS' PS1 + C' PS1' PS0 NS0 = TS PS1 PS0' + PS1' PS0 + TS' PS1 PS0 ST = C TL PS1' + C' PS1' PS0 + TS PS1 H1 = PS0 F1 = PS0' H0 = PS1 PS0' F0 = PS1 PS0! SA3 NS3 = C' PS2 + TL PS2 + TS' PS3 NS2 = TS PS1 + C TL' PS2 NS1 = C TL PS0 + TS' PS1 NS0 = C' PS0 + TL' PS0 + TS PS3 ST = C TL PS0 + TS PS1 + C' PS2 + TL PS2 + TS PS3 H1 = PS3 + PS2 H0 = PS1 F1 = PS1 + PS0 F0 = PS3! SA4 left as an exercise but this is the one we are going to go with Autumn 2014 CSE390C - VIII - Finite State Machines 2 22

Traffic light controller as two communicating FSMs! Without separate timer " S0 would require 7 states " S1 would require 3 states " S2 would require 7 states " S3 would require 3 states TS' S1 TS/ST S1a S1b " S1 and S3 have simple transformation " S0 and S2 would require many more arcs! C could change in any of seven states! By factoring out timer " greatly reduce number of states! 4 instead of 20 " counter only requires seven or eight states! 12 total instead of 20 ST traffic light controller TS S1c TL /ST timer Autumn 2014 CSE390C - VIII - Finite State Machines 2 23

Traffic light controller FSM! Specification of inputs, outputs, and state elements module FSM(HR, HY, HG, FR, FY, FG, ST, TS, TL, C, reset, clk); output HR, HY, HG; output FR, FY, FG; output ST; input TS, TL, C; input reset; input clk; reg [6:1] state; reg ST; parameter highwaygreen = 6'b001100; parameter highwayyellow = 6'b010100; parameter farmroadgreen = 6'b100001; parameter farmroadyellow = 6'b100010; assign HR = state[6]; assign HY = state[5]; assign HG = state[4]; assign FR = state[3]; assign FY = state[2]; assign FG = state[1]; specify state bits and codes for each state as well as connections to outputs Autumn 2014 CSE390C - VIII - Finite State Machines 2 24

Traffic light controller FSM (cont d) initial begin state = highwaygreen; ST = 0; end always @(posedge clk) begin if (reset) begin state = highwaygreen; ST = 1; end else begin ST = 0; case (state) highwaygreen: end endmodule case statement triggerred by clock edge if (TL & C) begin state = highwayyellow; ST = 1; end highwayyellow: if (TS) begin state = farmroadgreen; ST = 1; end farmroadgreen: if (TL!C) begin state = farmroadyellow; ST = 1; end farmroadyellow: if (TS) begin state = highwaygreen; ST = 1; end endcase end Autumn 2014 CSE390C - VIII - Finite State Machines 2 25

Timer for traffic light controller! Another FSM module Timer(TS, TL, ST, Clk); output TS; output TL; input ST; input Clk; integer value; assign TS = (value >= 4); // 5 cycles after reset assign TL = (value >= 14); // 15 cycles after reset always @(posedge Clk) if (ST) value = 0; else value = value + 1; endmodule Autumn 2014 CSE390C - VIII - Finite State Machines 2 26

Complete traffic light controller! Tying it all together (FSM + timer) " structural Verilog (same as a schematic drawing) module main(hr, HY, HG, FR, FY, FG, reset, C, clk); output HR, HY, HG, FR, FY, FG; input reset, C, clk; Timer part1(ts, TL, ST, clk); FSM part2(hr, HY, HG, FR, FY, FG, ST, TS, TL, C, reset, clk); endmodule traffic light controller ST timer TS TL Autumn 2014 CSE390C - VIII - Finite State Machines 2 27

Communicating finite state machines! One machine's output is another machine's input X FSM 1 FSM 2 Y CLK FSM1 X 4-cycle handshake A A B Y==0 A [1] B [0] Y==1 Y==0 X==0 X==1 C [0] [1] X==1 X==0 X==0 FSM2 Y C machines advance in lock step initial inputs/outputs: X = 0, Y = 0 Autumn 2014 CSE390C - VIII - Finite State Machines 2 28