Problem Set 5 Solutions

Similar documents
Summary of FPGA & VHDL

The University of Alabama in Huntsville Electrical and Computer Engineering CPE/EE 422/522 Spring 2005 Homework #6 Solution

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

CSE 260 Introduction to Digital Logic and Computer Design. Exam 1. Your name 2/13/2014

Timing in synchronous systems

VHDL in 1h. Martin Schöberl

6.111 Lecture # 8. Topics for Today: (as time permits)

In our case Dr. Johnson is setting the best practices

Sequential Logic - Module 5

DIGITAL LOGIC WITH VHDL (Fall 2013) Unit 6

The University of Alabama in Huntsville ECE Department CPE Midterm Exam Solution Spring 2016

VHDL Modeling Behavior from Synthesis Perspective -Part B - EL 310 Erkay Savaş Sabancı University

Sign here to give permission for your test to be returned in class, where others might see your score:

Problem Set 10 Solutions

Schedule. ECE U530 Digital Hardware Synthesis. Rest of Semester. Midterm Question 1a

DIGITAL LOGIC DESIGN VHDL Coding for FPGAs Unit 6

CSE 260 Introduction to Digital Logic and Computer Design. Exam 1 Solutions

The University of Alabama in Huntsville ECE Department CPE Midterm Exam Solution March 2, 2006

COVER SHEET: Total: Regrade Info: 5 (14 points) 7 (15 points) Midterm 1 Spring 2012 VERSION 1 UFID:

Lecture 5: State Machines, Arrays, Loops. EE 3610 Digital Systems

Lab 3. Advanced VHDL

Sequential Statement

Design Problem 4 Solutions

EEE8076. Reconfigurable Hardware Design (coursework) Module Outline. Dr A. Bystrov Dr. E.G. Chester. Autumn

The University of Alabama in Huntsville ECE Department CPE Final Exam Solution Spring 2004

Luleå University of Technology Kurskod SMD152 Datum Skrivtid

Two HDLs used today VHDL. Why VHDL? Introduction to Structured VLSI Design

Modeling Complex Behavior

CSE 260 Digital Computers: Organization and Logical Design. Exam 2. Jon Turner 3/28/2012

Sign here to give permission for your test to be returned in class, where others might see your score:

3 Designing Digital Systems with Algorithmic State Machine Charts

Counters. Counter Types. Variations. Modulo Gray Code BCD (Decimal) Decade Ring Johnson (twisted ring) LFSR

-- Fill in values for each generic. -- Fill in values for each signal. SIGNAL load_start : std_ulogic := '1'; SIGNAL clock : std_ulogic := '0';

VHDL. VHDL History. Why VHDL? Introduction to Structured VLSI Design. Very High Speed Integrated Circuit (VHSIC) Hardware Description Language

COE 405 Behavioral Descriptions in VHDL


Example 58: Traffic Lights

Lecture 08 Finite State Machine Design Using VHDL

Computer-Aided Digital System Design VHDL

COVER SHEET: Total: Regrade Info: 5 (5 points) 2 (8 points) 6 (10 points) 7b (13 points) 7c (13 points) 7d (13 points)

Hardware Description Languages. Modeling Complex Systems

[VARIABLE declaration] BEGIN. sequential statements

FINITE STATE MACHINES (FSM) DESCRIPTION IN VHDL. Cristian Sisterna UNSJ

CprE 583 Reconfigurable Computing

Control Unit: Binary Multiplier. Arturo Díaz-Pérez Departamento de Computación Laboratorio de Tecnologías de Información CINVESTAV-IPN

Synthesis from VHDL. Krzysztof Kuchcinski Department of Computer Science Lund Institute of Technology Sweden

Control and Datapath 8

8-1. Fig. 8-1 ASM Chart Elements 2001 Prentice Hall, Inc. M. Morris Mano & Charles R. Kime LOGIC AND COMPUTER DESIGN FUNDAMENTALS, 2e, Updated.

The block diagram representation is given below: The output equation of a 2x1 multiplexer is given below:

Finite State Machines (FSM) Description in VHDL. Review and Synthesis

EITF35: Introduction to Structured VLSI Design

Codec. WM8731 Audio Codec

Example 15: Moving Sprites with Flash Background

Altera s Avalon Communication Fabric

CprE 583 Reconfigurable Computing

CS/EE Homework 7 Solutions

HDL. Hardware Description Languages extensively used for:

