Docsity

VHDL Part 2: Function-style Attributes, Type Conversion, and Signal Assignments, Exams of Electrical and Electronics Engineering

Partial preview of the text

Download VHDL Part 2: Function-style Attributes, Type Conversion, and Signal Assignments and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

  • VHDL --- Part 2 ECE 153B --- Feb 3,

Function-style Attributes • Return info about a given type, signal, or array value^ type^ state is

(Init, Hold, Strobe, Read, Idle);

List of attributes

state’pos(Read)

position number of value

‘pos(value)

state’val(3)

Value corresp to position number

‘val(value) Note: ‘leftof and ‘rightof are not necessarily the same as ‘pred and ‘succsince there are ways to change the ordering of a subrange.

state’rightof(Init)

Opposite of the above

‘rightof

state’leftof(Read)

Value to the left of given value

‘leftof

state’pred(Read)

Predecessor (opposite of ‘succ)

‘pred(value)

state’succ(Read)

Value of successor of this type

‘succ(value)

Attributes for Signals List of attributes

Time elapsed since last transaction on this signal

‘last_active

Boolean: true if signal changed value this simulation cycle

‘event

Boolean: true if any transaction is scheduled on this signalin the current cycle

‘active

Value of the signal prior to last event

‘last_value

Time elapsed since previous event on this signal

‘last_event

Resolution • When a signal is simultaneously driven with more than 1 value, it mustbe resolved • Needed in order to describe bus

-style interconnect

-^ Data types in VHDL are, by default, un

resolved

-^ Data types are resolved only when a resolution function is included aspart of their declaration^ –^ Such a function specifies for all

combinations

of one or more values what

the resulting (resolved) value should be – IEEE 1164 has taken care of this for all of us ... (e.g. see

std_1164.vhd

-^ Std_logic and std_logic_vector are resolved types –^ Std_ulogic and std_ulogic_vector are corresponding un-resolved types –^ Both types are drop-in replacements for the defaults “bit” and “bit_vector” library ieee;use ieee.std_logic_1164.all

;

If-then-else statement • If^ statements imply priority^ –^ first_cond must be false beforesecond_cond is even looked at…^ if^ first_cond then^ statementelsif^ second_cond then^ statementelse^ statementend^ if;

  • Predicates must evaluate to boolean

type

  • e.g. can’t say

if^ my_signal

then^ ….

  • Instead,^ if

my_signal

=^ ‘1’^ then

-^ statement

can be one or more sequential statements

Case statement • Does not

imply priority

case^ control_expr is^ when^

test_expr1 =>statementswhen test_expr2 =>statementswhen others^ =>statements

end^ case;

  • all test expressions must be mutually exclusive• and^ they must cover all possible cases• The special case others

catches any cases not described earlier

while loop … • Conditional looping^ –^ probably not synthesizable^ –^ primary use is in a test bench^ –^ loop_name

phrase is optional (brackets not used) [loop_name:] while

condition loop statementsend loop^ [loop_name]

;

Infinite loop … • Another form of [un]conditional looping^ –^ probably not synthesizable^ –^ primary use is in a test bench^ –^ loop_name

phrase is optional (brackets not used)

-^ conditional loop exit optional [loop_name:] loop^ statements[exit^ when

condition_expr;] end^ loop

[loop_name]

;

Example bus_test FSM library^ ieee;use^ ieee.std_logic_1164.all;entity^ bus_test is^ port^ ( reset: in

std_logic;^

-- system reset signal (active-low)

addr:^ in^ std_logic_vector 23 downto 12;

-- top 12 address lines

STRB:^ in^ std_logic;

-- bus cycle active signal (active-low)

RW:^ in^ std_logic;

-- direction (1==read, 0==write)

H1:^ in^ std_logic;

-- system clock (nominally 10MHz)

RDY:^ out^ std_logic );

-- bus handshake (active-low, shared)

end^ bus_test;

Example bus_test_FSM architecture^ bus_test_FSM

of^ bus_test^ is constant^ MYADDR

:^ std_logic_vector

23 downto^12

:=^ "0001_0000_1111";
--^ 10F

signal^ RDYOE^

:^ std_logic;^

--^ tri-state^ control

signal^ for^ RDY

signal^ RDYVAL:

std_logic;^

--^ value^ for^ RDY

when^ enabled

type^ state^ is^

(Idle,^ DoIt,^ Fini);

--^ define^

FSM^ states

signal^ mystate

:^ state;^

--^ instantiate

our^ state^ variable

process^ (reset,

H1)^

--^ use^ process

for^ sequential

synthesis

begin^ if^ reset=‘0’

then^

--^ this^ is^ an^

asynchronous^ reset

mystate^ <= Idle;

--^ initialize^

the^ FSM^ state

RDYOE^ <=‘0’;^

--^ tri-state^ RDY RDYVAL<=‘0’;^

--^ be^ ready^ for

enable^ later

elsif^ H1’event

and^ H1=‘0’^ then

--^ trailing

edge^ trigger

case^ mystate^ is^ when^ Idle^ =>if^ STRB=‘0’

and^ RW=‘1’^ and

addr=MYADDR^ then mystate^ <=^ DoIt;

--^ also^

do^ any^ needed^

READ^ action^ here

RDYOE^ <=^ ‘0’;^

RDYVAL^ <= ‘0’;

else^ mystate^ <=^

Idle;^ --^

stay^ in^ Idle^

state RDYOE^ <=^ ‘0’;^

RDYVAL^ <= ‘0’;

end^ if;

Synthesis Guidelines • Always think of the physical structure that you want to get from synthesis^ –^ A clocked process

generates one or more registers

-^ A case^ statement generates a multiplexer –^ An if^ – then - else^ generates a priority encoder or mux -^ Comparison operators infer an identity or magnitude comparator^ •^ Identity comparisons are much

more efficient than magnitude comparators

-^ Try to imagine the hardware that corresponds to each piece of code •^ Build your design according to a mental (or actual) block diagram •^ Remember, ‘Z’ is usually not a value that synthesis can assign to a flip-flop! •^ Do not specify initial values in your signal declarations^ –^ Most synthesis systems ignore these^ –^ Instead, always initialize everything under an explicit reset

architecture CONCURRENT of REGMUX issignal^

MUXOUT : STD_LOGIC;-- Declare component before usecomponent DREGport (CLK, D : in^

STD_LOGIC;Q : out STD_LOGIC);

end component;begin-- This statement marks the beginning-- of the concurrent section.-- All design elements, whether-- components, simple concurrent-- statements, or processes, operate-- concurrently with each other-- “Just like hardware!”

-- Model operation of a 4-to-one-- mux component with a simple-- concurrent signal assignmentwith SEL selectY <=^ A when "00",B when "01",C when "10",D when others;-- Instantiated register runs-- concurrently with previous-- mux assignmentU1 : DREG-- use positional referencesport map ( CLK, MUXOUT, Y );end CONCURRENT;

Example Architecture

Structural VHDL  Structural code is analogous to a schematic^ ^ Components are instantiated^ ^ Signals are used to connect components^ ^ Function is specified internal to the components^ ^ Connections between components are made bysignals

Let’s Describe this Schematic