Digital Systems - 6
Pere Pal`a - Alexis L
opez
iTIC http://itic.cat
March 2015
Sequential Datapath and Control Section
I
Objective: To add 4 numbers of 4 bits
Restriction: Only one adder.
Datapath
Control Section
A
B
C
D
M1
M0
clk
rst
6
00
01
mx
10
11
00
D
R
Datapath
signal
signal
signal
signal
A ,B ,C ,D , mx
: s t d _ l og i c _ v e c t o r (3 downto 0);
clk , rst
: std_logic ;
M
: s t d _ l o g i c _ v e c t o r (1 downto 0);
addA , addB , addOut ,
Din ,Q , S
: s t d _ l o g i c _ v e c t o r (5 downto 0);
begin
with M select
mx <= A when " 00 " , B when " 01 " ,
C when " 10 " , D when " 11 " , " ---- " when others ;
addA
<= Q ;
addB
<= " 00 " & mx ;
addOut <= s t d _ l o gi c _ v e c t o r ( unsigned ( addA )+ unsigned ( addB ));
Din
<= addOut ;
process ( clk )
begin
if rising_edge ( clk ) then
if rst = 1 then
Q <= " 000000 " ;
else
Q <= Din ;
end if ;
end if ;
end process ;
S <= Q ;
end ;
Control Section
Control Signals
I
Trigger the process
Indicate completion
State Transition Diagram
0
Depending on the signal
do_add
0
1
0
1
State Transitions
Present State
A
B
C
D
E
Next State
A, if do_add=1
B, if do_add=0
A, if do_add=1
C, if do_add=0
A, if do_add=1
D, if do_add=0
A, if do_add=1
E, if do_add=0
A, if do_add=1
E, if do_add=0
Actions
M <= "00"
add_done <= 0
M <= "01"
add_done <= 0
M <= "10"
add_done <= 0
M <= "11"
add_done <= 0
M <= "--"
add_done <= 1
State Machine Coding
type t_state is ( sA , sB , sC , sD , sE );
signal pr_state , nx_state : t_state ;
process ( clk )
begin
if rising_edge ( clk ) then
pr_state <= nx_state ;
end if ;
end process ;
rst <= do_add ;
process ( pr_state , do_add )
begin
case pr_state is
when sA = > -- actions c o r r e s p o n d i n g to state A
M
<= " 00 " ;
-- 1: Outputs . Caution !!!
add_done <= 0 ;
-- Do not forget any output !
if do_add = 1 then
nx_state <= sA ;
-- 2: Compute next state
else
-- d e p e n d i n g on present state
nx_state <= sB ;
-- and the input ( s )
end if ;
when sB = > -- actions c o r r e s p o n d i n g to state B
...
Simulation Results
Showing 1+2+4+8 = x0F = 001111
I add_done
signals when the result is available.
Has to be read on the next clock edge!
Additional signal
dstate
created to debug the state.