-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtsj.v.bak
62 lines (53 loc) · 1.48 KB
/
qtsj.v.bak
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
/*启停电路*/
module qtsj(clk_quick,clk_slow,clk_delay,clr,rst,SW_choose,A1,cpustate,clk_run,clk_choose);
input clk_quick,clk_slow;
input clk_delay;
input clr;
input rst;
input SW_choose;
input A1;//按钮
input [1:0] cpustate;
output clk_run,clk_choose;
reg A_d1,A_d2,clk_enable;
reg clr_d1,clr_d2;
wire reset;
wire A_Neg;
wire clr_Neg;
//wire clk_choose;
//wire clk_run;
assign reset = rst&(cpustate == 2'b11);
assign clk_choose = (SW_choose)?clk_quick:clk_slow;
always @(posedge clk_delay or negedge reset)//将A1延时1个时钟
begin
if(!reset) A_d1 <= 1;
else A_d1 <= A1;
end
always @(posedge clk_delay or negedge reset)//将A1延时2个时钟
begin
if(!reset) A_d2 <= 1;
else A_d2 <= A_d1;
end
assign A_Neg = (~A_d1)&A_d2;//若A1有效,则将A1变为延时1个时钟的有效脉冲信号
always @(posedge clk_choose or negedge reset)//将clr延时1个时钟
begin
if(!reset) clr_d1 <= 1;
else clr_d1 <= clr;
end
always @(posedge clk_choose or negedge reset)//将clr延时2个时钟
begin
if(!reset) clr_d2 <= 1;
else clr_d2 <= clr_d1;
end
assign clr_Neg = (~clr_d2)&clr_d1;//若clr有效,则将clr变为延时1个时钟的有效脉冲信号
always @(posedge clk_delay or negedge reset)//A1有效时,clk_enable为1;clr有效时,clk_enable为0
begin
if(!reset) clk_enable <= 0;
else
begin
if(clr_Neg) clk_enable <= 0;
else if(A_Neg) clk_enable <= 1;
else clk_enable <= clk_enable;
end
end
assign clk_run = clk_choose & clk_enable;//生成clk_run时钟信号
endmodule