Академический Документы
Профессиональный Документы
Культура Документы
Array attributes are used to find the range, length or boundaries of arrays.
Type ROM is array (0 to 15, 7 downto 0) of bit;
Signal ROM1: ROM;
Signal Attributes:
A transaction occurs on a signal every time it is evaluated. Regardless of whether the signal changes or
not. Consider the concurrent VHDL statement A<=B and C. If B=0, then a transaction occurs on A
every time C changes, since A is recomputed every time C changes. If B=1, then an event and a
transaction occur on A every time C changes. S’ACTIVE returns true if S has just been reevaluated,
even if S does not change.
Attribute T/E Example Kind Type
Attribute description for the specified example
‘EVENT EV S1’EVENT VALUE BOOLEAN
In a simulation cycle, if s1 changes, this attribute becomes TRUE.
‘LAST_EVENT EV s1’LAST_VALUE VALUE TIME
The amount of time since the last value change on s1. If s1’EVENT is TRUE, the value of
s1’LAST_VALUE is 0.
‘LAST_VALUE EV s1’LAST_VALUE VALUE As s1
The value of s1 before the most recent event occurred on this signal.
‘ACTIVE TR s1’ACTIVE VALUE BOOLEAN
If s1 has had a transaction in the current simulation cycle, s1’ACTIVE will be TRUE for
this simulation cycle, for delta time.
‘LAST_ACTIVE TR s1’LAST_ACTIVE VALUE TIME
The amount of time since the last transaction occurred on s1. If s1’ACTIVE is TRUE,
s1’LAST_ACTIVE is 0.
‘DRIVING - s1’DRIVING VALUE BOOLEAN
If s1 is being driven in a process, s1’DRIVING is TRUE in the same process.
‘DRIVING_VALUE - s1’DRIVING_VALUE VALUE As s1
The driving value of s1 from within the process this attribute is being applied.
‘DELAYED - s1’DELAYED (5 NS) SIGNAL As s1
A copy of s1, but delayed by 5 NS. If no parameter or 0, delayed by delta. Equivalent to
TRANSPORT delay of s1.
‘STABLE EV s1’STABLE (5 NS) SIGNAL BOOLEAN
A signal that is TRUE if s1 has not changed in the last 5 NS. If no parameter or 0, the
resulting signal is TRUE if s1 has not changed in the current simulation time.
‘QUIET TR s1’QUIET (5 NS) SIGNAL BOOLEAN
A signal that is TRUE if no transaction has been placed on s1 in the last 5 NS. If no
parameter or 0, the current simulation cycle is assumed.
‘TRANSACTION TR s1’TRANSACTION SIGNAL BIT
A signal that toggles each time a transaction occurs on s1. Initial value of this attribute is not
defined.
Programs using Functions & Procedure
begin
z<= largest(10,30,20); Actual
end lar; parameters
The function largest computes the largest among the three integer variables a, b, c
passed as formal parameters and returns the largest number. Since the function is
written in architecture it becomes local to this architecture lar. So this function code
cannot be used in any other architecture Output of the program will be 30 which is the
largest among the three numbers 10,30 and 20 that is passed as actual parameters to the
function largest
2. Program to convert vector to integer using functions.
library ieee;
use ieee.std_logic_1164.all;
entity test is
port(a: in std_logic_vector (3 downto 0);
ya: out integer range 0 to 15 );
function v2i(a:std_logic_vector)
return integer is
variable r: integer;
begin
r:=0;
for i in a’range loop
if a(i)=‘1’ then
r:= r+2**i;
end if;
end loop;
return r;
end function v2i;
The function v2i computes the integer equivalent of the std_logic_vector, which is
passed as an argument to the function. Since the function v2i is written in the entity test
the function code is available to any architecture written to the entity test. it is
important to note that this function code v2i can be made available to multiple
architectures written to the same entity. But in the previous example since the function
is written in architecture the code will not be available to any other architecture written
to the same entity.
If the input a=1010
Then the output ya =10.
3. Program to add 4 bit vector using procedures.
library ieee;
use ieee.std_logic_1164.all;
entity test is
port(a,b: in std_logic_vector(3 downto 0);
cin : in std_logic;
sum: out std_logic_vector(3 downto 0);
cout: out std_logic);
end test;
begin
addvec(a,b,cin,sum,cout,4);
end test;
The procedure addvec is used to compute addition of two four bit numbers and
implicitly returns the sum and carry after addition. Since the procedure is written in the
architecture it cannot be used in any other architecture.
The input to the programs are a=0001, b=1110, cin=0.the output for the given inputs are
sum =1111 and cout=0;
4. Program to convert a given vector of 4 bits to its equivalent integer using procedure
library ieee;
use ieee.std_logic_1164.all;
entity test is
port(a: in std_logic_vector (3 downto 0);
ya: out integer range 0 to 15);
The procedure v2i computes the integer equivalent of the std_logic_vector, which
is passed as an in mode argument to the procedure and the computed integer value
is assigned to be out mode parameter passed to the procedure. Since the procedure
v2i is written in the entity test the procedure code is available to any architecture
written to the entity test. it is important to note that this procedure code v2i can be
made available to multiple architectures written to the same entity. But in the
previous example since the procedure is written in architecture the code will not be
available to any other architecture written to the same entity.
If the input a=1010 Then the output ya =10.
PACKAGES
5. Program to create a package ‘bit_pack’ to add four bit and eight bit numbers.
library ieee;
use ieee.std_logic_1164.all;
package bit_pack is
function add4(add1 ,add2:std_logic_vector (3 downto 0);
carry: std_logic ) return std_logic_vector;
end package bit_pack;
package bit_pack is
function vec2int(a: bit_vector)
return integer;
function int2vec(a,size: integer)
return bit_vector;
end bit_pack;
-- This package provides two overloaded functions for the plus operator
Package bit_overload is
function "+" (Add1, Add2: bit_vector) return bit_vector;
function "+" (Add1: bit_vector; Add2: integer) return bit_vector;
end bit_overload;
library BITLIB;
use BITLIB.bit_pack.all;
end bit_overload;
package fourpack is
type u_x01z is ('X','0','1','Z'); -- u_x01z is unresolved
type u_x01z_vector is array (natural range <>) of u_x01z;
function resolve4 (s:u_x01z_vector) return u_x01z;
subtype x01z is resolve4 u_x01z;
-- x01z is a resolved subtype which uses the resolution function resolve4
type x01z_vector is array (natural range <>) of x01z;
end fourpack;
2. In the following VHDL process A, B, C & D are all integers that have a value of 0 at time = 10 ns.
If E changes from ‘0’ to ‘1’ at time = 20 ns, specify the times at which each signal change and the
value to which it will change. List these changes in chronological order (20, 20 + ∆, ….).
P1: process
begin
wait on E;
A <= 1 after 5 ns;
B <= A + 1;
C <= B after 10 ns;
wait for 0 ns;
D <= B after 3 ns;
A <= A + 5 after 15 ns;
B <= B + 7;
end process p1;
4. A DD Flip-Flop is similar to a D Flip-Flop; expect that the f/f can change the state on both rising
& falling edge of the clock input. The f/f has a direct reset input R, and R = 0 resets the f/f to Q= 0
independent of clock. Write a VHDL description of a DD Flip-Flop.
5. A Moore Sequential machine with two inputs X1 & X2 and one output Z has following state table.
Write VHDL code that describes the machine at the behavioral level. Assume that state changes
occurs 10 ns after falling edge of the clock, and the output changes occur 10 ns after the state
changes.
X1 X2 Output
States 00 01 10 11 Z
1 1 2 2 1 0
2 2 1 2 1 1
6. Write a VHDL description for a divider that divides an 8-bit divided by a 5-bit divisor to give a 3-
bit quotient. The dividend register should be loaded when St = 1.
7. FSM with mealy output is shown below. Write the VHDL model for the FSM.
8. What value is sampled by the logic from an input port that is left open (that is, no-connect) during
its module instantiation?
9. How is the connectivity established in Verilog when connecting wires of different widths?
10. Why a nonblocking assignment should be used for sequential logic and what would happen if a
blocking assignment were used? Compare it with the same code in a combinatorial block.
11. What are the differences between the looping constructs forever, repeat, while, for, and do-while?
12. Illustrate a few important considerations on simulation regressions, and how Verilog can be useful
for achieving the same.