Professional Documents
Culture Documents
Resources
Volnei A. Pedroni, Circuit Design with VHDL Chapter 5, Concurrent Code (without 5.5) Chapter 4.1, Operators
Combinational Logic
Combinational Logic
Registers
dataflow
Concurrent statements
structural
Components and interconnects
behavioral
Sequential statements Registers State machines Test benches
Data-flow VHDL Major instructions Concurrent statements concurrent signal assignment () conditional concurrent signal assignment (when-else) selected concurrent signal assignment (with-select-when) generate scheme for equations (for-generate)
A1
IN 0
NEG_A
MUX_1 MUX_2
IN 1 IN 2 IN 3 O U T PU T
Y1
S E L1 S E L0
B1
MUX_4_1
MUX_3
NEG_Y
NEG_B L1 L0
Data-flow VHDL Major instructions Concurrent statements concurrent signal assignment () conditional concurrent signal assignment (when-else) selected concurrent signal assignment (with-select-when) generate scheme for equations (for-generate)
11
12
PARITY Example
13
14
ENTITY parity IS PORT( parity_in : IN STD_LOGIC_VECTOR(7 DOWNTO 0); parity_out : OUT STD_LOGIC ); END parity;
15
xor_out(2)
xor_out(3)
xor_out(4)
xor_out(5) xor_out(6)
16
PARITY: Architecture
ARCHITECTURE parity_dataflow OF parity IS SIGNAL xor_out: std_logic_vector (6 downto 1); BEGIN
xor_out(1) <= parity_in(0) XOR parity_in(1); xor_out(2) <= xor_out(1) XOR parity_in(2); xor_out(3) <= xor_out(2) XOR parity_in(3); xor_out(4) <= xor_out(3) XOR parity_in(4); xor_out(5) <= xor_out(4) XOR parity_in(5); xor_out(6) <= xor_out(5) XOR parity_in(6); parity_out <= xor_out(6) XOR parity_in(7);
END parity_dataflow;
17
xor_out(2)
xor_out(3)
xor_out(4)
xor_out(5) xor_out(6)
xor_out(7)
18
PARITY: Architecture
ARCHITECTURE parity_dataflow OF parity IS SIGNAL xor_out: STD_LOGIC_VECTOR (7 downto 0); BEGIN
xor_out(0) <= parity_in(0); xor_out(1) <= xor_out(0) XOR parity_in(1); xor_out(2) <= xor_out(1) XOR parity_in(2); xor_out(3) <= xor_out(2) XOR parity_in(3); xor_out(4) <= xor_out(3) XOR parity_in(4); xor_out(5) <= xor_out(4) XOR parity_in(5); xor_out(6) <= xor_out(5) XOR parity_in(6); xor_out(7) <= xor_out(6) XOR parity_in(7); parity_out <= xor_out(7);
END parity_dataflow;
19
END parity_dataflow;
20
21
concurrent signal assignment () conditional concurrent signal assignment (when-else) selected concurrent signal assignment (with-select-when) generate scheme for equations (for-generate)
22
23
Internal signals (defined in a given architecture) Ports of the mode - out - inout - buffer
Arithmetic operations
Synthesizable arithmetic operations: Addition, + Subtraction, Comparisons, >, >=, <, <= Multiplication, * Division by a power of 2, /2**6 (equivalent to right shift) Shifts by a constant, SHL, SHR
26
Arithmetic operations
The result of synthesis of an arithmetic operation is a - combinational circuit - without pipelining. The exact internal architecture used (and thus delay and area of the circuit) may depend on the timing constraints specified during synthesis (e.g., the requested maximum clock frequency).
27
30
ARCHITECTURE Behavior OF adder16 IS SIGNAL Sum : STD_LOGIC_VECTOR(16 DOWNTO 0) ; BEGIN Sum <= ('0' & X) + Y + Cin ; S <= Sum(15 DOWNTO 0) ; Cout <= Sum(16) ; END Behavior ;
31
ARCHITECTURE Behavior OF adder16 IS SIGNAL Sum : UNSIGNED(16 DOWNTO 0) ; BEGIN Sum <= ('0' & X) + Y + Cin ; S <= Sum(15 DOWNTO 0) ; Cout <= Sum(16) ; END Behavior ;
32
ARCHITECTURE Behavior OF adder16 IS SIGNAL Sum : STD_LOGIC_VECTOR(16 DOWNTO 0) ; BEGIN Sum <= ('0' & X) + Y + Cin ; S <= Sum(15 DOWNTO 0) ; Cout <= Sum(16) ; Overflow <= Sum(16) XOR X(15) XOR Y(15) XOR Sum(15) ; END Behavior ;
33
34
ARCHITECTURE Behavior OF adder16 IS SIGNAL Sum : SIGNED(16 DOWNTO 0) ; BEGIN Sum <= ('0' & X) + Y + Cin ; S <= Sum(15 DOWNTO 0) ; Cout <= Sum(16) ; Overflow <= Sum(16) XOR X(15) XOR Y(15) XOR Sum(15) ; END Behavior ;
35
36
37
Integer Types
Operations on signals (variables) of the integer types: INTEGER, NATURAL, and their sybtypes, such as
TYPE day_of_month IS RANGE 0 TO 31; are synthesizable in the range -(231-1) .. 231 -1 for INTEGERs and their subtypes 0 .. 231 -1 for NATURALs and their subtypes
38
Integer Types
Operations on signals (variables) of the integer types: INTEGER, NATURAL, are less flexible and more difficult to control than operations on signals (variables) of the type STD_LOGIC_VECTOR UNSIGNED SIGNED, and thus are recommened to be avoided by beginners.
39
40
Testbenches
41
43
45
CONSTANT reset2_width : TIME := 150 ns; SIGNAL reset1 : STD_LOGIC; SIGNAL reset2 : STD_LOGIC := 1;
BEGIN ....... reset1_generator: PROCESS reset1 <= 1; WAIT FOR reset_width; reset1 <= 0; WAIT; END PROCESS; reset2_generator: PROCESS WAIT FOR reset_width; reset2 <= 0; WAIT; END PROCESS; ....... END behavioral; 46
Typical error
SIGNAL test_vector : STD_LOGIC_VECTOR(2 downto 0); SIGNAL reset : STD_LOGIC; BEGIN ....... generator1: PROCESS reset <= 1; WAIT FOR 100 ns reset <= 0; test_vector <="000"; WAIT; END PROCESS; generator2: PROCESS WAIT FOR 200 ns test_vector <="001"; WAIT FOR 600 ns test_vector <="011"; END PROCESS; ....... END behavioral; 47
48
Wait : waveform will keep its state after the last wait instruction.
49
Assert
Assert is a non-synthesizable statement whose purpose is to write out messages on the screen when problems are found during simulation. Depending on the severity of the problem, The simulator is instructed to continue simulation or halt.
50
Assert - syntax
ASSERT condition [REPORT "message" [SEVERITY severity_level ]; The message is written when the condition is FALSE. Severity_level can be: Note, Warning, Error (default), or Failure.
51
Assert - Examples
assert initial_value <= max_value report "initial value too large" severity error;
assert packet_length /= 0 report "empty network packet received" severity warning; assert false report "Initialization complete" severity note;
52
Report - syntax
REPORT "message" [SEVERITY severity_level ]; The message is always written. Severity_level can be: Note (default), Warning, Error, or Failure.
53
Report - Examples
report "Initialization complete";
54
55
Anatomy of a Process
[label:] process [(sensitivity list)] [declaration part] begin statement part end process;
56
58
59