-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab3.v
More file actions
244 lines (218 loc) · 6.78 KB
/
Copy pathlab3.v
File metadata and controls
244 lines (218 loc) · 6.78 KB
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
module lab3(
input CLOCK_50,
input [2:0] KEY,
input [9:0] SW,
output reg [6:0] HEX0,HEX1, HEX2, HEX3,
output [9:0] LEDR
);
//нажатие кнопок
wire start_stop,reset,mytask;
reg [2:0] start_stop_sync, mytask_sync, reset_sync=0;
always @(posedge CLOCK_50)
begin
start_stop_sync[0] <= KEY[0];
start_stop_sync[1] <= start_stop_sync[0];
start_stop_sync[2] <= start_stop_sync[1];
end
assign start_stop = (~start_stop_sync[2] & start_stop_sync[1]);
always @(posedge CLOCK_50)
begin
mytask_sync[0] <= KEY[1];
mytask_sync[1] <= mytask_sync[0];
mytask_sync[2] <= mytask_sync[1];
end
assign mytask = (~mytask_sync[2] & mytask_sync[1]);
always @(posedge CLOCK_50)
begin
reset_sync[0] <= KEY[2];
reset_sync[1] <= reset_sync[0];
reset_sync[2] <= reset_sync[1];
end
assign reset = (~reset_sync[2] & reset_sync[1]);
//нажатие кнопок
//счетчики
//стоп/пуск
/*reg device_running=0;
always @(*)
begin
if(reset) device_running=0;
else if(start_stop) device_running<=~device_running;
end*/
wire count=SW[9];
wire device_running=SW[8];
/*
reg count=1;
always @(*)
begin
if(reset) count=1;
else if(mytask) count<=~count;
end
*/
//стоп/пуск
//счётчик тактов выдающий сигнал о прошествии 1/100 секунды
reg [18:0] pulse_counter = 19'd0;
wire hundredth_of_second_passed = count?(pulse_counter == 19'd499999):(pulse_counter == 19'd0);
always @(posedge CLOCK_50 or posedge reset)
begin
if (reset) pulse_counter <= 0;//асинхронный сброс
else if(count)
begin
if ( device_running | hundredth_of_second_passed)
if (hundredth_of_second_passed) pulse_counter <= 0;
else pulse_counter <= pulse_counter + 1;
end
else
begin
if ( device_running | hundredth_of_second_passed)
if (hundredth_of_second_passed) pulse_counter <= 19'd499999;
else pulse_counter <= pulse_counter - 1;
end
end
//счётчик тактов выдающий сигнал о прошествии 1/100 секунды
//счётчик сотых долей выдающий сигнал о проществии 1/10 секунды
reg [3:0] hundredths_counter = 4'd0;
wire tenth_of_second_passed =count?((hundredths_counter == 4'd9) & hundredth_of_second_passed):((hundredths_counter == 4'd0) & hundredth_of_second_passed);
always @(posedge CLOCK_50 or posedge reset)
begin
if (reset) hundredths_counter <= 0;
else if(count)
begin
if (hundredth_of_second_passed)
if (tenth_of_second_passed) hundredths_counter <= 0;
else hundredths_counter <= hundredths_counter + 1;
end
else if(~count)
begin
if (hundredth_of_second_passed)
if (tenth_of_second_passed) hundredths_counter <= 9;
else hundredths_counter <= hundredths_counter - 1;
end
end
//счётчик сотых долей выдающий сигнал о проществии 1/10 секунды
//счётчик десятых долей выдающий сигнал о проществии 1 секунды
reg [3:0] tenths_counter = 4'd0;
wire second_passed = count ? ((tenths_counter == 4'd9) & tenth_of_second_passed) : ((tenths_counter == 4'd0) & tenth_of_second_passed);
always @(posedge CLOCK_50 or posedge reset)
begin
if (reset) tenths_counter <= 0;
else if(count)
begin
if (tenth_of_second_passed)
if (second_passed) tenths_counter <= 0;
else tenths_counter <= tenths_counter + 1;
end
else if(~count)
begin
if (tenth_of_second_passed)
if (second_passed) tenths_counter <= 9;
else tenths_counter <= tenths_counter - 1;
end
end
//счётчик десятых долей выдающий сигнал о проществии 1 секунды
//счётчик секунд выдающий сигнал о проществии 10 секунд
reg [3:0] seconds_counter = 4'd0;
wire ten_seconds_passed =count?((seconds_counter == 4'd9) & second_passed):((seconds_counter == 4'd0) & second_passed);
always @(posedge CLOCK_50 or posedge reset)
begin
if (reset) seconds_counter <= 0;
else if(count)
begin
if (second_passed)
if (ten_seconds_passed) seconds_counter <= 0;
else seconds_counter <= seconds_counter + 1;
end
else if(~count)
begin
if (second_passed)
if (ten_seconds_passed) seconds_counter <= 9;
else seconds_counter <= seconds_counter - 1;
end
end
//счётчик секунд выдающий сигнал о проществии 10 секунд
//счётчик десятков секунд
reg [3:0] ten_seconds_counter = 4'd0;
always @(posedge CLOCK_50 or posedge reset)
begin
if (reset) ten_seconds_counter <= 0;
else if(count)
begin
if (ten_seconds_passed)
if (ten_seconds_counter == 4'd9) ten_seconds_counter <= 0;
else ten_seconds_counter <= ten_seconds_counter + 1;
end
else if(~count)
begin
if (ten_seconds_passed)
if (ten_seconds_counter == 4'd0) ten_seconds_counter <= 9;
else ten_seconds_counter <= ten_seconds_counter - 1;
end
end
//счётчик десятков секунд
//счетчики
//вывод чисел
always @(*)
begin
case (hundredths_counter)
8'h0: HEX0 = 7'b1000000;//0
8'h1: HEX0 = 7'b1111001;//1
8'h2: HEX0 = 7'b0100100;//2
8'h3: HEX0 = 7'b0110000;//3
8'h4: HEX0 = 7'b0011001;//4
8'h5: HEX0 = 7'b0010010;//5
8'h6: HEX0 = 7'b0000010;//6
8'h7: HEX0 = 7'b1111000;//7
8'h8: HEX0 = 7'b0000000;//8
8'h9: HEX0 = 7'b0010000;//9
default: HEX0 = 7'b1111111;
endcase
end
always @(*)
begin
case (tenths_counter)
8'h0: HEX1 = 7'b1000000;//0
8'h1: HEX1 = 7'b1111001;//1
8'h2: HEX1 = 7'b0100100;//2
8'h3: HEX1 = 7'b0110000;//3
8'h4: HEX1 = 7'b0011001;//4
8'h5: HEX1 = 7'b0010010;//5
8'h6: HEX1 = 7'b0000010;//6
8'h7: HEX1 = 7'b1111000;//7
8'h8: HEX1 = 7'b0000000;//8
8'h9: HEX1 = 7'b0010000;//9
default: HEX1 = 7'b1111111;
endcase
end
always @(*)
begin
case (seconds_counter)
8'h0: HEX2 = 7'b1000000;//0
8'h1: HEX2 = 7'b1111001;//1
8'h2: HEX2 = 7'b0100100;//2
8'h3: HEX2 = 7'b0110000;//3
8'h4: HEX2 = 7'b0011001;//4
8'h5: HEX2 = 7'b0010010;//5
8'h6: HEX2 = 7'b0000010;//6
8'h7: HEX2 = 7'b1111000;//7
8'h8: HEX2 = 7'b0000000;//8
8'h9: HEX2 = 7'b0010000;//9
default: HEX2 = 7'b1111111;
endcase
end
always @(*)
begin
case (ten_seconds_counter)
8'h0: HEX3 = 7'b1000000;//0
8'h1: HEX3 = 7'b1111001;//1
8'h2: HEX3 = 7'b0100100;//2
8'h3: HEX3 = 7'b0110000;//3
8'h4: HEX3 = 7'b0011001;//4
8'h5: HEX3 = 7'b0010010;//5
8'h6: HEX3 = 7'b0000010;//6
8'h7: HEX3 = 7'b1111000;//7
8'h8: HEX3 = 7'b0000000;//8
8'h9: HEX3 = 7'b0010000;//9
default: HEX3 = 7'b1111111;
endcase
end
//вывод чисел
endmodule