VHDL Slides For Cstruct Mux & Decoder
VHDL Slides For Cstruct Mux & Decoder
sel sel
sel sel
B 01
process (A, B, C, D sel) 10
Y
C
begin
if sel = b”00” then D 11
Y <= A;
elsif sel = b”01” then 2
Y <= B; Sel[1:0]
elsif sel = b”10” then
Y <= C;
8x(4→1) mux
else
Y <= D; A[7:0] 00
8
end if; B[7:0] 01
end process; 8
Y[7:0]
C[7:0] 8
10 8
D[7:0] 8
11
2
Sel[1:0]
2→4 decoder
signal sel : STD_LOGIV_VECTOR (1 downto 0);
signal Y : STD_LOGIV_VECTOR (3 downto 0);
process (sel)
begin 2→4 decoder
if sel = b”00” then
Y <= b“0001”; Y(0)
elsif sel = b”01” then sel(0) Y(1)
Y <= b”0010”;
elsif sel = b”10” then sel(1) Y(2)
Y <= b”0100”;
else Y(3)
Y <= b”1000”;
end if;
end process;
What do we do with VHDL?
• We describe our design in VHDL
This is similar to writing a program
0
0 Y
D Q 1
A0 1
A1 LUT
sel2
A2 CK
sel1
A3
0
in0 0 Y
D Q 1
x000 => 0
A0 x001 => 1 1
x010 => 0
in1 A1 x011 => 1
x100 => 0 sel2
sel A2 x101 => 0 CK
x110 => 1 sel1
A3 x111 => 1
sel sel
sel sel
CE CK CK
Here:
signal A : std_logic_vector (7 downto 0);
signal Y : std_logic_vector (7 downto 0);
signal CE : std_logic;
signal CK : std_logic;
process (CK)
begin
if CK’event and CK=‘1’ then If we have a rise in the CK then:
if CE = ‘1' then
Y <= A; If CE=‘1’ we sample data,
end if; else we keep the data unchanged.
end if;
end process;
A simple Data Path in VHDL- I
R0
n n
WE0
n x (2 → 1) mux
CK
R1 n
A ALU
n n
WE1 Y n
2
A1A0
2→4 CK
n B
decoder
2
R2 3
C1 C0
n n
S 2S 1S 0
2
WE2
B 1B 0
CK
R3
n n
WE3
S 2S 1S 0 A1A0 B 1B 0 C1 C0 n bits imm
CK
The CPU instruction format
A simple Data Path in VHDL- II
-- Definition of all signals used
29,28 25,24 21,20 17,16 15 0
0 S 2S 1S 0 0 0 A1A0 0 0 B 1B 0 0 0 C1 C0 16 bits imm
-- CPU “instruction”
signal instruction : STD_LOGIC_VECTOR (31 downto 0);
-- fields of the instruction
signal ALU_op : STD_LOGIC_VECTOR (2 downto 0);
signal ALU_src_A : STD_LOGIC_VECTOR (1 downto 0);
signal ALU_src_B: STD_LOGIC_VECTOR (1 downto 0);
signal ALU_destinaton: STD_LOGIC_VECTOR (1 downto 0);
signal imm : STD_LOGIC_VECTOR (15 downto 0);
-- ALU signals
signal ALU_A_in : STD_LOGIC_VECTOR (15 downto 0);
signal ALU_B_in : STD_LOGIC_VECTOR (15 downto 0);
signal ALU_Y_out : STD_LOGIC_VECTOR (15 downto 0);
-- general signals
signal CK : STD_LOGIC;
A simple Data Path in VHDL- III
-- renaming fields of the instruction
ALU_op <= instruction (30 downto 28);
29,28 25,24 21,20 17,16 15 0
ALU_src_A <= instruction (25 downto 24);
0 S 2S 1S 0 0 0 A1A0 0 0 B 1B 0 0 0 C1 C0 16 bits imm
ALU_src_B <= instruction (21 downto 20);
ALU_destinaton <= instruction (17 downto 16);
imm <= instruction (15 downto 0);
end case;
end process;
R1
-- ALU src B mux A
process(R0,R1,R2,imm,ALU_src_B) Y
begin
B
case ALU_src_B is R2
end case;
end process;
-- ALU
A simple Data Path in VHDL- IV
process (ALU_A_in, ALU_B_in, ALU_op)
begin
case ALU_op is
when b"000" => ALU_Y_out <= ALU_A_in + ALU_B_in;-- ADD
when b"001" => ALU_Y_out <= ALU_A_in - ALU_B_in;-- SUB
when b"010" => ALU_Y_out <= ALU_A_in and ALU_B_in;-- AND
when b"011" => ALU_Y_out <= ALU_A_in or ALU_B_in;-- OR
when b"100" => ALU_Y_out <= ALU_A_in xor ALU_B_in;-- XOR
when b"101" => ALU_Y_out <= not(ALU_A_in);--not A
when b"110" => ALU_Y_out <= ALU_A_in; -- A
when others => ALU_Y_out <= ALU_B_in;-- B
end case;
end process;
-- Data Path registers
process (CK) R0
begin
if CK'event and CK='1' then
if ALU_destinaton=b"00" then R1
R0 <= ALU_Y_out; A
R1 <= ALU_Y_out; B
elsif ALU_destinaton=b"10" then R2
R2 <= ALU_Y_out;
else
R3 <= ALU_Y_out;
R3
end if;
end if;
end process;
A simple Data Path in VHDL- V
NextState CrntState
Red
Yellow
X Green
Traffic Light FSM - III
-- Definitions related to the FSM
-- FSM states
type FSM_state is (
Red_State,
YellowRed_State,
Green_State,
Green2_State,
Green3_State,
Off1_State,
Off2_State,
Off3_State,
Yellow_State );