Lecture 4: Modeling in VHDL (Continued ) EE 3610 Digital Systems

EITF35: Introduction to Structured VLSI Design

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

VHDL And Synthesis Review

VHDL for Logic Synthesis

EL 310 Hardware Description Languages Midterm

EITF35: Introduction to Structured VLSI Design

Concurrent & Sequential Stmts. (Review)

CS303 LOGIC DESIGN FINAL EXAM

Reconfigurable Hardware Design (coursework)

Introduction to Computer Design

VHDL: Code Structure. 1

Design Problem 5 Solutions

ECE 459/559 Secure & Trustworthy Computer Hardware Design

VHDL Testbench. Test Bench Syntax. VHDL Testbench Tutorial 1. Contents

Test Benches - Module 8

Digital System Construction

ECE 545 Lecture 11 Addendum

Nanosistemų programavimo kalbos 5 paskaita. Sekvencinių schemų projektavimas

6.111 Lecture # 11. Handshaking. Topics for today: Required when multiple lines of input are involved

COE Design Process Tutorial

ECEU530. Schedule. ECE U530 Digital Hardware Synthesis. Datapath for the Calculator (HW 5) HW 5 Datapath Entity

Lecture 12 VHDL Synthesis

Lecture 6. Digital Design Laboratory. Copyright 2007, 2009, 2010, 2014 Thomas R. Collins, Kevin Johnson

Constructing VHDL Models with CSA

ECE Digital Design Laboratory. Lecture 3 Finite State Machines!

Simplicity in the Design of a. Traffic Light Controller

SEQUENTIAL STATEMENTS

VHDL Examples Mohamed Zaky

The process. Sensitivity lists

Today. Comments about assignment Max 1/T (skew = 0) Max clock skew? Comments about assignment 3 ASICs and Programmable logic Others courses

VHDL for FPGA Design. by : Mohamed Samy

8 Register, Multiplexer and

The University of Alabama in Huntsville ECE Department CPE Midterm Exam February 26, 2003

Introduction to VHDL #1

Simulation with ModelSim Altera from Quartus II

Multiplication Simple Gradeschool Algorithm for 16 Bits (32 Bit Result)

Assignment. Last time. Last time. ECE 4514 Digital Design II. Back to the big picture. Back to the big picture

VHDL. ELEC 418 Advanced Digital Systems Dr. Ron Hayne. Images Courtesy of Cengage Learning

FSM$Modeling. Controller$Implementation

CSE 260 Digital Computers: Organization and Logical Design. Exam 2 Solutions

Quartus Counter Example. Last updated 9/6/18

Building Blocks. Entity Declaration. Entity Declaration with Generics. Architecture Body. entity entity_name is. entity register8 is

Transcription:

Problem Set 5 Solutions library ieee; use ieee.std_logic_1164.all; use work.std_arith.all; -- here is the declaration of entity entity la_rewarder is port (clk, go, SRAM_busy, SRAM_rdy: in std_logic; min: buffer std_logic_vector(2 downto 0); max: buffer std_logic_vector(2 downto 0); staff_hours_adr: out std_logic_vector(2 downto 0); staff_hours : in std_logic_vector(2 downto 0); minmax_start, minmax_done : buffer std_logic; timeoff : buffer std_logic_vector(3 downto 0); rdy : out std_logic); end la_rewarder; --the assumption is that the payroll module functions in such way to provide --a signal SRAM_busy to denote that it is updating the system and SRAM_rdy --when the data on the bus is valid (corresponding to the values stored at --staff_hours_adr). -- here is the body of the architecture architecture state_machine of la_rewarder is -- first declaration of all states type StateType is (idle,idle2, rew_la1, rew_la12, rew_la2, rew_la22, rew_la3, rew_la32, rew_la4, rew_la42, rew_finish); signal present_state, next_state : StateType; signal LA_points1 : std_logic_vector(1 downto 0); signal LA_points2 : std_logic_vector(1 downto 0); signal LA_points3 : std_logic_vector(1 downto 0); signal LA_points4 : std_logic_vector(1 downto 0); component maxmin port( clk, SRAM_busy, SRAM_rdy : in std_logic; minmax_start : buffer std_logic; min : buffer std_logic_vector(2 downto 0); max : buffer std_logic_vector(2 downto 0); staff_hours : in std_logic_vector(2 downto 0); minmax_done : buffer std_logic); end component; process(present_state, clk, min, max, SRAM_busy, go, timeoff, LA_points1, LA_points2, LA_points3, LA_points4, SRAM_rdy, minmax_done,min, max, staff_hours) --start off with timeoff being zero for all LA's -- start off with the output not calculated minmax_start <= '0'; case present_state is when idle => -- in idle, no LA gets time off

