Week 5
Week 5
Week 5
entity nand_2 is
port ( a : in STD_LOGIC; -- NAND gate input 1
b : in STD_LOGIC; -- NAND gate input 2
c : out STD_LOGIC -- NAND gate output );
end nand_2;
2 to 4 Binary Decoder
A0 A0 A1
A1
entity dec_2_4 is
port ( A : in bit_vector ( 1 downto 0 );
Q : out bit_vector ( 3 downto 0 ) );
end dec_2_4;
2. Wait until
wait until (x*50 >500); -- wait for certain condition
3. Wait on signal
wait on a,b ; -- wait until a or b changes
4. Multiple wait
wait on a,b until interrupt = 1 for 10 ns; -- combination between 1,2,3
XOR gate in VHDL
AND gate in VHDL
OR gate in VHDL
a
or_out
b
Design of RS Flip-Flop
R S Q Q’ R
0 0 No change Q
RS_FF
0 1 1 0
Q’
1 0 0 1 S
1 1 Undefined
begin
u1 : nor2 port map (reset, Qb, Q);
u2 : nor2 port map (set, Q, Qb);
end struct_RS;
Design of a 4-bit shift register
Output
Z1 Z2 Z3
Z0
Q0 Q1 Q2 Q3
Z4
D Q
0 0
1 1
entity reg is
port (
Input , clk , reset : in bit;
Output : out bit
);
end reg ;
architecture shift_reg of reg is
component dff
port (
d, clk, reset : in bit ; dff0 : dff port map (z(0), clk, rest, z(1));
Q : out bit dff1 : dff port map (z(1), clk, rest, z(2));
); dff2 : dff port map (z(2), clk, rest, z(3));
end component ; dff3 : dff port map (z(3), clk, rest, z(4));
begin
z(0) <= Input;
G1 : for i in 0 to 3 generate
dffi : dff port map (z(i), clk, rest, z(i+1)); Can be replaced with
end generate;
Output <= z(4);
end shift_reg ;
Design of a single bit Full Adder
A
S
B F.A
C_OUT
C_IN
VHDL architecture behavior for Full Adder
entity FA1 is
port (
A , B , C_IN : in bit;
S, C_OUT : out bit
);
end FA1 ;
architecture behave_FA1 of FA1 is
begin
S <= A xor B xor C_IN;
C_OUT <= (A and B) or (C_IN and (A xor B));
end behave_FA1 ;
Using karnaugh map:
S = A B C_IN
C_OUT = AB + C_IN (A B)
VHDL architecture structural for Full Adder
X1
architecture struct_FA of FA1 is
component xor
port ( C_IN
a, b : in bit ; X2
c : out bit
); C_OUT
end component ;
component and
port ( X3
a, b : in bit ;
c : out bit
); begin
end component ; u1 : xor port map (A, B, X1);
component or u2 : xor port map (X1, C_IN, S);
port ( u3 : and port map (C_IN, X1, X2);
a, b : in bit ; u4 : and port map (A, B, X3);
c : out bit u5 : or port map (X2, X3, C_OUT);
); end struct_FA ;
end component ;
a
sum
H.F
carry_out
b
HALF-ADDER structure in VHDL
Full-adder using half-adders and any gate in VHDL
sum s1 sum
a a a sum
b b carry_out b carry_out
s3
carry_in carry_out
s2
4-bit binary adder in VHDL
Delay model in VHDL
1. Internal delay
2. Transport delay
Internal delay :
If b is the output signal and a is the input signal
Input output
5 ns 5 ns
0 5 2 7
𝑏 <= a after 10 ns;
Input output
5 ns
No signal
0 5
There is no output signal (zero output) if input signal is less than internal delay
Transport delay :
If b is the output signal and a is the input signal
a b
𝑏 <= a after 2 ns;
Input output
5 ns 5 ns
0 5 2 7
0 5 10 15