DS2023-无代写-Assignment 2
时间:2023-05-09
DS 2023 Project Assignment 2
Professor Jonathan H. Manton
27 April 2023
Report Requirements
Refer to Practical Assignment 1 for report requirements.
Final Project Submission
In addition to the four project reports, you will also be required to submit your Quartus
project containing your final code, as a single Zip archive.
1 Clock
First we will finish the clock we started working on in assignment #1. Here is the
complete specification.
The time is to be displayed on the 7-segment displays (hours, minutes and seconds, in
24-hour format). The buttons perform the following functions.
KEY2 Set the time
KEY1 Up
KEY0 Down
Specifically, if KEY2 is pressed for one second or longer, the seconds digits will flash at
a rate of 2 Hz with a duty cycle of 80%, and the time stops advancing. Another press
(however short) of KEY2 will cause only the minutes digits to flash, and yet another
press will cause only the hours digits to flash, and one more press will cause the clock
to return to normal, with the time starting to advance again.
If some digits are flashing then the Up and Down keys (KEY1 and KEY0) can be used
to increment and decrement their combined value. If one of these keys is pressed for
less than half a second, the value should increment or decrement by unity. If pressed for
1
longer than half a second then the value should change rapidly, at a rate of ten numbers
per second (in other words, changing by one unit once per 1/10 of a second). (The
IFAdvance module from assignment #1 can be used to achieve this behaviour.)
1.1 Top-Down Design
Since we have built each of the parts we require, it is time to shift to a top-down design
approach. Always remember that a module is just like a chip with pins. We connect
modules together with wires. A block diagram can be used to show how we wish to
connect our modules together.
There are multiple ways of arranging our clock design into modules. For example, should
the Time module also generate the flashing, or should the flashing be handled elsewhere?
As a general principle, we wish to keep each module as small as possible, therefore, we
aim to generate the flashing elsewhere. Our proposed design is shown in Figure 1.
Time
Flash
KEY1KEY2 KEY0
Demulti-
plexer
Mode
Fast
Advance
Fast
Advance
7-Segment
Decoder
7-Segment
Decoder
7-Segment
Decoder
Binary to
Decimal
Binary to
Decimal
Binary to
Decimal
7-Segment
Decoder
7-Segment
Decoder
7-Segment
Decoder
7-Segment
Display
7-Segment
Display
7-Segment
Display
7-Segment
Display
7-Segment
Display
7-Segment
Display
Hours
Minutes
Seconds
Clock lines are not shown
Figure 1: Block diagram of our clock design. Besides the inputs and outputs, each rect-
angle represents a module. The dashed orange lines show how these modules
can themselves be arranged into modules.
2
1.2 Button Control
The lower left dashed rectangle in Figure 1 represents the module ButtonControl. It
comprises an instance of the module Mode and two instances of the module FastAdvance
(corresponding to IFAdvance in assignment #1). You are welcome to give these modules
more meaningful names!
The Mode module has a 2-bit output: 00 for normal mode, 01 for seconds adjust, 10 for
minutes adjust and 11 for hours adjust. Its 1-bit input must be a 1 for at least one
second in order to transition from 00 to 01. Transitioning from 01, then to 10, then to
11, then back to 00, merely requires the input to be a 1 for an arbitrarily short period
of time.
It is recommended you build your design piece-by-piece, checking each piece as you go.
1. Implement FastAdvance with the correct specifications. Connect its output to a
LED so you can check on the board that it works.
2. Implement Mode with the correct specifications. Connect its output to two LEDs
so you can check on the board that it works.
3. Implement ButtonControl that contains an instance of Mode and two instances of
FastAdvance. Connect its output to four LEDs so you can check it works.
Task 1
Show in your report the complete code for ButtonControl and all instantiated
modules inside it.
1.3 Flash Control
The upper left dashed rectange in Figure 1 represents the module FlashControl. It
comprises an instance of the module Flash and an instance of the module DeMUX4 (labelled
Demultiplexer in the figure).
You should already have your Flash module working from assignment #1. Double-check
it flashes at 2 Hz with a duty cycle of 80%.
Next, write the module DeMUX4 having the following specifications. It has a 1-bit input
in and a 2-bit input sel (for select). It has one 4-bit output out. At any one time,
all the four bits of out are zero, except for the sel-th bit which is equal to in, that is,
out[sel]=in. It sound be clear that this is a demultiplexer, serving to route in to the
sel-th output, so to speak. You can test DeMUX4 works by attaching switches to the
inputs and LEDs to the output bits.
The module FlashControl simply contains an instance of both Flash and DeMUX4. Its
input is a 2-bit number corresponding to which output (0 to 3) should be flashing. By
3
connecting two switches to the 2-bit input and four LEDs to the 4-bit output, you can
check the correct LED is flashing based on the switch settings.
Finally, you can replace the switches by an instance of the Mode module and check it
works.
Task 2
Show the full code in your report: KEY2 will control which LED is flashing.
1.4 Display
The upper right dashed rectangle in Figure 1 represents the module Display. It comprises
three instances of a module which converts from binary to decimal, and six instances
of 7-segment decoders. The binary to decimal module converts a 7-bit number into
two 4-bit numbers representing the tens and units. (You worked out how to do this
in assignment #1.) Do not worry about what it produces if the input is greater than
99. The 7-segment decoders function normally, but they also have an input called blank
which, if 1, will cause the 7-segment display to blank. This allows an instance of the
FlashControl module to flash the display.
Task 3
Show the full code of Display in your report.
Task 4
Wire up an instance each of ButtonControl, FlashControl and Display. Hard
code your favourite numbers to be displayed. Check the correct pair of digits are
flashing based on the history of how KEY2 has been pressed. Show the top-level
module in your report.
1.5 Digital Clock
Adding an instance of a Time module, as in Figure 1, will complete your clock imple-
mentation. Based on the incoming mode, Time will function as follows. In mode 0, time
is displayed normally, and the plus and minus inputs (coming indirectly from KEY1 and
KEY0) are ignored. In all other modes, the time does not increment on its own. Rather,
the plus and minus inputs increment or decrement the hours (mode 3), minutes (mode
2) or seconds (mode 1).
4
Task 5
Show in your report both your top-level module and your Time module. Note
that your top-level module should only include instances of Time, ButtonControl,
FlashControl and Display. Additionally, once your clock works, include the whole
code in an appendix to your report.
2 Stop Watch
For now, put your clock to one side, and start a new project in Quartus in which to build
a stop watch. (Assignment #3 will combine the clock with a stop watch and count-down
timer.) The stop watch will function as follows. It will display minutes, seconds and
hundredths of a second. KEY2 will reset the time to zero. KEY0 will start and stop
the running of the stop watch. (When running, it counts the time in hundredths of a
second.)
You should reuse the Display module (the upper right dashed rectangle in Figure 1).
Other than that, you just require a StopWatch module taking two inputs (driven by
KEY2 and KEY0).
Task 6
Once your stop watch is working, show the whole code in your report (except for
the Displaymodule). Comment on any difficult aspects, if any, in the development
of your code.
3 Count-down Timer
Once again, start a new project in Quartus, this time for building a count-down timer.
The timer will display hours, minutes and seconds. We will keep the complexity down by
having a simple means for setting the start time. KEY2 will reset the displayed time to
zero. KEY1 will increment the time by 1 second; by using an instance of the FastAdvance
module, we can increment the time rapidly by holding down KEY1. KEY0 will start
and stop the count-down timer: when started, it will count down by one second every
second, until it gets to zero, at which point it stops, and LED0 lights up. (In practice,
LED0 would be replaced by a beeper, but we do not have beepers at hand to connect
to the DE1-SoC board.) Pressing the reset button (KEY2) will also turn off LED0 (the
analogue of turning off the beeper in an actual count-down timer).
5
Task 7
Once your count-down timer is working, show the whole code in your report
(except for the Display module). Comment on any difficult aspects, if any, in the
development of your code.
4 Advanced
If you wish, you can combine the clock, stop watch and count-down timer to form a
working watch. Use KEY3 to switch mode: upon each press of KEY3, your watch
should cycle through the three modes: clock, stop watch and count-down timer. Use
LED9, LED8 and LED7 to show the current mode. Note that the clock, stop watch
and count-down timer should continue to operate in the background regardless of the
current mode.
If you get this to work, you can include your block diagram and your working code in
your next assignment (#3) in place of the guided design there.
If you wish to go even further, then add an alarm clock to your watch. That would
conclude the project - but if you really wish, you can also add a game to it.
Happy designing!
essay、essay代写