0 24
/2
CE 2704 - Digital Logic Design
-2
Dr. Ehsan Ali
Assumption University of Thailand
l
ehsanali@au.edu
tia
Semester 2/2024
en
d
nfi
Co
Contents
24
1 Module 8 - Assignments Answers 2
1.1 Copyright Notice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
0
1.2 Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
/2
l -2
tia
d en
nfi
Co
1
Chapter 1
24
Module 8 - Assignments Answers
0
1.1 Copyright Notice
/2
This PDf file is generated by Dr. Ehsan Ali and contains the answers to all the assignments of mod-
ule 8 of CE2704 Digital Logic Design - academic semester 2/2024. The material in this PDF file is
copyrighted. and cannot be shared whatsoever to any third party or online websites, forums, etc.
l -2
tia
d en
nfi
Co
2
1.2 Assignments
1. How does a Verilog model for a D-flip-flop handle treating reset as the highest priority input?
By listing the reset condition as the first item in an if/then statement. In this way, the reset condition
will always be evaluated first.
2. For a Verilog model of a D-flip-flop with a synchronous enable (EN), why isn’t EN listed in the
sensitivity list?
24
Because EN is always treated as a synchronous signal so it is only evaluated when there is a
triggering edge of the clock.
3. For a Verilog model of a D-flip-flop with a synchronous enable (EN), what is the impact of listing
0
EN in the sensitivity list?
/2
Listing EN in the sensitivity list will cause a transition on EN to trigger the process. Since the
only signals that can trigger a D-flip-flop are the clock and reset lines, EN will be OR’d with one
of these signals in order to trigger action in the D-flip-flop.
4. For a Verilog model of a D-flip-flop with a synchronous enable (EN), why is the behavior of the
-2
enable modeled using a nested if-else statement under the else clause handling the logic for the
clock edge input?
Listing EN in the sensitivity list will cause a transition on EN to trigger the process. Since the
only signals that can trigger a D-flip-flop are the clock and reset lines, EN will be OR’d with one
of these signals in order to trigger action in the D-flip-flop.
l
5. What is the advantage of using parameters for the state when modeling a finite-state machine?
tia
You don’t need to worry about assigning the state codes, you instead allow the synthesizer to
assign them. This means you can design at a higher level of abstraction without worrying about
the lower-level details.
en
6. What is the advantage of having to assign the state codes during the parameter declaration for the
state names when modeling a finite-state machine?
It gives you control over the exact state codes to assign the states during synthesis. This can be
advantageous when trying to optimize the design for a certain parameter. You also can change the
d
encoding there.
7. When using the three-procedural block behavioral modeling approach for finite-state machines,
nfi
does the next state logic block model combinational or sequential logic?
Combinational logic.
8. When using the three-procedural block behavioral modeling approach for finite-state machines,
Co
does the state memory block model combinational or sequential logic?
Sequential logic.
9. When using the three-procedural block behavioral modeling approach for finite-state machines,
does the output logic block model combinational or sequential logic?
Combinational logic.
3
10. When using the three-procedural block behavioral modeling approach for finite-state machines,
what inputs are listed in the sensitivity list of the next state logic block?
The current state and the inputs.
11. When using the three-procedural block behavioral modeling approach for finite-state machines,
what inputs are listed in the sensitivity list of the state memory block?
Clock and Reset.
24
12. When using the three-procedural block behavioral modeling approach for finite-state machines,
what inputs are listed in the sensitivity list of the output logic block?
The current state and potentially the inputs.
0
13. When using the three-procedural block behavioral modeling approach for finite-state machines,
how can the signals listed in the sensitivity list of the output logic block immediately indicate
/2
whether the FSM is a Mealy or a Moore machine?
If only the current state is listed in the sensitivity list, it is a Moore machine.
14. Why is it not a good design approach to combine the next state logic and output logic behavior
into a single-procedural block?
-2
Because the next state logic may be sensitive to inputs that are different from the output logic. If
one process is used, the circuitry synthesized may be sensitive to inputs that aren’t supposed to
influence particular outputs. This can lead to glitches in the outputs.
15. Design a Verilog behavioral model to implement the finite-state machine described by the state
l
diagram in Fig. 1.23. Use the port definition provided in this figure for your design. Use the
tia
three-block approach to modeling FSMs described in this week for your design. Model the state
variables using parameters and encode the states in binary using the following state codes:
Start = "00" Midway = "01" Done = "10". As your answer include your both implementation
and simulation source code and functional simulation waveform.
en
State Diagram:
d
nfi
Co
4
Co
Design code:
nfi
d en
5
tia
l -2
/2
0 24
Simulation waveform:
0 24
/2
16. Design a Verilog behavioral model to implement the finite-state machine described by the state
diagram in Fig. 1.23. Use the port definition provided in this figure for your design. Use the
three-block approach to modeling FSMs described in this chapter for your design. Model the state
variables using parameters, and encode the states in one-hot using the following state codes:
-2
Start = "001", Midway = "010", Done = "100". As your answer include your both implemen-
tation and simulation source code and functional simulation waveform.
State Diagram:
l
tia
d en
nfi
Co
6
Co
Design code:
nfi
d en
7
tia
l -2
/2
0 24
Simulation waveform:
0 24
/2
17. Design a Verilog behavioral model to implement the finite-state machine described by the state
diagram in Fig. 1.24. Use the port definition provided in this figure for your design. Use the
three-block approach to modeling FSMs described in this chapter for your design. Model the state
variables using parameters and encode the states in binary using the following state codes:
-2
S0 = "00", S1 = "01", S2 = "10", and S3 = "11". As your answer include your both implementa-
tion and simulation source code and functional simulation waveform.
State Diagram:
l
tia
d en
nfi
Co
8
Co
Design code:
nfi
d en
9
tia
l -2
/2
0 24
0 24
/2
-2
Simulation waveform:
l
tia
d en
nfi
18. Design a Verilog behavioral model to implement the finite-state machine described by the state
diagram in Fig. Fig. 1.24. Use the port definition provided in this figure for your design. Use the
three-block approach to modeling FSMs described in this chapter for your design. Model the state
variables using parameters and encode the states in one-hot using the following state codes:
S0 = "0001", S1 = "0010", S2 = "0100", and S3 = "1000". As your answer include your both
Co
implementation and simulation source code and functional simulation waveform.
10
Co
State Diagram:
nfi
d en
11
tia
l -2
/2
0 24
Co
Design code:
nfi
d en
12
tia
l -2
/2
0 24
24
0
/2
l -2
Simulation waveform:
tia
d en
nfi
Co
13
19. Design a Verilog behavioral model for a 4-bit serial bit sequence detector similar to Example 2
in Section 1.2.1. Use the port definition provided in Fig. 1.25. Use the three-block approach to
modeling FSMs described in this chapter for your design. The input to your sequence detector
is called DIN and the output is called FOUND. Your detector will assert FOUND anytime there is
a 4-bit sequence of "0101". Model the states in this machine with parameters. Choose any state
encoding approach you wish. As your answer include your both implementation and simulation
source code and functional simulation waveform.
24
State Diagram:
0
/2
l -2
tia
d en
nfi
Co
14
Co
Design code:
nfi
d en
15
tia
l -2
/2
0 24
0 24
/2
Simulation waveform:
l -2
tia
20. Design a Verilog behavioral model for a 20-cent vending machine controller similar to Example 3
in Section 1.2.2. Use the port definition provided in Fig. 1.26. Use the three-block approach
to modeling FSMs described in this chapter for your design. Your controller will take in nickels
en
and dimes and dispense a product anytime the customer has entered 20 cents. Your FSM has
two inputs, Nin and Din. Nin is asserted whenever the customer enters a nickel, while Din
is asserted anytime the customer enters a dime. Your FSM has two outputs, Dispense and
Change. Dispense is asserted anytime the customer has entered at least 20 cents and Change
d
is asserted anytime the customer has entered more than 20 cents and needs a nickel in change.
Model the states in this machine with parameters. Choose any state encoding approach you wish.
nfi
Co
16
Co
State Diagram:
nfi
d en
17
tia
l -2
/2
0 24
Co
Design code:
nfi
d en
18
tia
l -2
/2
0 24
Co
nfi
d en
19
tia
l -2
/2
0 24
Co
nfi
d en
20
tia
l -2
/2
0 24
Co
nfi
d en
21
tia
l -2
/2
0 24
Co
nfi Simulation code:
d en
22
tia
l -2
/2
0 24
Simulation waveform:
24
21. Design a Verilog behavioral model for a finite-state machine for a traffic light controller. Use the
0
port definition provided in Fig. 1.27. This is the same problem we discussed before. This time,
you will implement the functionality using the behavioral modeling techniques presented in this
/2
week. Your FSM will control a traffic light at the intersection of a busy highway and a seldom
used side road. You will be designing the control signals for just the red, yellow, and green lights
facing the highway. Under normal conditions, the highway has a green light. The side road has car
detector that indicates when car pulls up by asserting a signal called CAR. When CAR is asserted,
-2
you will change the highway traffic light from green to yellow and then from yellow to red. Once
in the red position, a built-in timer will begin a countdown and provide your controller a signal
called TIMEOUT when 15 seconds has passed. Once TIMEOUT is asserted, you will change the
highway traffic light back to green. Your system will have three outputs GRN, YLW, and RED,
which control when the highway facing traffic lights are on (1 = ON, 0 = OFF). Model the states
in this machine with parameters. Choose any state encoding approach you wish.
l
State Diagram:
tia
d en
nfi
Co
23
Co
Design code:
nfi
d en
24
tia
l -2
/2
0 24
Simulation waveform:
0 24
/2
22. Design a Verilog behavioral model for a 16-bit, binary up counter using a single-procedural block.
The block diagram for the port definition is shown in Fig. 1.28.
Block Diagram:
l -2
tia
Design code:
d en
nfi
Simulation waveform:
Co
25
23. Design a Verilog behavioral model for a 16-bit, binary up counter with enable and load using a
single-procedural block. The block diagram for the port definition is shown in Fig. 1.29.
Block Diagram:
0 24
/2
Design code:
l -2
tia
en
Simulation waveform:
d
nfi
Co
26
24. In register transfer level modeling, how does the width of the register relate to the number of
D-flip-flops that will be synthesized?
Each bit within the register will result in one D-flip-flop being synthesized.
25. In register transfer level modeling, how is the synchronous data movement managed if all registers
are using the same clock?
The outputs of one register are routed to the inputs of other registers, typically through combina-
24
tional logic circuitry that manipulates the data. Since all outputs are created at the same time and
there is a finite delay from the outputs to the inputs, there is sufficient delay to avoid violating the
setup requirements of the receiving register.
26. Design a Verilog RTL model of a 32-bit, synchronous register. The block diagram for the port
0
definition is shown in Fig. 1.30. The register has a synchronous enable. The register should be
modeled using a single-procedural block.
/2
Block Diagram:
l -2
tia
Design code:
d en
nfi
Co
27
Simulation waveform:
0 24
/2
27. Design a Verilog RTL model of an 8-stage, 16-bit shift register. The block diagram for the port
definition is shown in Fig. 1.31. Each stage of the shift register will be provided as an output of the
system (A, B, C, D, E, F, G, and H). The shift register should be modeled using a single-procedural
block.
Block Diagram:
l -2
tia
d en
nfi
Co
28
Design code:
24
0
/2
l -2
tia
Simulation waveform:
d en
nfi
Co
29
28. Design a Verilog RTL model of the multi-drop bus topology in Fig. 1.32. Each of the 16-bit
registers (RegA, RegB, RegC, and RegD) will latch the contents of the 16-bit data bus if their
enable line is asserted. Each register should be modeled using an individual procedural block.
Block Diagram:
0 24
/2
l -2
tia
d en
nfi
Co
30
Co
Design code:
nfi
d en
31
tia
l -2
/2
0 24
Simulation waveform:
24
0
/2
l -2
tia
d en
nfi
Co
32