--in idle, any address is asserted --the timeoff is not calculated yet minmax_start <= '0'; if (SRAM_busy = '1') then --SRAM_busy means that the payroll is updating the SRAM table --of weekly hours elsif (minmax_done = '0' and go <= '1') then --this is the state where the payroll has updated --the records, but the minor fsm --has not calculated the new min and max values; --min and max values have to be --calculated after each payroll update. minmax_start <= '1'; start signal that the next_state <= idle2; minmax to calculate min and at this point --the major fsm asserts the --minor fsm uses to see when it needs --to perform the next calculation. --next_state = wait for --max values no output is ready elsif (minmax_done = '1' and go = '1') then --this is the state when the payroll has finished --updating the records and the --minmax has finished calculating the min and max next_state <= rew_la1; --values next state checks the first LA's points, --LA corresponds to 011 in the table staff_hours_adr <= "011"; minmax_start <= '0'; --safe bet to play is that if we are getting anything -- to return to the idle --state when idle2 => for the minor minmax minmax_start <= '1'; if(minmax_done = '0') then --fsm --this is the sate where we wait

next_state <= idle2; next_state <= rew_la1; next state and check the staff_hours_adr <= "011"; minmax_start <= '0'; for is 011 --minmax is done - go to the --LA points for the first LA --the LA we are checking when rew_la1 => staff_hours_adr <= "011"; minmax_start <= '0'; if (SRAM_rdy = '0') then interface and use asserted on the bus staff_hours_adr <= "011"; next_state <= rew_la1; next_state <= rew_la12; staff_hours_adr <= "011"; --we abstract from the SRAM --SRAM_rdy signal to denote when --the valid data (or LA hours) is when rew_la12 => if(la_points1 = 11) then --if the LA has accumulated 3 points (highly unlikely ;) ) --then he gets time --off. For LA1 that means asserting bit0 or equivalently --adding 1 to the timeoff --value. --reminder - it is possible that an LA will lose a point --at LA_points = 3 timeoff <= timeoff+1; --reminder - to keep things simple, it is possible that --an LA will miss LA_points1 <= "00"; --we reset his points to zero next_state <= rew_la2; --transition into the next state and check LA2 elsif (staff_hours < min) then --if the LA has not worked the required hours (very likely), LA_points1 <= LA_points1-1; change because he does not --then he loses a --point in his LA_points vector --the timeoff value does not

next_state <= rew_la2; elsif (staff_hours > max) then predicted (never happens :) ) LA_points1 <= LA_points1+1; it was when we entered of points next_state <= rew_la2; LA_points1 <= LA_points1; the points and timeoff timeoff<= timeoff; next_state <= rew_la2; --have enough poitns --if he worked harder than --then he gets a point --in his LA_points vector --the timeoff value remains what --the state, because the --LA didn't have a sufficient amount --if he worked just enough, then --do not change. when rew_la2 => --we move to the next LA staff_hours_adr <= "100"; --his adress is 100 if (SRAM_rdy = '0') then --wait until the hours are on the bus staff_hours_adr <= "100"; next_state <= rew_la2; --if the SRAM values aren't ready, remain in the state next_state <= rew_la22; --otherwise transition into the next state to compare --the obtained values when rew_la22 => if(la_points2 = 11) then --if he has accumulated 3 points, reward him by giving --him some time off timeoff <= timeoff+2; --for LA2 this is done by incrementing timeoff by 2. LA_points2 <= "00"; --set his points to 00 for the next cycle; again he may against the max value next_state <= rew_la3; LA3 elsif (staff_hours < min) then he loses a point --lose a point b/c --we chose not to check his hours --go and check the values for --if he didn't work enough then

LA_points2 <= LA_points2-1; next_state <= rew_la3; elsif (staff_hours > max) then LA_points2 <= LA_points2 + 1; next_state <= rew_la3; LA_points2 <= LA_points2; timeoff<= timeoff; next_state <= rew_la3; --and doesn't get any time off --we go to the next LA when rew_la3 => staff_hours_adr <= "101"; if (SRAM_rdy = '0') then staff_hours_adr <= "101"; next_state <= rew_la3; next_state <= rew_la32; when rew_la32 => if(la_points3 = 11) then timeoff <= timeoff+4; LA_points3 <= "00"; next_state <= rew_la4; elsif (staff_hours < min) then LA_points3 <= LA_points3-1; next_state <= rew_la4; elsif (staff_hours > max) then LA_points3 <= LA_points3 + 1; next_state <= rew_la4; LA_points3 <= LA_points3; timeoff<= timeoff; next_state <= rew_la4; when rew_la4 => staff_hours_adr <= "110";

