vhdlprg

64
CS2204 CS2204 CS2204 CS2204 Digital Logic Digital Logic and and and and State Machine Design State Machine Design VHDL Programming Vijay Vijay Polavarapu Polavarapu Fall 2012 Fall 2012

description

programme of vhdl.

Transcript of vhdlprg

Page 1: vhdlprg

CS2204CS2204CS2204CS2204Digital LogicDigital Logic

andandandandState Machine DesignState Machine Design

VHDL ProgrammingVijay Vijay PolavarapuPolavarapu

Fall 2012Fall 2012

Page 2: vhdlprg

VHDL PROGRAMMING 2

Agenda• Introduction • VHDL Review (Page #3-19)

M d li t l i VHDL ith l• Modeling styles in VHDL with examples (Page #20-28)• Constructs in VHDLConcurrent (Page #29-48)Sequential (Page #49-55)

• Think Hardware? (Page #56-57)• Examples of Behavioral coding (Page #58-63)Examples of Behavioral coding (Page #58-63)• Conclusions (Page #64)

A k l d tAcknowledgements• Prof. Haldun Hadimioglu• John Wakerly, Cisco Systems, Stanford University

CS 2204 Digital Logic and State Machine DesignFall 2012

• System Design using VHDL-Charles H. Roth

Page 3: vhdlprg

VHDL PROGRAMMING 3

VHDLVHDL Revisited

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 4: vhdlprg

VHDL PROGRAMMING 4

Wh HDL ?Why HDLs?

I ft thi i ti l• In software everything is sequential • Sequence of statements is significant, since they are executed in

that order• In hardware events are concurrent, so a software language cannot

be used for describing and simulating hardware.

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 5: vhdlprg

VHDL PROGRAMMING 5

e.g. C = (not (X) and Y) or (not (X))

1 -> 0 A 0 -> 1X CX C

Y BY B

Different outputs with software programming languages with ‘0’ initial values

Case 1A = not X

Case 2B = A and Y

Case 3C = A or B

with ‘0’ initial values

A not XB = A and YC = A or BResult:

B A and YC = A or BA = not XResult:

C A or BA = not XB = A and YResult:

CS 2204 Digital Logic and State Machine DesignFall 2012

C = 1 C = 0 C = 0

Page 6: vhdlprg

VHDL PROGRAMMING 6

Features of HDLsFeatures of HDLs

• Concurrent Descriptions• Synchronizing mechanisms between concurrent flows • Event Scheduling• Special object types and data types p j yp yp• Hierarchy

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 7: vhdlprg

VHDL PROGRAMMING 7

HDL Implementation Design CycleCycle

DESIGN ENTRY

Schematic , VHDL, Verilog,Schematic , VHDL, Verilog, etc.

Functional SimulationIP cores

SYNTHESIS

Test insertion

Static Timing Analysis

IP cores

Test insertionGate level simulation

LIBRARIES

Post layout simulation

Implementation

MAP, PLACE , ROUTE

Static Timing Analysis

CS 2204 Digital Logic and State Machine DesignFall 2012

Post layout simulation ROUTE

Page 8: vhdlprg

VHDL PROGRAMMING 8

Advantages of using Hardware Description LanguagesAdvantages of using Hardware Description Languages

• Designs can be described at various levels of abstractions

• Top-Down Approach and hierarchical designs for large projects

• Functional Simulation Early in the Design Flow

• Automatic Conversion of HDL Code to GatesWith user level control. Consistent quality. Fast.

• Early Testing of Various Design ImplementationsDue to fast synthesis, there is a scope for trying different implementations.

Design Reuse• Design ReuseTechnology independence, standardization, portability, ease of maintenance.

All these result in low risk, high convergence, fast time to market, more

CS 2204 Digital Logic and State Machine DesignFall 2012

money.

Page 9: vhdlprg

VHDL PROGRAMMING 9

A Brief History Of VHDLA Brief History Of VHDL

• VHDL stands for Very high speed integrated circuit HardwareVHDL stands for Very high speed integrated circuit Hardware Description Language

• Funded by the US Department of Defense in the 80's

• Originally meant for design standardisation, documentation, simulation and ease of maintenance.

• Established as IEEE standard IEEE 1076 in 1987. An updated standard, IEEE 1164 was adopted in 1993. In 1996 IEEE 1076.3 became a VHDL synthesis standard.y

• Today VHDL is widely used across the industry for design description, simulation and synthesis.

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 10: vhdlprg

VHDL PROGRAMMING 10

About VHDL

• VHDL is not case sensitive• VHDL is a free form language. You can write the whole program on

i l lia single line.

-- This is a VHDL commententity my_exor is -- one more commentbegin...end my_exor;

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 11: vhdlprg

VHDL PROGRAMMING 11

my EXOR gate-- This is my first VHDL program

library IEEE;use IEEE std logic 1164 all; tit d l ti d ib thuse IEEE.std_logic_1164.all;

entity my_exor isport (ip1 : in std_logic;

ip2 : in std logic;

entity declaration - describes the boundaries of the object.It defines the names of the ports, theirmode and their type.ip2 : in std_logic;

op1 : out std_logic);

end my_exor;

yp

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 12: vhdlprg

VHDL PROGRAMMING 12

my EXOR gatelibrary IEEE;use IEEE.std_logic_1164.all;

entity my exor is entity - defines theentity my_exor isport (ip1 : in std_logic;

ip2 : in std_logic;op1 : out std_logic

);

yinterface.

Mode of the port :);end my_exor;

Mode of the port : Direction of flow. It can be in, out or inout

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 13: vhdlprg

VHDL PROGRAMMING 13

my EXOR gatelibrary IEEE;use IEEE.std_logic_1164.all;

entity my exor is entity - defines theentity my_exor isport (ip1 : in std_logic;

ip2 : in std_logic;op1 : out std_logic

);

entity defines theinterface.

td l i i th t f th);end my_exor; Mode of the port :

It can be in, out or inout

std_logic is the type of the port.Standard logic is defined by the standardby the standard IEEE 1164.It is defined in the IEEE library.An node of t pe std logicAny node of type std_logic can take 9 different values.‘0’ , ’1’ , ’H’ , ’L’ , ’Z’ , ’U’ , ’X’ , ’W’ , ’-’

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 14: vhdlprg

VHDL PROGRAMMING 14

my EXOR gate library IEEE;use IEEE.std_logic_1164.all;

entity my exor is

Library : Collection of design elements, type declarations, sub programs, etc.

entity my_exor isport (ip1 : in std_logic;

ip2 : in std_logic;op1 : out std_logic

););end my_exor;

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 15: vhdlprg

