Professional Documents
Culture Documents
Lec13 VHDL
Lec13 VHDL
Digital Logic
1/26
Outline
Structural VHDL Use of hierarchy Component instantiation statements Concurrent statements Test Benches
2/26
entity entity-name is [port ( In_1, In_2, In_3 : in bit; out_1, out_2 : out bit; inout_1, inout_2 : inout bit);] end [entity] [entity-name];
architecture arch-name of entity-name is [declaration] begin architecture body end [architecture] [arch-name];
3/26
4/26
Concurrent Assignment
entity fulladder_df is port ( A, B, Cin : in bit; Sum, Cout : out bit); end fulladder_df;
A B Cin Sum full Cout adder_df
architecture data_flow of fulladder_df is begin Sum <= A xor B xor Cin; Cout <= (A and B) or (A and Cin) or (B and Cin); end data_flow;
5/26
Process
entity fulladder_bh is port ( A, B, Cin : in bit; Sum, Cout : out bit); end fulladder_bh; architecture behavioral of fulladder_bh is begin process (A , B, Cin) begin if ( A = 0 and B = 0 and Cin = 0) then Sum <= 0; Cout <= 0; elsif ( A = 0 and B = 0 and Cin = 1) then Sum <= 1; Cout <= 0; elsif ( A = 0 and B = 1 and Cin = 0) then Sum <= 1; Cout <= 0; elsif ( A = 0 and B = 1 and Cin = 1) then Sum <= 0; Cout <= 1; elsif ( A = 1 and B = 0 and Cin = 0) then Sum <= 1; Cout <= 0; elsif ( A = 1 and B = 0 and Cin = 1) then Sum <= 0; Cout <= 1; elsif ( A = 1 and B = 1 and Cin = 0) then Sum <= 0; Cout <= 1; else Sum <= 1; Cout <= 1; end if; end process; end behavioral;
A B Cin
6/26
The statement part of an architecture body of a structural VHDL description contains component instantiation statements FORMAT
label : component_name port map (positional association of ports); label : component_name port map (named association of ports); A1 : AND2_OP port map (A_IN, B_IN, INT1); A2 : AND2_OP port map (A => A_IN, C => C_IN, Z => INT2);
EXAMPLES
7/26
Component
entity fulladder_st is port ( A, B, Cin : in bit; Sum, Cout : out bit); end fulladder_st; architecture structral of fulladder_st is componenet XOR3_OP port ( IN_A, IN_B, IN_C : in bit; OUT_Z : out bit ); end component; componenet AOI3_OP port ( IN_A, IN_B, IN_C : in bit; OUT_Z : out bit ); end component; begin XOR : XOR3_OP port map (A, B, Cin, Sum); AOI : AOI3_OP port map (A, B, Cin, Cout); end structral;
fulladder _st A B Cin XO R Sum
AO I
Cout
8/26
Hirarchical Structure
Can combine 4 fulladder_xx functions (defined earlier) to form another 4-bit fulladder function
component fulladder_st port (A, B, Cin : in bit; Sum, Cout : out bit); end component; signal sig_c0, sig_c1, sig_c2 : bit; begin FA0 : fulladder_df port map (A(0), B(0), Cin, Sum(0), sig_c0); FA1 : fulladder_bh port map (A(0), B(0), sig_c0, Sum(0), sig_c1); FA2 : fulladder_st port map (A(0), B(0), sig_c1, Sum(0), sig_c2); FA3 : fulladder_bh port map (A(0), B(0), sig_c2, Sum(0), Cout); end hirarchical;
entity fulladder_4bit is port (A, B : in bit_vetcor (3 downto 0); Cin : in bit; Sum : out bit_vetcor (3 downto 0); Cout : out bit); end fulladder_4bit ; architecture hirarchical of fulladder_4bit is component fulladder_df port (A, B, Cin : in bit; Sum, Cout : out bit); end component; component fulladder_bh port (A, B, Cin : in bit; Sum, Cout : out bit); end component;
Cin
A(0) B(0)
A(1) B(1)
A(2) B(2)
A(3) B(3)
FA0
sig_c0
FA1
sig_c1
FA2
sig_c2
FA3
Cout
9/26
reg4
q(0)
entity reg4 is port ( en, clk : in bit; d : in bit_vector (3 downto 0); q : out bit_vector (3 downto 0)); end reg4;
10/26
d d_latch clk q
x and2_op y z
12/26
q(2)
q(1)
q(0)
13/26
Mixed Models
Models need not be purely structural or behavioral Often it is useful to specify a model with some parts composed of interconnected component instances and other parts using processes Use signals as a way to join component instances and processes A signal can be associated with a port of a component instance and can be assigned to or read in a process
14/26
clk reset
15/26
result : reg
port map (d => partial_product, q => full_product, en => result_en, reset => reset);
multiplier_sr : shift_reg
port map (d => multiplier, q => mult_bit, load => mult_load, clk => clk);
end component;
product <= full_product; process begin -- sequential statements end process; end mixed; 16/26
The signal assignment Z <= ((not A) and B) or (A and (not B)); Implies that the statement is executed whenever an associated signal changes value
17/26
Above, the first two statements will be executed when A or B changes, and third if Z changes Order of statements in the text does not matter
18/26
SIG_A <= IN_A and IN_B; SIG_B <= IN_A nor IN_C; SIG_C <= not IN_D;
The above sequence of statements can be concurrent or sequential depending on context If above appears inside an architecture body, it is a concurrent signal assignment If above appears inside a process statement, they will be executed sequentially
19/26
entity EVEN_PARITY is port ( BVEC : in bit_vector(7 downto 0); PARITY: out bit); end EVEN_PARITY; architecture DATA_FLOW of EVEN_PARITY is begin PARITY <= BVEC(0) xor BVEC(1) xor BVEC(2) xor BVEC(3) xor BVEC(4) xor BVEC(5) xor BVEC(6) xor BVEC(7); end DATA_FLOW ;
20/26
TREE CONFIGURATION
architecture TREE of EVEN_PARITY is signal INT1, INT2, INT3, INT4, INT5, INT6 : bit; begin INT1 <= BVEC(0) xor BVEC(1) ; INT2 <= BVEC(2) xor BVEC(3) ; INT3 <= BVEC(4) xor BVEC(5) ; INT4 <= BVEC(6) xor BVEC(7) ; INT5 <= INT1 xor INT2; INT6 <= INT3 xor INT4; PARITY <= INT5 xor INT6; end TREE ;
BVEC(0) BVEC(1) BVEC(2) BVEC(3) BVEC(4) BVEC(5) BVEC(6) BVEC(7)
EVEN_PARITY
INT1
INT2
INT5
PARITY
INT3
INT6
INT4
21/26
CASCADE CONFIGURATION
architecture CASCADE of EVEN_PARITY is signal INT1, INT2, INT3, INT4, INT5, INT6 : bit; begin INT1 <= BVEC(0) xor BVEC(1) ; INT2 <= INT1 xor BVEC(2) ; INT3 <= INT2 xor BVEC(3) ; INT4 <= INT3 xor BVEC(4) ; INT5 <= INT4 xor BVEC(5) ; INT6 <= INT5 xor BVEC(6); PARITY <= INT6 xor BVEC(7); end CASCADE ;
BVEC(0) BVEC(1) BVEC(2) BVEC(3) BVEC(4) BVEC(5) BVEC(6) BVEC(7) INT1 INT2 INT3 INT4 INT5 INT6 PARITY
EVEN_PARITY
22/26
Three different VHDL descriptions of the even parity generator were shown They have the same interface but three different implementation Use the same entity description but different architecture bodies
architecture DATA_FLOW of EVEN_PARITY is
23/26
Test Benches
One needs to test the VHDL model through simulation We often test a VHDL model using an enclosing model called a test bench A test bench consists of an architecture body containing an instance of the component to be tested It also consists of processes that generate sequences of values on signals connected to the component instance
24/26
Summary
Structural VHDL Use of hierarchy Component instantiation statements Concurrent statements Test Benches
26/26