if (SRAM_rdy = '0') then staff_hours_adr <= "110"; next_state <= rew_la4; next_state <= rew_la42; when rew_la42 => if(la_points4 = 11) then timeoff <= timeoff+8; LA_points4 <= "00"; next_state <= rew_finish; elsif (staff_hours < min) then LA_points4 <= LA_points4-1; next_state <= rew_finish; elsif (staff_hours > max) then LA_points4 <= LA_points4 + 1; next_state <= rew_finish; LA_points4 <= LA_points4; timeoff<= timeoff; next_state <= rew_finish; when rew_finish => the timeoff value is the weekly --in this state we assert rdy to be high, --remains at the --same value as it was in the previous state and --constantly asserted. --we stay in this state until the payroll updates --hours table, --at which point, our timeoff value needs to be calculated again. rdy <= '1'; if (SRAM_busy = '0') then next_state <= rew_finish; when others => end case; end process;

process(clk, present_state, next_state, SRAM_busy) if rising_edge(clk) then if(sram_busy = '1') then present_state <= idle; --SRAM_busy means that the payroll is updating the staff --weekly hours table, --which automatically means that the current min and max --are no longer valid --the fsm should return to idle and wait until the payroll --is done updating present_state <= next_state; end process; instmaxmin : maxmin port map ( clk => clk, minmax_start =>minmax_start, SRAM_busy => SRAM_busy, SRAM_rdy => SRAM_rdy, min => min, max => max, staff_hours => staff_hours, minmax_done => minmax_done); end architecture state_machine; library ieee; use ieee.std_logic_1164.all; use work.std_arith.all; -- here is the declaration of entity entity maxmin is port (clk, SRAM_busy, SRAM_rdy : in std_logic; minmax_start, minmax_done : buffer std_logic; min : buffer std_logic_vector(2 downto 0); max : buffer std_logic_vector(2 downto 0); staff_hours : in std_logic_vector(2 downto 0)); end maxmin; architecture state_machine of maxmin is -- first declaration of all states type StateType is (idle,read_ta1, read_ta12, read_ta2, read_ta22, read_ta3, read_ta32, finish);

signal staff_hrs_adr : std_logic_vector(2 downto 0); signal present_state, next_state : StateType; process(present_state, clk, minmax_start, staff_hours, min, max, staff_hours, SRAM_busy, SRAM_rdy) min <="000"; max <= "111"; case present_state is when idle => min <= "000"; max <= "111"; if(minmax_start = '1') then staff_hrs_adr <= "000"; min<="111"; max<="000"; next_state <= read_ta1; when read_ta1 => min <= "111"; max <= "000"; staff_hrs_adr <= "000"; if(sram_rdy = '1') then next_state <= read_ta12; next_state <= read_ta1; min <= "111"; max <= "000"; when read_ta12 => min <= staff_hours; max <= staff_hours; next_state <= read_ta2; when read_ta2 => staff_hrs_adr <= "001"; if(sram_rdy = '1') then next_state <= read_ta22;

next_state <= read_ta2; when read_ta22 => if(staff_hours < min) then min <= staff_hours; next_state <= read_ta3; elsif(staff_hours > max) then max <= staff_hours; next_state <= read_ta3; next_state <= read_ta3; when read_ta3 => staff_hrs_adr <= "010"; if(sram_rdy = '1') then next_state <= read_ta32; next_state <= read_ta3; when read_ta32 => if(staff_hours < min) then min <= staff_hours; minmax_done <= '1'; next_state <= finish; elsif(staff_hours > max) then max <= staff_hours; minmax_done <= '1'; next_state <= finish; minmax_done <= '1';

next_state <= finish; when finish => minmax_done <= '1'; if(sram_busy = '0') then next_state <= finish; minmax_done <= '1'; when others => end case; end process; process(clk, present_state, next_state, SRAM_busy) if rising_edge(clk) then if (SRAM_busy = '0') then present_state <= next_state; present_state <= idle; end process; end architecture state_machine;