VHDL PROGRAMMING 15

Library : Collection of design my EXOR gatelibrary IEEE;use IEEE.std_logic_1164.all;

entity my exor is

elements, type declarations,sub programs, etc.

entity - defines theentity my_exor isport (ip1 : in std_logic;

ip2 : in std_logic;op1 : out std_logic

);

entity defines theinterface.

std_logic is the type of the portIt is defined in the IEEE library);

end my_exor;

architecture my exor beh of my exor is

Mode of the port :It can be in, out or inout

It is defined in the IEEE library.Any node of type std_logic can take9 different values.‘0’ , ’1’ , ’H’ , ’L’ , ’Z’ , ’U’ , ’X’ , ’W’ , ’-’

architecture my_exor_beh of my_exor isbeginop1 <= (ip1 and (not ip2)) or

(ip2 and (not ip1));end my exor beh;

The architecture describes the behaviour (function), end my_exor_beh; ( ),interconnections and the relationship between different inputs and outputs of the entity.

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 16: vhdlprg

VHDL PROGRAMMING 16

Library : Collection of design elements, type declarations,my EXOR gate

library IEEE;use IEEE.std_logic_1164.all;

entity my exor is

sub programs, etc.

entity - defines theinterface.

entity my_exor isport (ip1 : in std_logic;

ip2 : in std_logic;op1 : out std_logic

);

std_logic is the type of the portIt is defined in the IEEE library.Any node of type std_logic can take9 diff t l);

