DIGITAL LOGIC DESIGN VHDL Coding for FPGAs Unit 3

Similar documents
DIGITAL LOGIC WITH VHDL (Fall 2013) Unit 3

DIGITAL LOGIC WITH VHDL (Fall 2013) Unit 2

ELCT 501: Digital System Design

Digital Systems Design

DIGITAL LOGIC DESIGN VHDL Coding for FPGAs Unit 6

Contents. Appendix D VHDL Summary Page 1 of 23

DIGITAL LOGIC WITH VHDL (Fall 2013) Unit 6

Chapter 6 Combinational-Circuit Building Blocks

Lecture 12 VHDL Synthesis

Introduction to VHDL #3

!"#$%&&"'(')"*+"%,%-".#"'/"'.001$$"

ECE 545 Lecture 5. Data Flow Modeling in VHDL. George Mason University

ECE 448 Lecture 3. Combinational-Circuit Building Blocks. Data Flow Modeling of Combinational Logic

ECE 448 Lecture 3. Combinational-Circuit Building Blocks. Data Flow Modeling of Combinational Logic

VHDL for Synthesis. Course Description. Course Duration. Goals

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

IT T35 Digital system desigm y - ii /s - iii

5. 0 VHDL OPERATORS. The above classes are arranged in increasing priority when parentheses are not used.

Introduction to VHDL #1

Lecture 1: VHDL Quick Start. Digital Systems Design. Fall 10, Dec 17 Lecture 1 1

EEL 4783: Hardware/Software Co-design with FPGAs

Department of Technical Education DIPLOMA COURSE IN ELECTRONICS AND COMMUNICATION ENGINEERING. Fifth Semester. Subject: VHDL Programming

Written exam for IE1204/5 Digital Design Thursday 29/

Very High Speed Integrated Circuit Har dware Description Language

VHDL for FPGA Design. by : Mohamed Samy

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

Lattice VHDL Training

Lecture 7. Standard ICs FPGA (Field Programmable Gate Array) VHDL (Very-high-speed integrated circuits. Hardware Description Language)

Lecture 3: Modeling in VHDL. EE 3610 Digital Systems

HDL. Hardware Description Languages extensively used for:

