Chapter 4
Chapter 4
(1)
Outline
• Attributes
(2)
Raising the Level of Abstraction
add R1, R2, R3
R W
sub R3, R4, R5
move R7, R3
..
Data Output
Data input
Address
.
Memory Module Instruction Set Simulation
(3)
Extending the Event Model
Description of a
Complex
Process Output signals
Input signals
Sig1 <= …..
Sig2 <= …...
(4)
The Process Statement
library IEEE;
use IEEE.std_logic_1164.all;
entity mux4 is
port (In0, In1, In2, In3: in std_logic_vector (7 downto 0);
Sel: in std_logic_vector(1 downto 0);
Z : out std_logic_vector (7 downto 0));
end entity mux4;
Sensitivity List
architecture behavioral-3 of mux4 is
(5)
The Process Construct
(6)
Concurrent Processes: Full Adder
s1
In1 sum
Half Half
Adder Adder
In2 s2
c_in c_out
s3
(8)
Concurrent Processes: Half Adder
(9)
Processes + CSAs
library IEEE; MemRead MemWrite
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
(10)
Process + CSAs: The Write Process
(11)
Process + CSAs: The Read Statement
(12)
Iteration
Example: A Simple Multiplier
architecture behavioral of mult32 is
constant module_delay: Time:= 10 ns;
begin
mult_process: process(multiplicand,multiplier) is
variable product_register : std_logic_vector (63 downto 0) := X”0000000000000000”;
variable multiplicand_register : std_logic_vector (31 downto 0):= X”00000000”;
begin
multiplicand_register := multiplicand;
product_register(63 downto 0) := X”00000000” & multiplier;
for index in 1 to 32 loop
if product_register(0) = ‘1’ then
product_register(63 downto 32) := product_register (63 downto 32) +
multiplicand_register(31 downto 0);
end if;
-- perform a right shift with zero fill
product_register (63 downto 0) := ‘0’ & product_register (63 downto 1);
end loop;
-- write result to output port Concatenation operator
product <= product_register after module_delay;
(13)
Iteration
• while loop
– Boolean expression for termination
(14)
Outline
• Attributes
(15)
Process Behavior
• All processes are executed once at start-up
• Thereafter dependencies between signal values and events on
these signals determine process initiation
• One can view processes as components with an
interface/function
• Note that signals behave differently from variables!
library IEEE; begin
use IEEE.std_logic_1164.all; L1: var_s1 := x and y;
L2: var_s2 := var_s1 xor z;
entity sig_var is L3: res1 <= var_s1 nand var_s2;
port (x, y, z: in std_logic; end process;
res1, res2: out std_logic);
end entity sig_var; proc2: process (x, y, z) -- Process 2
begin
architecture behavior of sig_var is L1: sig_s1 <= x and y;
signal sig_s1, sig_s2: std_logic; L2: sig_s2 <= sig_s1 xor z;
begin L3: res2 <= sig_s1 nand sig_s2;
proc1: process (x, y, z) is -- Process 1 end process;
variable var_s1, var_s2: std_logic;
end architecture behavior;
(16)
Variables vs. Signals: Example
signals
variables
This transition is
determined by
process initiation
variables signals
• Writing processes
– Use signals to represent corresponding hardware entities
– Use variables when computing (future) values of signals
(18)
Simulation and Signals
Execute Process
• Process is initiated
current signal future signal
• Compute new signal values using
values values
current signal values
s1 reference compute
s1 – Use the value of the signal
s2 Process Foo s2 at process initiation
– Ignore textual
s7
dependencies between
s7 signals
update
(19)
Using Signals in a Process
s1 s3
In1
In2 s4
s2
library IEEE;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_1164.all;
entity combinational is
entity combinational is
port (In1, In2: in std_logic;
port (In1, In2: in std_logic;
z : out std_logic);
z : out std_logic);
end entity combinational;
end entity combinational;
signal s1, s2, s3, s4: std_logic:= ‘0’;
signal s1, s2, s3, s4: std_logic:= ‘0’;
begin
begin
sig_in_proc: process (In1, In2) is
s1 <= not In1;
begin
s2 <= not In2;
s1 <= not In1;
s3 <= not (s1 and In2);
s4 <= not (s2 and In1);
s2 <= not In2;
z <= not (s3 and s4); s3 <= not (s1 and In2);
Encapsulate in a
end architecture behavior; process
s4 <= not (s2 and In1);
z <= not (s3 and s4);
end process sig_in_proc;
end architecture behavior;
(21)
Using Signals in a Process (cont.)
IN1 IN1
IN2 IN2
Z Z
S1 S1
S2 S2
S3 S3
S4 S4
10 20 30 40 50 60 70 10 20 30 40 50 60 70
Using concurrent signal assignment statements Using signal assignment statements within a process
(22)
Outline
• Attributes
(23)
The Wait Statement
library IEEE;
use IEEE.std_logic_1164.all;
entity dff is
port (D, Clk : in std_logic;
Q, Qbar : out std_logic);
end entity dff; signifies a value change on signal clk
architecture behavioral of dff is
begin
output: process is
begin
wait until (Clk’event and Clk = ‘1’); -- wait for rising edge
Q <= D after 5 ns;
Qbar <= not D after 5 ns;
end process output;
end architecture behavioral;
(24)
The Wait Statement: Waveform
Generation
library IEEE; clock_process: process is
use IEEE.std_logic_1164.all; begin
entity two_phase is phi1 <= ‘1’, ‘0’ after 10 ns;
port(phi1, phi2, reset: out std_logic); phi2 <= ‘0’, ‘1’ after 12 ns, ‘0’ after
end entity two_phase; 18 ns;
architecture behavioral of two_phase is wait for 20 ns;
begin end process clock_process;
rproc: reset <= ‘1’, ‘0’ after 10 ns; end architecture behavioral;
reset
events specified
by the reset phi1
and clock
phi2
processes
10 20 30 40 50 60
Time (ns)
(25)
Wait Statement: Asynchronous Inputs
library IEEE; use IEEE.std_logic_1164.all;
entity asynch_dff is
port (R, S, D, Clk: in std_logic;
Q, Qbar: out std_logic);
end entity asynch_dff;
architecture behavioral of asynch_dff is
begin
output: process (R, S, Clk) is execute on event on any signal
begin
if (R = ‘0’) then
Q <= ‘0’ after 5 ns; implied ordering provides
Qbar <= ‘1’ after 5 ns; asynchronous set
elsif S = ‘0’ then reset
Q <= ‘1’ after 5 ns;
Qbar <= ‘0’ after 5 ns;
elsif (rising_edge(Clk)) then
Q<= D after 5 ns;
Qbar <= (not D) after 5 ns;
end if;
end process output;
end architecture behavioral;
(26)
The Wait Statement
(27)
Outline
• Attributes
(28)
Attributes
driver
(29)
Classes of Attributes
• Value attributes
– returns a constant value
• Function attributes
– invokes a function that returns a value
• Signal attributes
– creates a new signal
• Type Attributes
– Supports queries about the type of VHDL objects
• Range attributes
– returns a range
(30)
Value Attributes
• Return a constant value
– type statetype is (state0, state1, state2 state3);
• state_type’left = state0
• state_type’right = state3
• Examples
(31)
Example
clk_process: process
begin
wait until (clk’event and clk = ‘1’);
if reset = ‘1’ then
state <= statetype’left;
else state <= next_state;
end if;
end process clk_process;
(32)
Function Attributes
(33)
Function Attributes (cont.)
(34)
Range Attributes
(35)
Signal Attributes
(36)
Signal Attributes: Example
(37)
Outline
• Attributes
(38)
State Machines
0/1
Combinational Outputs
Inputs logic
1/0 s0 s1 0/1
1/0
Next state
State
Clk
• Basic components
– Combinational component: output function and next state
function
– Sequential component
• Natural process-based implementation
(39)
Example: State Machine
library IEEE;
use IEEE.std_logic_1164.all;
entity state_machine is
port(reset, clk, x : in std_logic;
z : out std_logic);
end entity state_machine;
architecture behavioral of state_machine is
type statetype is (state0, state1);
signal state, next_state : statetype := state0;
begin
comb_process: process (state, x) is
begin
--- process description here
end process comb_process;
clk_process: process is
begin
-- process description here
end process clk_process;
end architectural behavioral;
(40)
Example: Output and Next State Functions
(41)
Example: Clock Process
clk_process: process is
begin
wait until (clk’event and clk = ‘1’); -- wait until the
rising edge
if reset = ‘1’ then -- check for reset and initialize
state
state <= statetype’left;
else state <= next_state;
end if;
end process clk_process;
end behavioral;
(42)
Summary
• Processes
– variables and sequential statements
– if-then, if-then-else, case, while, for
– concurrent processes
– sensitivity list
• Attributes
• Modeling State machines
wait on ReceiveData’transaction
if ReceiveData’delayed = ReceiveData then
..
(43)