end my_exor;

architecture my exor beh of my exor is

Mode of the port :It can be in, out or inout

9 different value.‘0’ , ’1’ , ’H’ , ’L’ , ’Z’ , ’U’ , ’X’ , ’W’ , ’-’

The architecture describes the architecture my_exor_beh of my_exor isbeginop1 <= (ip1 and (not ip2)) or

(ip2 and (not ip1));end my exor beh;

behaviour(function), interconnectionsand the relationship between differentinputsand outputs.

end my_exor_beh;

configuration my_exor_C of my_exor isfor my_exor_behend for;

The configuration is optional.It defines the entity architecturebindings.

CS 2204 Digital Logic and State Machine DesignFall 2012

end for;end my_exor_C;

gMore about configurations later.

Page 17: vhdlprg

VHDL PROGRAMMING 17

Internal connections are made using signals.Signals are defined inside the architecture.

architecture my_exor_beh of my_exor issignal temp1 : std_logic;signal temp2 : std_logic;

beginbegin......

end my_exor_beh;

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 18: vhdlprg

VHDL PROGRAMMING 18

my EXOR with internal signalslibrary IEEE;use IEEE.std_logic_1164.all;

entity my_exor isport (ip1 : in std_logic;

ip2 : in std_logic;op1 : out std_logic

);end my_exor;

architecture exor_w_sig of my_exor issignal temp1, temp2 : std_logic;

b ibegintemp1 <= ip1 and (not ip2);temp2 <= ip2 and (not ip1);op1 <= temp1 or temp2;d iend exor_w_sig;

configuration my_exor_C of my_exor isfor exor_w_sig

d f

CS 2204 Digital Logic and State Machine DesignFall 2012

end for;end my_exor_C;

Page 19: vhdlprg

VHDL PROGRAMMING 19

SUMMARYIntroduction to:

• VHDL flow

• Comments

• Library declaration

• Entity declaration (ports, modes, std_logic type)

• Architecture

Si l d l ti• Signal declarations

• Signal assignments

• Component declaration and instantiation• Component declaration and instantiation

• Configuration statement

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 20: vhdlprg

VHDL PROGRAMMING 20

Design Hierarchy Levels ( Modeling Styles)

• Structural Define explicit components and the connections between

them.

• Dataflow• DataflowMost are like assigning expressions to signals

• BehavioralWrite an algorithm that describes the circuit’s output

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 21: vhdlprg

VHDL PROGRAMMING 21

Dataflow Level

• Dataflow description The detail is less with data dependencies described, not

the components and connections

Includes “when” and “select” (case) statements

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 22: vhdlprg

VHDL PROGRAMMING 22

Full Adder - Data flow

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 23: vhdlprg

VHDL PROGRAMMING 23

Structural Level

• A structural description is like the schematic, describing the components and their interconnections precisely

Includes concurrent statements • A component statement is a concurrent statement

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 24: vhdlprg

VHDL PROGRAMMING 24

4-bit Ripple-Carry Adder - Structural Description4 bit Ripple Carry Adder Structural Description

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 25: vhdlprg

VHDL PROGRAMMING 25

4-bit Ripple-Carry Adder - Structural Description cntd.

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 26: vhdlprg

VHDL PROGRAMMING 26

Behavioral Level

• Behavioral descriptionMay not be synthesizable or may lead to a very large y y y y g

circuit Primarily used for simulation N ll VHDL “ ” Normally uses VHDL “processes”

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 27: vhdlprg

VHDL PROGRAMMING 27

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 28: vhdlprg

VHDL PROGRAMMING 28

Simulation results (temp. signals also shown)

HDL Synthesis ReportMacro Statistics# Adders/Subtractors : 25-bit adder : 2

# Comparators : 1# Comparators : 15-bit comparator greater : 1

A strong reason to think of hardware being designed,

CS 2204 Digital Logic and State Machine DesignFall 2012

A strong reason to think of hardware being designed, while writing VHDL behavioral code.

Page 29: vhdlprg

VHDL PROGRAMMING 29

