Professional Documents
Culture Documents
compare in1(.A(A[1]),.B(A[0]),.C(B[1]),.D(B[0]),.out(res));
endmodule
endmodule
Truth Table of the code :
A B C D Output
0 0 0 0 0
0 1 0 0 1
1 0 0 0 1
1 1 0 0 1
0 0 0 1 0
0 1 0 1 0
1 0 0 1 1
1 1 0 1 1
0 0 1 0 0
0 1 1 0 0
1 0 1 0 0
1 1 1 0 1
0 0 1 1 0
0 1 1 1 0
1 0 1 1 0
1 1 1 1 0
A[1] = A
A[0] = B
B[1] = C
B[0] = D
K-Map :
From KMap we get the logic of gates to be written
which is : AC’+BC’D’+ABD’
Hence from this logic I have implemented the the compare
module and hence made the comparator of 2 bit inputs A
and B.
3) FSM state diagram :
Present Bump_le Bump_rigth Next Walk_left walk_righ
State ft State t
S0 1 0 S1 0 1
S0 1 1 S1 0 1
S0 0 1 S0 1 0
S0 0 0 S0 1 0
S1 0 0 S1 0 1
S1 0 1 S0 1 0
S1 1 0 S1 1 0
S1 1 1 S0 0 1
S1 Areset==1 S0 1 0
S0 Areset==1 S0 1 0
always @(*)
begin
present_state<=next_state;
end
I have written the code from the basic state diagram of the
machine I know that as the next state is changed my present
state must also change hence we have define it in always @(*)
block and then for calculating next state I have made a always
@(posedge clk or posedge areset) as if areset is 1 then next
state is s0 and we are checking first that after that we are
checking that if state is s0 and we have got input that
bump_left==1 then state changes to s1 otherwise it is s0 only
and for the case if state is s1 and input is bump_right==1 then
we change state to s0 otherwise it remain same default state of
the machine is given to be s0. At last we know that if present
state is s0 then we are moving left hence we are assigning
walk_left equal to Boolean of present state == s0 and similarly
for the walk_right we have assigined. We consider a case that
your state was s0 and the walk_left==1 then we have
bump_left and bump_right both equal to 1 in that case as we
know that bump_right is 1 hence its state will change to s1 and
we will get walk_left inversed as present state changed to s1
and walk_right will also get inversed as the present state
changed to s1 hence walk_left would we 1(In this case only the
if statement of the state is processed as if is true then we never
run else and also it is given after passing from this it will run
agiain at the posedge of clk or posedge of areset).
4) (a) The given code is of 32 bit shift register as we can see from
code because here we can see that serial input from SI is
concatenated with first 31 bits of the value present in data. SEL
acts as a register which holds 32 address the bit value
corresponding to the address is passed to DO which is our
output. As if reset =1 at posedge of clock then data will become
0 else if reset is not 1 we assign data = data[30:0] hence we
conclude it is a 32 bit shift register.
Output size = 32 bit
Input size = 1 bit
No of address = 32
As we have used 32 flip-flop in this because it is a 32 bit shift
register hence there will be a latency(delay from input to
output)is of 32 clock cycle.