DD Lab4
DD Lab4
Lab 4
A simple combination lock
1 Introduction
The aim of the coursework assignment will be to design a combination lock using
VHDL and synchronous design techniques. The user interface will be simple and
based on use of the push buttons, slider switches, and LEDs on the FPGA board.
In this lab we will look at the basic techniques that will be needed, and produce a
simple prototype for part of the lock. In the assignment this prototype will be
extended and expanded to be more useful and to have more features.
Instead, we need to detect the transition of the button from “not pressed” to “pressed”.
The obvious was to do this is with the VHDL rising_edge() function. However,
this is likely to create a problem for the synthesis tool. The normal purpose of the
rising_edge() function is to create clock signals for flip-flops, but our button is
not the FPGA clock, so synthesis would be likely to fail if we use this method.
So we need a more complicated solution. This is based on the ideas of lectures 25 and
26. It works like this:
We create a new signal called “previous”, which is a copy of the button state but
lagging by one clock cycle. Creating a copy that lags by one clock cycle is easy:
we just put the signal assignment inside a process that is conditioned on the rising
edge of the clock.
We check for the condition button=’1’ and previous=’0’. This means that the
button has just been pressed
When the button has just been pressed, we set a signal called rise to ‘1’.
Here is the basic code:
process(clock)
begin
if rising_edge(clock) then
previous <= button;
if button=’1’ and previous=’0’ then
rise<=’1’;
else
rise<=’0’;
end if;
end if;
end process;
Modify your code so that when the button is pressed (rise=’1’) the system checks for
the appropriate number from the combination. If the number is correct we advanced to
the next state in the sequence. If the number entered is incorrect, we move back to the
state Init.
6 Improving the lock
So far we have a lock that, when it sees a wrong digit entered, will return to the initial
state and will let the user know that it is back in the initial state. This is nice for
debugging, but terrible for security as it makes it obvious when and where a wrong
number has been entered. Thieves would only need to try a very small set of numbers
before they can figure out what the correct combination should be.
Change the lock so that it will always consume four numbers, and only at the end of
the sequence of 4 numbers will give feedback on whether the combination was right
or wrong.
Increase the number of digits in your design to 6, with the last 6 digits of your ID
number as your passcode.