Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity Security_Door is
--frequency of basys3 board clock
generic(freq : integer := 100000000);
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
C : in STD_LOGIC;
D : in STD_LOGIC;
E : in STD_LOGIC;
F : in STD_LOGIC;
U, V, W, X, Y, Z : out std_logic;
--buttons
SEND : in std_logic;
RESET : in std_logic;
--clock
clk : in std_logic;
--locked_test : out std_logic;
--for seven segment display
ANODE : out std_logic_vector (3 downto 0); --all digits declared although only 3 and 0 are used
LED_out : out STD_LOGIC_VECTOR (6 downto 0));
end Security_Door;
architecture Behavioral of Security_Door is
signal slow_clk_enable: std_logic;
signal Q1, Q2, Q2_bar, q0: std_logic;
--signal declarations
---user input
signal input : std_logic_vector(5 downto 0);
---hardset password
signal password : std_logic_vector(5 downto 0);
--count for displayed countdown
signal count : integer range 2 to 11;
--locked flag
signal locked: boolean := true;
--ticks to innumerate clock ticks
signal ticks: integer := 0;
--counters for flashing function
signal flashCount: integer;
signal flashCountX: integer;
--count for debouncing button (0.25 seconds)
constant buttonCount: integer := 25000000;
signal buttonReset: integer := 0;
type button_state is (idle, waiting, pressed);
signal user_in : button_state := idle;
signal send_in : button_state := idle;
signal reset_in : button_state := idle;
constant button_active : std_logic := '1';
signal buttonticks : integer := 0;
signal send_out : integer := 0;
signal reset_out : integer := 0;
signal send_pressed : boolean := false;
signal reset_pressed : boolean := false;
type LED_state is (flashing, lockedLED, unlockedLED);
signal LED : LED_state := lockedLED;
signal internalReset : boolean := true;
signal DB_SEND : std_logic;
signal o : std_logic;
begin
--concat input from switches into a vector to be able to compare it to the password
input <= A & B & C & D & E & F;
--declare password
password <= "110011";
--process(clk) is
--begin
--if rising_edge(clk) then
--case (user_in) is
--when idle =>
-- if (SEND = button_active) then
-- user_in <= waiting;
-- if (SEND = button_active) then
-- send_pressed <= true;
-- else
-- reset_pressed <= true;
-- end if;
-- else
-- --keep in idle until a button is pressed
-- user_in <= idle;
---- send_out <= 0;
---- reset_out <= 0;
-- end if;
-- when waiting =>
-- when pressed =>
--end case;
--end if;
--end process;
clock_enable_generator: entity work.clock_enable_debouncing_button PORT MAP
( clk => clk,
slow_clk_enable => slow_clk_enable
);
Debouncing_FF0: entity work.DFF_Debouncing_Button PORT MAP
( clk => clk,
clock_enable => slow_clk_enable,
D => SEND,
Q => Q0
);
Debouncing_FF1: entity work.DFF_Debouncing_Button PORT MAP
( clk => clk,
clock_enable => slow_clk_enable,
D => Q0,
Q => Q1
);
Debouncing_FF2: entity work.DFF_Debouncing_Button PORT MAP
( clk => clk,
clock_enable => slow_clk_enable,
D => Q1,
Q => Q2
);
Q2_bar <= not Q2;
DB_SEND <= Q1 and Q2_bar;
--main
main:
process(clk) is
begin
if rising_edge(clk) then
if (DB_SEND = '1' and internalReset) then
--password is right
if (input = password) then
locked <= false;
--locked_test <= '0';
ticks <= 0;
count <= 11;
LED <= unlockedLED;
internalReset <= false;
if ticks = freq - 1 then --after one second
ticks <= 0;
--relocks after 10 seconds
if count = 0 then
locked <= true;
--locked_test <= '1';
LED <= lockedLED;
--send_out <= 0; --reset send_out to prevent infinite loop
--user has to reset
internalReset <= true;
else
--decrease count after a second
count <= count - 1;
end if;
else
ticks <= ticks + 1;
end if;
--if password is wrong, user has to reset after
else
locked <= true;
--locked_test <= '1';
--flashing lights (until reset?)
ticks <= 0;
--flashcount will change 20 times -> 10 on 10 off -> for 5 seconds
flashCount <= 20;
LED <= lockedLED;
internalReset <= false;
if ticks = 4999 then
ticks <= 0;
if flashCount = 0 then
LED <= lockedLED;
locked <= true;
--locked_test <= '1';
--send_out <= 0;
internalReset <= true;
else
flashCount <= flashcount - 1;
end if;
else
ticks <= ticks + 1;
end if;
end if;
--if send is not pressed nothing happens
else
locked <= true;
--locked_test <= '1';
LED <= lockedLED;
internalReset <= true;
end if;
end if;
end process;
process (flashCount, count, locked, LED)
begin
ANODE <= "1111";
LED_out <= "1111111";
case (LED) is
when flashing =>
ANODE <= "0000";
if ((flashCount mod 2) = 0) then
LED_out <= "1111111";
else
LED_out <= "1111110";
end if;
when unlockedLED =>
ANODE <= "1110";
case count is
--when 1 => LED_out <= "0000001"; -- "0" --display of U is one second, so numbers displayed will be 9-1
when 2 => LED_out <= "1001111"; -- "1"
when 3 => LED_out <= "0010010"; -- "2"
when 4 => LED_out <= "0000110"; -- "3"
when 5 => LED_out <= "1001100"; -- "4"
when 6 => LED_out <= "0100100"; -- "5"
when 7 => LED_out <= "0100000"; -- "6"
when 8 => LED_out <= "0001111"; -- "7"
when 9 => LED_out <= "0000000"; -- "8"
when 10 => LED_out <= "0000100"; -- "9"
when 11 => LED_out <= "1000001"; -- "U"
end case;
when lockedLED =>
ANODE<= "0111";
LED_out <= "1110001";
end case;
end process;
end Behavioral;