Multi-valued Logic. Standard Logic IEEE 1164 Type std_ulogic is ( U, uninitialized

Hardware Description Language VHDL (1) Introduction

Hardware Modeling. VHDL Syntax. Vienna University of Technology Department of Computer Engineering ECS Group

Part 4: VHDL for sequential circuits. Introduction to Modeling and Verification of Digital Systems. Memory elements. Sequential circuits

VHDL 2 Combinational Logic Circuits. Reference: Roth/John Text: Chapter 2

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

HDLs and SystemVerilog. Digital Computer Design

Computer-Aided Digital System Design VHDL

Nanosistemų programavimo kalbos 4 paskaita. Nuosekliai vykdomi sakiniai

EITF35: Introduction to Structured VLSI Design

VHDL: RTL Synthesis Basics. 1 of 59

CSCI Lab 3. VHDL Syntax. Due: Tuesday, week6 Submit to: \\fs2\csci250\lab-3\

Abi Farsoni, Department of Nuclear Engineering and Radiation Health Physics, Oregon State University

Control and Datapath 8

Experiment 0 OR3 Gate ECE 332 Section 000 Dr. Ron Hayne June 8, 2003

[VARIABLE declaration] BEGIN. sequential statements

Sequential Statements

ECE 545 Lecture 8. Data Flow Description of Combinational-Circuit Building Blocks. George Mason University

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

Logic and Computer Design Fundamentals VHDL. Part 1 Chapter 4 Basics and Constructs

DIGITAL LOGIC WITH VHDL (Fall 2013) Unit 1

Lab 3: Standard Combinational Components

SRI SUKHMANI INSTITUTE OF ENGINEERING AND TECHNOLOGY, DERA BASSI (MOHALI)

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

DIGITAL LOGIC DESIGN VHDL Coding for FPGAs

VHDL. Official Definition: VHSIC Hardware Description Language VHISC Very High Speed Integrated Circuit

CPE 626 Advanced VLSI Design Lecture 6: VHDL Synthesis. Register File: An Example. Register File: An Example (cont d) Aleksandar Milenkovic

ACS College of Engineering. Department of Biomedical Engineering. Logic Design Lab pre lab questions ( ) Cycle-1

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

Solutions - Homework 2 (Due date: October 9:30 am) Presentation and clarity are very important!

CS211 Digital Systems/Lab. Introduction to VHDL. Hyotaek Shim, Computer Architecture Laboratory

קורס VHDL for High Performance. VHDL

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

Constructing VHDL Models with CSA

Lecture 4. VHDL Fundamentals. George Mason University

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

EITF35: Introduction to Structured VLSI Design

Luleå University of Technology Kurskod SMD152 Datum Skrivtid

UNIT I Introduction to VHDL VHDL: - V -VHSIC, H - Hardware, D - Description, L Language Fundamental section of a basic VHDL code Library :

Inferring Storage Elements

Department of Electronics & Communication Engineering Lab Manual E-CAD Lab

VHDL And Synthesis Review

VHDL in 1h. Martin Schöberl

3 Designing Digital Systems with Algorithmic State Machine Charts

ENGIN 241 Digital Systems with Lab

CDA 4253 FPGA System Design VHDL Testbench Development. Hao Zheng Comp. Sci & Eng USF

Assignment 01 Computer Architecture Lab ECSE

CMPT 250: Computer Architecture. Using LogicWorks 5. Tutorial Part 1. Somsubhra Sharangi

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

Introduction to VHDL. Main language concepts

Mid-Term Exam Solutions

C-Based Hardware Design

VHDL. Chapter 7. Behavioral Modeling. Outline. Behavioral Modeling. Process Statement

Lecture 4. VHDL Fundamentals. Required reading. Example: NAND Gate. Design Entity. Example VHDL Code. Design Entity

ECE 448 Lecture 4. Sequential-Circuit Building Blocks. Mixing Description Styles

EL 310 Hardware Description Languages Midterm

Review of Digital Design with VHDL

VHDL 3 BASIC OPERATORS AND ARCHITECTURE BODY. Design descriptions & design constructions examples are taken from foundation series examples

DESCRIPTION OF DIGITAL CIRCUITS USING VHDL

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

Outline. CPE/EE 422/522 Advanced Logic Design L05. Review: General Model of Moore Sequential Machine. Review: Mealy Sequential Networks.

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

Sequential Statement

Chapter 2 Basic Logic Circuits and VHDL Description

Digital Design with SystemVerilog

JUNE, JULY 2013 Fundamentals of HDL (10EC45) PART A

VHDL simulation and synthesis

Hardware Description Languages. Modeling Complex Systems

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

ECE 545 Lecture 6. Behavioral Modeling of Sequential-Circuit Building Blocks. George Mason University

Transcription:

DIGITAL LOGIC DESIGN VHDL Coding for FPGAs Unit 3 BEHAVIORAL DESCRIPTION Asynchronous processes (decoder, mux, encoder, etc): if-else, case, for-loop. Arithmetic expressions inside asynchronous processes.

BEHAVIORAL DESCRIPTION (OR SEQUENTIAL) In this design style, the circuit is described via a series of statements (also called sequential statements) that are executed one after other; here the order is very important. This feature is advantageous when it comes to implement sequential circuits. The sequential statements must be within a block of VHDL code called process. The sequential code suits the description of sequential circuits very well. However, we can also describe combinatorial circuits with sequential statements. Here we will use the sequential description style to implement combinatorial circuits. In this instance, the block of VHDL code ( process ) is called asynchronous process.

ASYNCHRONOUS PROCESSES (Implementation of combinatorial circuits with sequential statements) Below we show the syntax of a sequential description. Note that the process statement denotes the sequential block. Beginning of process block End of process block entity example is port (......); end example; architecture behav of example is process (signal_1, signal_2,...)......... Sequential Statements end behav; Sensitivy list (all the signals used inside the process)

SEQUENTIAL STATEMENTS: IF Statement: Simple Conditional Example: AND gate. The sensitivity list is made of a and b. We can use any other gate: OR, NOR, NAND, XOR, XNOR. It is a good coding practice to include all the signals used inside the process in the sensitivity list. Xilinx Synthesizer: DO NOT omit any signal in the sensitivity list, otherwise the Behavioral Simulation (isim) will be incorrect. This is usually not a problem for other Synthesizers. entity my_and is port ( a, b: in std_logic; f: out std_logic); end my_and; a b f architecture behav of my_and is process (a,b) if (a = '1') and (b = '1') then f <= '1'; else f <= '0'; end behav;

IF Statement: Example: 2-to-1 Multiplexor: Three different coding styles: a b 0 1 y entity my_mux21 is port ( a, b, s: in std_logic; y: out std_logic); end my_mux21; architecture st of my_mux21 is y <= (not(s) and a) or (s and b); end st; architecture st of my_mux21 is with s select y <= a when '0', b when others; end st; s y = sa + sb architecture st of my_mux21 is process (a,b,s) if s = '0' then y <= a; else y <= b; end st;

IF Statement: Example: 4-to-1 Multiplexor Two different styles: entity my_mux41 is port ( a,b,c,d: in std_logic; s: in std_logic_vector (1 downto 0); y: out std_logic); end my_mux41; a b c d 0 1 2 3 2 s y architecture st of my_mux41 is with s select y <= a when "00", b when "01", c when "10", d when "11", '-' when others; end st; architecture st of my_mux41 is process (a,b,c,d,s) if s = "00" then y <= a; elsif s = "01" then y <= b; elsif s = "10" then y <= c; else y <= d; end st;

IF Statement Example: 4-to-2 priority encoder w3 w2 w1 w0 w 3 0 1 0 0 0 PRIORITY ENCODER y1 y0 z w 2 w 1 w 0 y 1 y 0 z 0 0 x x 1 x 0 1 0 x x x 0 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 0 1 The priority level is implicit by having w(3) in the first if, and w(2) in the second if, and so on. entity my_prienc is port ( w: in std_logic_vector (3 downto 0); y: out std_logic_vector (1 downto 0); z: out std_logic); end my_prienc; architecture bhv of my_prienc is process (w) if w(3) = '1' then y <= "11"; elsif w(2) = '1' then y <= "10; elsif w(1) = '1' then y <= "01"; else y <= "00"; if w = "0000" then z <= '0'; else z <= '1'; end bhv;

IF Statement Example: 4-to-2 priority encoder (another style) Process: Statements are executed (the way the synthesizer reads it) one after the other. The first statement assigns y <= 00. Then the value of y changes ONLY if the conditions are met for the input w. Note the order: w(1), w(2), w(3). This establishes a priority for w(3) (last statement to be executed). z starts with 1, but if the condition is met, it is changed to 0. entity my_tprienc is port ( w: in std_logic_vector (3 downto 0); y: out std_logic_vector (1 downto 0); z: out std_logic); end my_tprienc; architecture bhv of my_tprienc is process (w) y <= "00"; if w(1) = '1' then y <= "01"; if w(2) = '1' then y <= "10"; if w(3) = '1' then y <= "11"; z <= '1'; if w = "0000" then z <= '0'; end bhv;

IF Statement: Example: 4-bit comparator use ieee.std_logic_unsigned.all; -- unsigned #s entity my_comp is port ( A,B: in std_logic_vector (3 downto 0); y: out std_logic); end my_comp; architecture struct of my_comp is y <= '1' when A = B else '0'; end struct; A 3 B 3 A 2 B 2 A 1 B 1 y A B COMPA- RATOR A = B? architecture behav of my_comp is process (a,b) if (A = B) then y <= '1'; else y <= '0'; end behav; y A 0 B 0

IF Statement: Example of bad design : 4-bits comparator, but the else is omitted: Warning! If a b y =? Since we did not specify what happens when a b, the synthesizer assumes that we want to keep the last value of y. In the circuit, initially y will be 0. But: If a = b y = 1 forever. It is said that the output has an implicit memory since it remembers the previous value of y. This results in a faulty comparator. use ieee.std_logic_unsigned.all; -- unsigned #s entity my_comp is port ( A,B: in std_logic_vector (3 downto 0); y: out std_logic); end my_comp; architecture behav of my_comp is process (a,b) The synthesized circuit if (A = B) then would look like this: A y <= '1'; 3 B 3 A 2 B end behav; 2 A 1 B 1 A 0 B 0 y

RULES FOR A GOOD COMBINATORIAL DESIGN USING PROCESSES Rule 1: EVERY input signal that is used within the process must appear in the sensitivy list. Rule 2: ALL the possible Input/Output combinations must be specified. Otherwise, we will find issues with implicit memory.. architecture behav of my_comp is process (a,b) if (A = B) then y <= '1'; else y <= '0'; end behav; architecture behav of my_comp is process (a,b) The case 'A B' is never specified if (A = B) then y <= '1'; end behav;

IF Statement. Example: Majority gate Triple Modular Redundancy: To improve reliability, a system is replicated three times. The 3 generated outputs go into a majorityvoting system (majority gate) to produce a single output. If at least two replicas produce identical outputs the majority gate selects that output. If the three replicas produce different results, the majority gate asserts an error flag (y_error = 1 ) N N N System replica 1 System replica 2 System replica 3 N N N Majority gate N entity my_maj_gate is generic (N: INTEGER:= 8); port (A,B,C: in std_logic_vector(n-1 downto 0); f: out std_logic_vector(n-1 downto 0); y_err: out std_logic); end my_maj_gate; architecture bhv of my_maj_gate is process (A,B,C) y_err <= '0'; if (A = B) then f <= A; if (A = C) then f <= A; if (B = C) then f <= B; if (A/=B) and (B/=C) and (A/=C) then y_error f <= (others => '0'); y_err <= '1'; end bhv; my_maj_gate.zip: my_maj_gate.vhd, tb_ my_maj_gate.vhd

SEQUENTIAL STATEMENTS: CASE statement It is used in multi-decision cases when nested IF s become complex. All possible choices must be included (see the keyword when for every choice of the selection signal ) Last case: We must use when others (even if all the 0/1s, as std_logic has 9 possible values). This also avoids outputs with implicit memory. Example: MUX 8-to-1 entity my_mux8to1 is port ( a,b,c,d,e,f,g,h: in std_logic; s: in std_logic_vector (2 downto 0); y: out std_logic); end my_mux8to1; architecture bhv of my_mux8to1 is process (a,b,c,d,e,f,g,h,s) case s is when "000" => y <= a; when "001" => y <= b; when "010" => y <= c; when "011" => y <= d; when "100" => y <= e; when "101" => y <= f; when "110" => y <= g; when others => y <= h; end case; end bhv; a b c d e f g h 0 1 2 3 4 5 6 7 s 3 y

CASE Statement: Example: MUX 7-to-1 entity my_mux7to1 is Note: y <= - (don t care). port ( a,b,c,d,e,f,g: in std_logic; This allows the synthesizer to s: in std_logic_vector (2 downto 0); optimize the circuit. y: out std_logic); end my_mux7to1; If, however, we had used when others => y <= g; The synthesizer would have assigned the value g for the cases 110 and 111 (a slighty less optimal circuit). architecture bhv of my_mux7to1 is process (a,b,c,d,e,f,g,s) case s is when "000" => y <= a; when "001" => y <= b; when "010" => y <= c; when "011" => y <= d; when "100" => y <= e; when "101" => y <= f; when "110" => y <= g; -- when others => y <= g; when "111" => y <= g; when "110" => y <= g; when others => y <= '-'; end case; end bhv;

CASE Statement: Example: Binary to gray decoder It could also be described using the with-select statement (no process) b 2 b 1 b 0 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 g 2 g 1 g 0 0 0 0 0 0 1 0 1 1 0 1 0 1 1 0 1 1 1 1 0 1 1 0 0 entity my_gray2bin is port ( B: in std_logic_vector(2 downto 0); G: in std_logic_vector(2 downto 0)); end my_gray2bin; architecture bhv of my_gray2bin is process (B) case B is when "000" => G <= "000"; when "001" => G <= "001"; when "010" => G <= "011"; when "011" => G <= "010"; when "100" => G <= "110"; when "101" => G <= "111"; when "110" => G <= "101"; when others => G <= "100"; end case; end bhv;

CASE statement Example: 7-segment decoder. We use the don t care value ( - ) to optimize the circuit, since we only expect inputs from 0000 to 1111. Note that the CASE statement avoids the output with implicit memory, since the when others clause makes sure that the remaining cases are assigned. entity my_7segdec is port ( bcd: in std_logic_vector(3 downto 0); leds: out std_logic_vector(6 downto 0)); end my_7segdec; architecture bhv of my_7segdec is process (bcd) case bcd is -- abcdefg when "0000" => leds <= "1111110"; when "0001" => leds <= "0110000"; when "0010" => leds <= "1101101"; when "0011" => leds <= "1111001"; when "0100" => leds <= "0110011"; when "0101" => leds <= "1011011"; when "0110" => leds <= "1011111"; when "0111" => leds <= "1110000"; when "1000" => leds <= "1111111"; when "1001" => leds <= "1111011"; when others => leds <= "-------"; end case; end bhv;

CASE Statement: Example: 2-to-4 decoder with enable. Note how we combine IF with CASE for this decoder with enable. The else cannot be omitted, otherwise the output will have implicit memory (it will be a LATCH) w E 2 DECODER Example: 2-to-4 decoder (3 styles): 4 mydec2to4.zip: mydec2to4.vhd, tb_mydec2to4.vhd, mydec2to4.ucf y entity my_dec2to4 is port ( w: in std_logic_vector(1 downto 0); y: out std_logic_vector(3 downto 0); E: in std_logic); end my_dec2to4; architecture bhv of my_dec2to4 is process (w,e) if E = '1' then case w is when "00" => y <= "0001"; when "01" => y <= "0010"; when "10" => y <= "0100"; when others => y <= "1000"; end case; else y <= "0000"; end bhv;

FOR-LOOP statement Very useful for sequential circuit description. But, it can also be used to describe some combinatorial circuits. Example: Signextension (from 4 bits to 8 bits) entity my_signext is port ( A: in std_logic_vector(3 downto 0); y: out std_logic_vector(7 downto 0)); end my_signext; architecture bhv of my_signext is b 3 b 2 b 1 b 0 process(a) 4 y(3 downto 0) <= A; for i in 7 downto 4 loop signextender y(i) <= A(3); end loop; end bhv; 8 b 3 b 3 b 3 b 3 b 3 b 2 b 1 b 0

in_data all_ones in_data FOR-LOOP statement Example: Ones/zeros detector: It detects whether the input contains only 0 s or only 1 s. Input length: Parameter N. This is a rare instance where using process for combinational circuits is the most efficient description. Variable inside a process: it helps to describe this circuit. Depending on the implementation, a variable could be a wire....... entity zeros_ones_det is generic (N: INTEGER:= 8); port (in_data: in std_logic_vector(n-1 downto 0); all_zeros, all_ones: out std_logic); end zeros_ones_det; architecture bhv of zeros_ones_det is process(in_data) variable result_and, result_or: std_logic; result_and:= '1'; result_or:= '0'; for i in in_data'range loop result_and:= result_and and in_data(i); result_or:= result_or or in_data(i); end loop; all_zeros <= not(result_or); all_ones <= result_and; end bhv; zeros_ones_detector.zip: all_zeros zeros_ones_detector.vhd, tb_zeros_ones_detector.vhd, zeros_ones_detector.ucf

ARITHMETIC EXPRESSIONS We can use the operators +, -, and * inside behavioral processes. We can also use the comparison statements (>,<,=,>=,<=). Example: Absolute value of A-B. A and B are unsigned integers. use ieee.std_logic_unsigned.all; Input length: Parameter N. For signed numbers, you must first must sign extend the operands A and B; the result will have an extra bit. entity my_uabs_diff is generic (N: INTEGER:= 4); port ( A,B: in std_logic_vector(n-1 downto 0); R: out std_logic_vector(n-1 downto 0)); end my_uabs_diff; architecture bhv of my_uabs_diff is process (A,B) if A >= B then R <= A - B; else R <= B - A; end bhv; my_uabs_diff.zip: my_uabs_diff.vhd, tb_my_uabs_diff.vhd