Digital Design Exercise - FPGA Implementation of A Matrix Keyboard Encoder
Digital Design Exercise - FPGA Implementation of A Matrix Keyboard Encoder
Digital Design Exercise - FPGA Implementation of A Matrix Keyboard Encoder
Contents
1 Introduction .................................................................................................................. 1
2 Background on Matrix Keyboard Encoders ................................................................... 1
3 Simulating the Keyboard Encoder ................................................................................. 2
4 Requirements for the Logic Primitives Version ............................................................. 2
5 Simulating the Primitives Version ................................................................................. 2
6 Requirements for the VHDL Version ............................................................................. 3
7 Simulating the VHD Version .......................................................................................... 4
8 Additional Points to Consider ........................................................................................ 4
9 Requirements for Signal Naming ................................................................................... 4
10 Approach to the Design Work ....................................................................................... 5
11 Software Tools and Tutorials ......................................................................................... 5
12 Guidance on Writing the Report ................................................................................... 6
13 Required Report Structure ............................................................................................ 7
14 Mark Scheme .............................................................................................................. 10
1 Introduction
You are required to design a fully digital, hardware-based keyboard encoder for a 16-key (4×4)
matrix keyboard. Your design is to be implemented using an FPGA and verified by simulation but
must be targeted at the specified development boards.
You will use two approaches to design development. First you are required to produce a
simple/minimal implementation using logic primitives (basic gates and flip flops). Secondly you are
to produce a (more) fully capable design using VHDL. Both designs are to be verified by simulation.
More detailed specifications and requirements are given later in this document.
1
3 Simulating the Keyboard Encoder
The matrix keyboard provides a challenge for simulating the keyboard encoder. The encoder will put
signals onto some wires of the keyboard matrix and receive input from others. When setting up a
simulation it may seem that should be possible to predict the response of the keyboard and
therefore manually setup the correct simulation input signals corresponding to the required key
presses. However, this approach is potentially flawed – if there are problems with driving signals due
to issues with the design the predicted signals will not match the actual behaviour of the circuit.
Furthermore, if the design involves feedback (the driving signals change in response to key presses)
trying to set up exactly the right simulation inputs may be difficult even for a functionally correct
design.
To overcome these issues a simulation model of the keyboard is provided for use in this exercise.
Full details are provided in the separate document “Simulating the Keyboard in the Keyboard
Encoder Design Exercise”. The keyboard model forms part of the VHDL test bench. The document
provides a walkthrough for using the keyboard model, and relevant code snippets are available for
download. The example will have to be adapted for your simulation, for example the timing and
sequence of keypresses in the example are unlikely to match what you require in your simulation.
although you may use different signal names. You will need to define an additional 4-bit signal for this.
Again this is detailed in the “Simulating the Keyboard in the Keyboard Encoder Design Exercise”
document.
As in the example, your testbench will need to include keypress signals, for which you will need a
signal definition, again as shown in the example. The keypresses simulated will need to be different
from those in the example – the timing of the example may be different, and you should only activate
one key at a time, whereas the example includes simultaneous keypresses.
3
6. The encoder must cope with key bounce of up to 10 ms without giving false outputs.
7. If one or more additional keys are pressed after the first key has been pressed, but while it is
still being held, then they are ignored, even if the first key is released before the others.
8. If one or more additional keys are pressed simultaneously (that is within a time shorter than
that in which the encoder can distinguish the order in which they were pressed) then a single
“key-pressed” indication should be given and the output code may relate to any of the keys
which have been pressed.
The system is expected to have one primary clock input (the 50 MHz FPGA clock input on the
development board) and possibly a master reset in addition to the I/O implied by the above
requirements.
Your design should comply with design guidelines provided by the FPGA manufacturer.
4
Where nnnnn are the last five digits of your student number. For example, if your student number
was 201712345 you would name your signals
S1_12345 and S2_12345
All other significant blocks/subsystems must have at least one input or output “tagged” with your
student number in a similar way.
This is important – If you fail to follow this naming requirement in all relevant schematics, block
diagrams, code, and simulation waveform you will lose significant marks. This applies to both the
primitives and VHDL versions. Make sure that any code listings or screenshots you include have all
relevant signal names clearly visible and readable (e.g. not hidden or blurry).
5
12 Guidance on Writing the Report
Marks will the strongly dependent on the degree to which you conform to these guidelines. That is,
even if you produced a good working design you will receive poor marks if it is poorly documented.
This work is not an experiment, it is a piece of design work. It must not be written up as if it were an
experiment. The purpose of the report should be to document the final, correct design and prove that
it meets the requirements specified.
You do not need to repeat large sections of the material from the background document “Matrix
Keyboard Encoders – Background for the Digital Design Exercise” as background in your report. You
can assume the reader of your report is familiar with this material. If necessary, you can specifically
reference this document in your report to support your discussion. If you use additional background
material from other sources this should be described in more detail and correctly referenced.
You can assume the reader of your report is familiar with, digital electronics, VHDL and the design
tools. Do not include basic background/theory material on these topics. Do not describe how to use
the design tools. This is already well documented. You can assume the reader of your report is familiar
with the design tools.
You should repeat the specifications from the sections 4 and 6 of this document, so that you report is
self-contained in terms of specification details. The specification numbers be used to identify
specifications where appropriate in your explanations and discussion. However, do not copy other
text from the handouts.
Report the final correct design as it is at the end of your development work. Do not describe early
versions or mistakes you made during development. Do not describe the development as a step-by-
step process. Your designs should be described with explicit reference to the requirements specified
in sections 4 and 6 – explain how your design achieves the requirements.
Provide top-down explanation of the operation of your designs with reference to block diagrams
before describing them in more detail. For this purpose, block diagrams should ideally be drawn in
simplified format which makes them clear (e.g. like figures 8 and 9 in the background document),
rather than using the top-level schematic from the design tool. However, you should also include the
top-level schematic. Explanations of circuit operation may also benefit from simplified waveform
diagrams (not simulation output) (e.g. figure 3 in the background document). You should highlight
features which relate to the specifications with explicit reference to the requirements. If your design
did not cover all requirements you should make it clear which requirements you have covered.
Your schematics and block diagrams should be placed in the main body of the report close to where
they are discussed in the text. Make sure that all labelling text on these diagrams (block and signal
names etc.) would be clearly and easily readable in a printed version of your report. That is, you should
screen-snip schematics etc. but make sure the zoom level used delivers an image with readable text.
You should include fragments of code in your report where these are required to assist your
description, but do not include every line in the main body of the report. All your code should be
available in appendices of your report and these should be referred to when the relevant part of the
design is discussed. Your code is expected to contain an appropriate level of comments. All code must
be presented in the report as text (not screenshots) a non-proportional font such as Courier New and
must be well laid-out in terms of indentation, line-spacing etc. It is suggested that you the
Programmer’s Notepad app which can export code as RFT with syntax colouring, which you can then
import into a Word document.
You report text must provide explanation and justification, not just description and figure references.
For example, it is not sufficient to simply state “figure x shows the schematic for y” without any
explanation of circuit y. Furthermore, do not just describe the structure or form of a circuit or
6
waveform – this is covered by the graphic. For example the following is very poor text to accompany
a schematic
“The circuit in figure x is some logic which uses an AND gate, two OR gates and an inverter
to convert from the 4-bits used by the keyboard to the 2-bits required for the output value.”
The following is much better because it explains exactly what the circuit is and why it is used, rather
than just describing the wiring or look of the schematic. There is an implication that the method used
(priority encoder) has already been justified in the top-level system overview. Also note the use of
references [] and the relating of the design to specific specification requirements.
“The row decoder has four row inputs (RI<4:1>), which will be active-1 during a keypress.
Its two outputs (RV<1:0>) contribute to the binary key value. As discussed in section v the
active row can be mapped to the upper two bits of the key value using a priority encoder.
The schematic, shown in figure w, is a widely available (e.g. [x] and [y]) implementation of
a 4-to-2 priority encoder. The circuit’s truth table is given in figure z [x]. It can be seen that
row-to-value encoding matches that in figure q and thus this circuit provides partial
implementation of specification requirement 2.”
Describe your verification strategy with explicit reference to the requirements specified in sections 4
and 6. Present simulation results which efficiently prove that the requirements are met. Highlight how
the results prove that you design has met the requirements specified in sections 4 and 6. Annotated
you waveforms (e.g. with arrows, circles etc. highlighting specific features) to make it as easy as
possible for the reader to assimilate the key results without wading through large amounts of detail.
Do not present large numbers of waveforms which do not add any useful additional insights. Include
waveforms in the main body of the report close to where they are discussed. If necessary, further, less
important, simulation results may be included in appendices.
Make sure that all text on simulation waveforms would be clearly and easily readable in a printed
version of your report. Make sure that all waveforms have timescales and signal names clearly visible.
Do include large areas of black space in your waveform screenshots. You may need to adjust the
window layout in the design tool prior to snipping the screen to achieve these requirements.
Your report must have a conclusion in which you summarise the work presented and discuss the
capabilities and performance of your design, indicating where there might be room for improvement
in future work. You should also reflect briefly on the differences between schematic-based and HDL-
based design. This, like the whole, report must be written in a formal and professional style. Do not
include direct descriptions of personal experience or reflections on your learning in this report.
All diagrams, simulation waveforms, code fragments etc. must be given figure numbers, explicitly
referred to by figure number and properly discussed in the text. Sections with section titles and
figures, but no body text are not acceptable. If you simply place a lot of waveforms etc. in the report
without referring to them or discussion them they may be discounted (not regarded as present in the
report).
All appendices containing code etc. must be referred to in the main body of the text when the relevant
section of the design is discussed.
7
1. Introduction Overview of the project with very brief introduction to
keyboard encoders but reference the handout rather
than repeating large chunks.
2. Specification Statement of specifications (copy specification from
handout, numbered for easy reference). Comment on
specifications if required (e.g. if any ambiguities were
resolved, or if it was decided not to implement particular
requirements prior to starting the design work).
2.1 Primitives Version Overview Top level description with reference to a simplified block
diagram (ideally not the top-level schematic) and also
simplified waveforms if needed. Explain system
operation and how the specification is achieved.
2.2 Primitives Version Detailed Design For each block
Present the schematic, define its inputs and outputs and
explain how it works, referencing the top-level
description where appropriate. Where appropriate,
explain how the design enables a particular specification
to be met. If appropriate provide design information
such as logic equations, truth tables, state diagrams.
Reference sources (e.g. of schematics) if you used
circuits from elsewhere.
2.3 Primitives Version Block If you deemed it appropriate to simulate (and present)
Verification particular blocks on their own describe the results for
each such block here.
In each case
Describe the simulation set up (e.g. what inputs were
provided and why?). Give details of any special code
required in the test bench (i.e. other than to just
generate the input waveforms)
Present the simulation results and explain how they
prove the circuit is operating correctly. Annotate the
waveform if required to assist with the explanation.
2.4 Primitives Version System You may need to perform more than one simulation to
Verification cover all requirements in the specification. Present these
in a logical order (most basic operations first).
For each simulation
Describe the simulation set up (e.g. what inputs were
provided and why?). Give details of any special code
required in the test bench (i.e. other than to just
generate the input waveforms). Note that any common
set-up information (relevant to all simulations) should be
covered once, before the individual sections.
Present the simulation results and explain how they
prove the system meets one or more of the
specifications. Be specific in referring to the
8
specifications. Annotate the waveform if required to
assist with the explanation.
3.1 VHDL Version Overview Top level description with reference to a simplified block
diagram (ideally not the top-level schematic) and also
simplified waveforms if needed. Explain system
operation and how the specification is achieved.
3.2 VHDL Version Detailed Design For each block
Define its inputs and outputs (ports). Present code
snippets and explain how it works, referencing the top-
level description where appropriate. Where appropriate,
explain how the implementation enables a particular
specification to be met. If appropriate provide design
information such as logic equations, truth tables, state
diagrams. Reference sources if you used code from
elsewhere.
3.3 VHDL Version Block Verification If you deemed it appropriate to simulate (and present)
particular blocks on their own describe the results for
each such block here.
In each case
Describe the simulation set up (e.g. what inputs were
provided and why?). Give details of any special code
required in the test bench (i.e. other than to just
generate the input waveforms)
Present the simulation results and explain how they
prove the circuit is operating correctly. Annotate the
waveform if required to assist with the explanation.
3.4 VHDL Version System Verification You may need to perform more than one simulation to
cover all requirements in the specification. Present these
in a logical order (most basic operations first).
For each simulation
Describe the simulation set up (e.g. what inputs were
provided and why?). Give details of any special code
required in the test bench (i.e. other than to just
generate the input waveforms). Note that any common
set-up information (relevant to all simulations) should be
covered once, before the individual sections.
Present the simulation results and explain how they
prove the system meets one or more of the
specifications. Be specific in referring to the
specifications. Annotate the waveform if required to
assist with the explanation.
Discussion Summarise the outcome of the design process. Did the
designs meet all the specifications, if not what is lacking?
Are there any other highlights or issues with the design
9
should be discussed? Are there any problems inherent in
the specifications (there may not be)?
Discuss the relative merits of the approaching a design
using schematics built from primitive logic elements
versus use of hardware description languages.
Conclusion Summarise the key outcomes of the work and if
necessary state what future work would still be required.
14 Mark Scheme
The report will be marked according to the following scheme. There is strong dependence on the
degree to which the specifications have and been correctly met, and shown to be met. Marks for
design and simulation elements may be significantly reduced if the presented schematics and
waveforms do not conform the naming convention described in section 9.
Report presentation (max 20%)
Overall quality of language, structure and organisation of the report. Quality of diagrams. Level of
conformance with format and presentational (figure numbering and figure referencing etc.).
Primitives System Design (max 15%)
Clarity and correctness of top level overview. Clarity and correctness of detailed design description.
Degree to which requirements are met.
Primitives System Simulation (max 15%)
Clarity and correctness of verification description and discussion. Degree to which requirements are
correctly verified.
VHDL System Design (max 20%)
Clarity and correctness of top level overview. Clarity and correctness of detailed design description.
Degree to which requirements are met.
VHDL System Simulation (max 20%)
Clarity and correctness of verification description and discussion. Degree to which requirements are
correctly verified.
Discussion/conclusions/evaluation (max 10%)
Quality of the discussion on design capabilities/limitations with respect to the specification and
possible applications. Quality of brief reflection on schematic vs HDL design. Quality of discussion on
possible improvements/further work.
10