Constructs in VHDLConstructs in VHDL

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 30: vhdlprg

VHDL PROGRAMMING 30

Concurrent Statements

• All concurrent statements in an architecture are executed simultaneously.

• Concurrent statements are used to express parallel activity as is the case with any digital circuit.y g

• Concurrent statements are executed with no predefined order by the simulator . So the order in which the code is ywritten does not have any effect on its function.

• They can be used for behavioral and structural and data yflow descriptions.

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 31: vhdlprg

VHDL PROGRAMMING 31

Concurrent statements contd.• Process is a concurrent statement in which sequential

statements are allowed.

All i hit t t d• All processes in an architecture are executed simultaneously.

• Concurrent statements are executed by the simulator• Concurrent statements are executed by the simulator when one of the signals in its sensitivity list changes . This is called occurrence of an ‘event’.eg : c <= a or b; is executed when either signal ‘a’ or signal ‘b’ changes.process(clk reset)process(clk , reset) ...is executed when either ‘clk’ or ‘reset’ changes

• Signals are concurrent whereas variables are sequential

CS 2204 Digital Logic and State Machine DesignFall 2012

objects.

Page 32: vhdlprg

VHDL PROGRAMMING 32

Conditional signal assignment

• The ‘when‘ statement This type of assignment has one target butThis type of assignment has one target but

multiple condition expressions.This statement assigns value based on the g

priority of the condition.syntaxsig_name <= exp1 when condition1 else

exp2 when condition2 elseexp3;exp3;

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 33: vhdlprg

VHDL PROGRAMMING 33

