This repository has been archived by the owner on Jul 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwam_hrd.v
139 lines (128 loc) · 3.66 KB
/
wam_hrd.v
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
// Hardness control
//
// by nyLiao, April, 2019
module wam_tch ( // input button
input wire clk_19,
input wire btn,
output reg tch // active high
);
reg btn_pre; // button last status
wire btn_edg; // posedge trigger
reg [3:0] btn_cnt; // counter
always @(posedge clk_19) // posedge detection
btn_pre <= btn;
assign btn_edg = (~btn_pre) & (btn);
always @ (posedge clk_19) begin
if (btn_cnt > 0) begin // filtering
if (btn_cnt > 4'b0100) begin // stable
btn_cnt <= 4'b0000;
tch <= 1; // output status
end
else begin
if (btn_edg) begin // if button then back to idle
btn_cnt <= 0;
end
else begin // count
btn_cnt <= btn_cnt + 1;
end
end
end
else begin // idle
tch <= 0;
if (btn_edg) begin // if button pressed then start filtering
btn_cnt <= 4'b0001;
end
end
end
endmodule // wam_tch
module wam_hrd ( // hardness control
input wire clk_19,
input wire clr,
input wire lft,
input wire rgt,
input wire cout0,
output reg [3:0] hrdn // hardness of 0~9 or H (hard)
);
wire lfts; // stable left button
wire rgts; // stable right button
wire cout0s; // shorter carry signal
wire harder;
wire easier;
wam_tch tchl( .clk_19(clk_19), .btn(lft), .tch(lfts));
wam_tch tchr( .clk_19(clk_19), .btn(rgt), .tch(rgts));
wam_tch tchc( .clk_19(clk_19), .btn(cout0), .tch(cout0s));
assign easier = lfts;
assign harder = rgts | cout0s;
always @ (posedge clk_19) begin
if (clr)
hrdn <= 0;
else if (easier) begin // lft: easier
if (hrdn > 0) begin
hrdn <= hrdn - 1'd1;
end
end
else if (harder) begin // rgt or cout0: harder
if (hrdn < 10) begin
hrdn <= hrdn + 1'd1;
end
end
end
endmodule // wam_hrd
module wam_par ( // decide hardness parameters
input wire [3:0] hrdn,
output reg [3:0] age,
output reg [7:0] rto
);
always @ ( * ) begin
case (hrdn)
'h0: begin
age <= 4'd14;
rto <= 42;
end
'h1: begin
age <= 4'd11;
rto <= 62;
end
'h2: begin
age <= 4'd09;
rto <= 76;
end
'h3: begin
age <= 4'd07;
rto <= 87;
end
'h4: begin
age <= 4'd06;
rto <= 93;
end
'h5: begin
age <= 4'd05;
rto <= 96;
end
'h6: begin
age <= 4'd04;
rto <= 93;
end
'h7: begin
age <= 4'd04;
rto <= 87;
end
'h8: begin
age <= 4'd03;
rto <= 76;
end
'h9: begin
age <= 4'd03;
rto <= 61;
end
'hA: begin
age <= 4'd02;
rto <= 93;
end
default: begin
age <= 4'b0111;
rto <= 70;
end
endcase
end
endmodule // wam_par