Ee457 HW1B r3
Ee457 HW1B r3
fm 10/6/06
EE457 Homework #1B 1/10
1 ( 12 + 12 + 12 = 36 points) 20 min.
j
State diagram design: 0 1 2 3 4 5 6 7
12
i3 1 1 1 1 1 1 1 1
pts 1.1 You need to clear a line of bits (a 450 degrees
line going south-east) starting from the given 4 1 1 1 1 1 1 1 1
START
start point I_ini and J_ini. You stop
5 1 1 1 0 1 1 1 1
when you hit the southern or eastern boarder
as shown on the side for I_ini = 5 and 6 1 1 1 1 0 1 1 1
J_ini =3.
7 1 1 1 1 1 0 1 1
END
The C code on the side precisely describes
the requirement.
i = I_ini;
j = J_ini;
while ((i <= 7) && (j <=7))
Complete the incomplete state diagram on
{
the next page. Complete it after considering A[i][j] = 0;
what the following 6 students are saying. i = i + 1;
You do not have to comment on them or j = j + 1;
agree or disagree with them. }
Student #4 asked student #3 to correct the "<" (less than) relational operators to "<=" (less than
or equal) relational operators as per the C code.
1.1.2 Student #5 and Student #6 wrote state transition conditions for state transition arrows diverging
from state C as shown below.
(I = 7) or (J = 7) (I = 8) or (J = 8)
Student #5 Student #6
C C
(Compute) (I = 7) or (J = 7) (Compute) (I = 8) or (J = 8)
S C
(Compute)
I D
(Initial) S (Done)
i<=I_ini;
j<=J_ini;
12
pts 1.2 In this slightly different design, you need to clear bits along the southern border or eastern border
after clearing bits on the 450 degrees line and reaching one of the borders as shown below.
The goal is to reach A[7][7] and clear that location too.
Obviously you should not clear any other location and you should not waste clocks.
Complete the state diagram for this revised task.
Note: Which ever counter reaches 7 first, should remain stay-put at 7 so that you walk along the
border.
j j
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1
i3 1 1 1 1 1 1 1 1 i3 1 1 1 1
START
1 0 1 1
4 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 0 1
START
5 1 1 1 0 1 1 1 1 5 1 1 1 1 1 1 1 0
6 1 1 1 1 0 1 1 1 6 1 1 1 1 1 1 1 0
7 1 1 1 1 1 0 0 0 END 7 1 1 1 1 1 1 1 0
END
S C
(Compute)
I D
(Initial) S (Done)
i<=I_ini;
j<=J_ini;
12 This is another variation of question 1.1 above. Instead of travelling at 450, here you travel in a
pts 1.3
"steps" like pattern as shown below. In the design A we take the first step horizontally where
as in the design B we take the first step vertically as shown. Any of them can reach any border
depending on the start point.
A j B j
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1
START
1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1
2 1 1 1 1 0 0 1 1 2 1 1 1 1 1 1 1 1
i3 i3
START
1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1
4 1 1 1 1 1 1 0 0 END 4 1 1 0 0 1 1 1 1
5 1 1 1 1 1 1 1 1 5 1 1 1 0 0 1 1 1
6 1 1 1 1 1 1 1 1 6 1 1 1 1 0 0 1 1
7 1 1 1 1 1 1 1 1 7 1 1 1 1 1 0 1 1
END
1.3.1 The following state diagram needs only state transition conditions to be added. The RTL is
complete! Find whether it is suitable for A or B and complete it. Suitable for
____________ ( A / B)
1.3.2 Make sure that your state diagram performs the task correctly for all starting points including
starting points on the borders such as A[7][4] or A[2][7] or A[7][7]. In these cases, your state
machine should clear that single-bit at the starting point and go to the DONE state.
4/10
Inc. J
j <= j + 1;
A[i][j] <= 0;
S
I D
(Initial) (Done)
i<=I_ini;
j<=J_ini; S
Inc. I 1
i <= i + 1;
A[i][j] <= 0;
2 ( 4 points) 2 min.
Cancelled
After START is given, light L should be lit for 1 minute (60 seconds). A slow clock of 1 cycle/
sec. has been provided for this purpose. Note that the I is initiated to 61 (sixty one) in the initial
state.
Three Bruins are asked to find the exit condition EC.
The three Bruins have applied for transfer to USC. You want to admit Bruin __________.
Unlike in lab 1 where you find minimum and maximum, here we need to find the LARGEST
PAIR_SUM (sum of two consecutive memory elements). We only process the first 8 elements of
the array, M(0) through M(7). The numbers, M(0) to M(7) are 4-bit UNSIGNED numbers.
The running largest pair_sum is maintained in a 5-bit register called LPS (LPS for Largest Pair
Sum).
1 ( 12 + 4 + 14 + 6 + 4 = 40 points) 25 min.
12
pts 1.1 After START is given, light L should be lit for one minute (60 seconds) and then should be off
for half a minute (30 seconds). It should keep repeating this ON/OFF operation until END signal
is given. However, if END signal is given when the light is lit, the light should complete its 60
seconds of ON period before returning to the initial state. A Q_ON_R (Q ON Remaining) state
is provided for this purpose of completing the 60-seconds of ON period. There is no need to
complete the 30 seconds OFF period if END is given while you are in Q_OFF state.
A slow clock of 1 cycle/sec. has been provided for this purpose. Complete the Mealy machine
below. All states and state transition arrows are in place.
Mr. Bruin is a little (?) confused about the terminal count for I and is looking at the following
choices: I = 29 / I = 30 / I = 31 for 30 seconds and I = 59 / I = 60 / I = 61 for 60 seconds.
T
AR
ST
RESET
Q_ON Q_OFF
L = 1; L = 0;
QI START if I = if I =
L = 0;
I <= 0; I <= 1; I <= ;
else else
I <= I + 1; I <= I + 1;
Note:
I <= 0; Note:
You are already given
Q_ON_R I <= 1. Do not change this.
L = 1;
I <= I + 1;
Carefully decide if this
should be
I <= 0; or I <= 1;
4
pts 1.2 Please note that we have written L = 1 and L = 0 (rather than L <= 1 and L <= 0). What could be
the possible difference? Does it matter? __________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
14 1.3 Convert the above design to a Moore machine. In the incomplete design below, Q_ON_C stands
pts for "Q ON CONTINUATION". This is the last clock of the ON period. Here (while keeping the
light ON) we want to initialize I in preparation to transiting to the Q_OFF state. Similarly
Q_OFF_C stands for "Q OFF CONTINUATION".
Q_OFF_C
L = 0;
I <= ;
Think!
T
AR
ST
RESET
Q_ON Q_OFF
QI START L = 1; L = 0;
L = 0; I <= I + 1; I <= I + 1;
I <= 0;
Q_ON_R Q_ON_C
L = 1; L = 1;
I <= I + 1; I <= 1 ;
Note
6
pts 1.4 If we were to implement the Moore machine using one-hot state assignment, show how you
would complete NSL and asynchronous initialization for the QI Flip-Flop (for the Initial state).
?
? PRE QI
D Q
CLK
CLK Q
CLR
?
4
pts 1.5 If the state machine is put in a box as shown on the
right, can you tell if it is the Mealy machine of START State L LED 330
Q1.1 or the Moore machine of Q1.3?
END Machine Ohm
Yes / No
CLOCK RESET
Given below is a small schematic and the associated Verilog code containing two assign
statements and three always clocked blocks. Rewrite the code without any assign statements in
two ways: Method #1: one clocked always block Method #2: Q1 and Q2 generated in one always
clocked block and Q3 generated in a separate clocked block. Do not worry about the data types
of signals (wire or reg). Let us assume that they are adjusted accordingly.
module Inputs/Outputs
D1
D Q Q1
D1 Q1 CLK I0
D3_Int
Q Q3
CLK
Q2 D3 I1 SY D
D2
CLK
D2 CLK
D3 Q3 D Q Q2 EN
X CLK
CLK
EN and D3_Int are internal
signals (not module port pins) X
Method #1: one clocked always block Method #2: Q1 and Q2 in one always block
Q3 in another
8+8
pts
We enjoyed teaching this course. Several of you made very interesting projects. Hope to see you in EE457. - Gandhi
For A to be equal to B, all the 8 A bits (A[14:7]) shall be ________________ (all zeros / all ones)
__________ (and / or)
the rest of the 7 A bits (A[6:0]) shall be equal to the corresponding 7 B bits (B[6:0]) .
For A to be less than B (like in -3 is less than -2), it is enough if any of the 8 A bits (A[14:7]) is
a ________ (zero / one). On the other hand , if all those 8 A bits (A[14:7]) are _______________
(all zeros / all ones), then, for A to be less than B, we need the 7-bit A (A[6:0]) to be ___________
(lower / higher) than the corresponding 7-bit B (B[6:0]). Here we compare the two 7-bit numbers
treating them as __________ (signed / unsigned) 7-bit numbers.
1.2 Mealy machine design: Browse through the state diagram on the next page first. Here, we perform
serial inspection of bits of A (or bits of A and B) to compare them. A is a 16-bit number, but
for this part of the question, B can be any where between 8-bit to 16-bit number. Here, we are
allowed to inspect at a time (in a clock) one bit of A (A[I]) and (simultaneously, if needed) one
bit of B (B[J]). The I and the J are indices into the A and B respectively. I is initialized to 15.
J is initiated to Jini (Jinitial) which can be anywhere between 7 through 15 (corresponding
to the B sizes of 8-bit to 16-bit ). You will be needing to compare I and J to see when they are
equal.
Note: Your TA says that ,after START is given, you should not take more than 16 clocks. After
all, A is 16 bits and B is at most 16 bits. So decrement I and/or J as soon as possible!
8
pts 1.2.1 Suppose B is an 8-bit number.
State an example of A and B (in binary) such that the conclusion is drawn in the least number of clocks.
A = _______________________________ ; B = _______________ ;
How many clocks are spent in INS_AI_BJ state for the above numbers? ________
State an example of A and B (in binary) such that the conclusion is drawn in the most number of clocks.
A = _______________________________ ; B = _______________ ;
How many clocks are spent in INS_AI_BJ state for the above numbers? ________
1.5
pts 1.2.2 Since A and B are negative, there is no point looking at A[15] and B[Jini]. True / False
2.5
pts 1.2.3 Since A’s size is fixed at 16-bit, if A is equal to B (equal in value, but not necessarily in size),
it takes the same number of clocks to compare A and B, irrespective of the size of B. True / False
RESET START
C_I_J
Compare I, J
I
Initial
A <= Aini; START
B <= Bini;
I <= 15;
J <= Jini;
INS_AI
Inspect A[I]
INS_AI_BJ
Inspect A[I],B[J]
ACK