entity my_nand isport (a b : in std logic;port (a, b : in std_logic;

c : out std_logic);end my_nand;architecture beh of my nand isarchitecture beh of my_nand isbegin

c <= ‘0’ when a = ‘1’ and b = ‘1’ else‘1’ ;

end beh;

entity tri_state is( i d l iport (a, en : in std_logic;b : out std_logic);

end tri_state;architecture beh of tri state isarchitecture beh of tri_state isbegin

b <= a when en = ‘1’ else‘Z’;

CS 2204 Digital Logic and State Machine DesignFall 2012

Z ;end beh;

Page 34: vhdlprg

VHDL PROGRAMMING 34

example

architecture try_A of try isbegin

Y <= i1 when s1 = ‘0’ and s0 = ‘0’ elseY <= i1 when s1 = ‘0’ and s0 = ‘0’ elsei2 when s1 = ‘0’ and s0 = ‘1’ elsei3 when s1 = ‘1’ and s0 = ‘0’ elsei4 when s1 = ‘1’ and s0 = ‘1’ else‘0’ ;

end try A;y_ ;

CS 2204 Digital Logic and State Machine DesignFall 2012

Incomplete specification is not allowed

Page 35: vhdlprg

VHDL PROGRAMMING 35

example

architecture when_grant of bus_grant issignalsignal …

begindata_bus <= a and b when e1 = ‘1’ else

e or f when a = b elseh h 3 ‘1’g & h when e3 = ‘1’

else(others => ‘Z’);

CS 2204 Digital Logic and State Machine DesignFall 2012

(others => Z );end when_grant;

Page 36: vhdlprg

VHDL PROGRAMMING 36

Selective signal assignment

The with statement

• This statement is similar to the case statement• syntaxwith expression selecttarget <= expression1 when choice1

i 2 h h i 2expression2 when choice2expressionN when choiceN;

• all possible choices must be enumerated• all possible choices must be enumerated• when others choice takes care of all the

remaining alternatives.

CS 2204 Digital Logic and State Machine DesignFall 2012

e a g a te at es

Page 37: vhdlprg

VHDL PROGRAMMING 37

Difference between with and when statements

• Each choice in the with statement should be unique

• Compared to the ‘when’ statement, in the ‘with’ statement, choice is limited to the choices provided by th ith ‘ i ’ h f th ‘ h ’ t t tthe with ‘expression’, whereas for the ‘when’ statement each choice itself can be a separate expression.

• The when statement is prioritized (since each choice can be a different expression, more than one condition can be true at the same time, thus necessitating a priority , g p ybased assignment) whereas the with statement does not have any priority (since choices are mutually exclusive)

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 38: vhdlprg

VHDL PROGRAMMING 38

entity my_mux isport (a b c d : in std logic;port (a, b, c, d : in std_logic;

sel0, sel1 : in std_logic;e : out std_logic);

end my_mux;

architecture my mux A of my mux isy_ _ y_signal sel: std_logic_vector(1 downto 0);

beginsel <= sel1 & sel0;sel <= sel1 & sel0;with sel selecte <= a when “00”

b when “01”c when “10”d when others;

CS 2204 Digital Logic and State Machine DesignFall 2012

;end my_mux_A;

Page 39: vhdlprg

VHDL PROGRAMMING 39

Component Instantiation

• A component represents an entity architecture pair.

C t ll hi hi l d i f l• Component allows hierarchical design of complex circuits.

A component instantiation statement defines a part• A component instantiation statement defines a part lower in the hierarchy of the design entity in which it appears. It associates ports of the component with the signals of the entity. It assigns values to the generics of the component.

A t h t b d l d i ith k• A component has to be declared in either a package or in the declaration part of the architecture prior to its instantiation.

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 40: vhdlprg

VHDL PROGRAMMING 40

Component Declaration and Instantiation

• Syntax(Declaration)component component_name p p _

[generic list][port list]

end component;

• Syntax(Instantiation)label:component_name [generic map][generic map] port map;

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 41: vhdlprg

VHDL PROGRAMMING 41

entity my and is1

entity my_and isport( a : in std_logic;

b : in std_logic;c : out std_logic);

U1: my_andgeneric map (tpd => 5 ns)port map (x => a,

y => b_

end my_and;

architecture my_and_A of my_and is

y => b,z => temp);

component and2generic (tpd: time := 2 ns);port (x : in std_logic;

i td l iy : in std_logic;z : out std_logic);

end component;signal temp : std logic;

U2: my_andgeneric map (tpd => 2 ns)port map (x => a,signal temp : std_logic;

beginc <= temp;-- component instantiation here

p p ( ,y => b,z => temp);

CS 2204 Digital Logic and State Machine DesignFall 2012

pend my_and_A;

Page 42: vhdlprg

VHDL PROGRAMMING 42

architecture exor_A of exor is1component my_or

port (a : in std_logic;b : in std_logic;

t td l i

u1 : my_orport map (y2,

y3,y1);y : out std_logic

);end component;component my and

y1);u2 : my_and

port map (a_n,b,component my_and

port (a : in std_logic;b : in std_logic;y : out std logic

b,y2);

u3 : my_andport map (a,y : out std_logic

);end component;signal a_n, b_n : std_logic;

p p ( ,b_n,y3);

_ _ _signal y1, y2, y3 : std_logic;

begin. . . . .

a_n <= not a ;b_n <= not b ;

CS 2204 Digital Logic and State Machine DesignFall 2012

end exor_A;

Page 43: vhdlprg

VHDL PROGRAMMING 43

Component Instantiation contd.Positional association

U1: my and y_generic map(5 ns)port map(a, b, temp);

Named AssociationU1:my andU1:my_and generic map (tpd => 5 ns)port map (x => a,

y => b,z => temp);

CS 2204 Digital Logic and State Machine DesignFall 2012

The formal and the actual can have the same name

Page 44: vhdlprg

VHDL PROGRAMMING 44

Component Instantiation contd.

• Named association is preferred because it makes the d d bl d i b ifi d icode more readable and pins can be specified in any

order whereas in positional association order should be maintained as defined in the component and all thebe maintained as defined in the component and all the pins need to be connected .

• Multiple instantiation of the same component should have different labels.

CS 2204 Digital Logic and State Machine DesignFall 2012

have different labels.

Page 45: vhdlprg

VHDL PROGRAMMING 45

Process statement

• The process statement is a concurrent statement• The process statement is a concurrent statement , which delineates a part of an architecture where sequential statements are executed.

• Syntaxlabel: process [(sensitivity list )]declarations

beginsequential statementssequential statements

end process;

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 46: vhdlprg

VHDL PROGRAMMING 46

Process statement

• All processes in an architecture are executed concurrently with all other concurrent statements.y

• Process is synchronized with the other concurrent statements using the sensitivity list or a wait statement.

• Process should either have sensitivity list or an explicit wait statement. Both should not be present in the same

t t tprocess statement. • The order of execution of statements is the order in

which the statements appear in the processwhich the statements appear in the process • All the statements in the process are executed

continuously in a loop .

CS 2204 Digital Logic and State Machine DesignFall 2012

y

Page 47: vhdlprg

VHDL PROGRAMMING 47

Process contd.

• The simulator runs a process when any one of the signals in the sensitivity list changes. For a waitt t t th i l t t th ft thstatement, the simulator executes the process after the

wait is over.

The sim lator takes 0 sim lation time to e ec te all the• The simulator takes 0 simulation time to execute all the statements in the process. (provided there is no wait)

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 48: vhdlprg

VHDL PROGRAMMING 48

processbegin

if (reset = ‘1’) thenA <= ‘0’ ;

elsif (clk’event and clk = ‘1’) thenA <= ‘B’;

end if;wait on reset clk;

( lk t)

wait on reset, clk;end process;

process (clk,reset)begin

if (reset = ‘1’) thenA <= ‘0’;A <= ‘0’;

elsif (clk’event and clk = ‘1’) thenA <= ‘B’;

end if;

CS 2204 Digital Logic and State Machine DesignFall 2012

end if;end process;

Page 49: vhdlprg

VHDL PROGRAMMING 49

Sequential Statements• Sequential statements are statements which are

analyzed serially one after the other. The final output depends on the order of the statements unlikedepends on the order of the statements, unlike concurrent statements where the order is inconsequential.

• Sequential statements are allowed only inside processand subprograms (function and procedure)

• Process and subprograms can have only sequential statements within them.O l ti l t t t i bl• Only sequential statements can use variables.

• The Process statement is the primary concurrent VHDL statement used to describe sequential behaviour

CS 2204 Digital Logic and State Machine DesignFall 2012

statement used to describe sequential behaviour.

Page 50: vhdlprg

VHDL PROGRAMMING 50

Sequential Statements contd.

• Sequential statements can be used to generateCombinational logicCombinational logicSequential logic

Cl k d• Clocked processIt is easily possible to infer flip-flops using if

statements and ‘event attributestatements and event attribute.• Combinatorial processgenerates purely combinatorial logicgenerates purely combinatorial logic.All the inputs must be present in the sensitivity

list. Otherwise the simulation and synthesis

CS 2204 Digital Logic and State Machine DesignFall 2012

yresults will not match.

Page 51: vhdlprg

VHDL PROGRAMMING 51

The if statement

• Syntaxif condition1 thenif condition1 then

statements[elsif condition2 then Priority[

statements][else

statements]end if;

• An if statement selects one or none of a sequence of events to execute . The choice depends on one or more conditions.

CS 2204 Digital Logic and State Machine DesignFall 2012

conditions.

Page 52: vhdlprg

VHDL PROGRAMMING 52

The if statement contd.

if sel = ‘1’ thenc <= a;

if (sel = “00”) theno <= a;

c <= a;else

c <= b;

elsif sel = “01” thenx <= b;

elsif (color = red) thenend if;

elsif (color red) theny <= c;

elseo <= d;

If t t t b t d

o <= d;end if;

• If statements can be nested.

• If statement generates a priority structure

CS 2204 Digital Logic and State Machine DesignFall 2012

• If corresponds to when else concurrent statement.

Page 53: vhdlprg

VHDL PROGRAMMING 53

The case statement - syntaxcase expression is

when choice 1 => statements

when choice 3 to 5 =>t t tstatements

when choice 8 downto 6 =>statementsstatements

when choice 9 | 13 | 17 =>statements

when others => statements

CS 2204 Digital Logic and State Machine DesignFall 2012

end case;

Page 54: vhdlprg

VHDL PROGRAMMING 54

The case statement

• The case statement selects, for execution one of a number of alternative sequences of statements .q

• Corresponds to with select in concurrent statements .

• Case statement does not result in prioritized logic structure unlike the if statement.

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 55: vhdlprg

VHDL PROGRAMMING 55

The case statement contd.process(sel, a, b, c, d)begin

case sel isprocess (count)begin

when “00” =>dout <= a;

when “01” =>

begincase count is when 0 =>d t < “00” when “01” =>

dout <= b;when “10” =>

dout <= “00”;when 1 to 15 =>dout <= “01”;

dout <= c;when “11” =>

dout <= d;

when 16 to 255 =>dout <= “10”;

when others => ;when others =>

null;end case;

when others >null;

end case;d

CS 2204 Digital Logic and State Machine DesignFall 2012

end case;end process;

end process;

Page 56: vhdlprg

VHDL PROGRAMMING 56

Think Hardware! (Mutually exclusive conditions)( y )

myif_pro: process (s, c, d, e, f) beginbegin

if s = "00" thenpout <= c;l if "01" thelsif s = "01" thenpout <= d;

elsif s = "10" thenpout <= e;

elsepout <= f;p

end if;end process myif_pro;

CS 2204 Digital Logic and State Machine DesignFall 2012

This priority is useful for timings.

Page 57: vhdlprg

VHDL PROGRAMMING 57

Think Hardware! Use a case for mutually exclusive thingsexclusive thingsmycase_pro: process (s, c, d, e, f)

beginbegincase s iswhen "00" =>

pout <= c;when "01" =>

pout <= d;

C

D POUTpout < d;when "10" =>

pout <= e;E

F

POUT

when others => pout <= f;

end if;

S

There is no priority with case.

CS 2204 Digital Logic and State Machine DesignFall 2012

;end process mycase_pro;

p y

Page 58: vhdlprg

VHDL PROGRAMMING 58

BEHAVIORAL ( Processes using signals)

Sig1 = 2 + 3 = 5

Sig2 = 1

Sig1 2 + 3 5

Sig3 = 2 g

Sum = 1 + 2 + 3 = 6

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 59: vhdlprg

VHDL PROGRAMMING 59

BEHAVIORAL ( Processes using Variables)

var1 = 2 + 3 = 5var1 = 2 + 3 = 5

var2 = 5

var3 = 5var3 5

Sum = 5 + 5 + 5 = 15

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 60: vhdlprg

VHDL PROGRAMMING 60

Behavioral Description of a 3-to-8 Decoder

Except for differentExcept for different syntax, approach is not all that different f th d t flfrom the dataflow version

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 61: vhdlprg

VHDL PROGRAMMING 61

A Different Behavioral Description of a 3-to-8 DecoderDecoder

May not be synthesizable,h l i ffi i t li ti

CS 2204 Digital Logic and State Machine DesignFall 2012

or may have a slow or inefficient realization. But just fine for simulation and verification.

Page 62: vhdlprg

VHDL PROGRAMMING 62

74x148 behavioral description(8 to 3 line cascadable Priority Encoder)(8 to 3 line cascadable Priority Encoder)

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 63: vhdlprg

VHDL PROGRAMMING 63

--EI - Enable I/P --EO - O/P Enable--I - I/P(data to be encoded)

A O/P--A - O/P

type conversiontype conversion

CS 2204 Digital Logic and State Machine DesignFall 2012

Page 64: vhdlprg

VHDL PROGRAMMING 64

CONCLUSION

• Many VHDL constructs, although useful for simulation and other stages in the design process, are not relevant to synthesis. A sub-set of VHDL only can be used for synthesis.

• A construct may be fully supported ignored or• A construct may be fully supported, ignored, or unsupported.

• Ignored means that the construct will be allowed in the VHDL file but will be ignored by the synthesis tool.

• Unsupported means that the construct is not allowed and the code will not be accepted for synthesisand the code will not be accepted for synthesis.

• See the documentation of tools for exact details.

CS 2204 Digital Logic and State Machine DesignFall 2012