-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path74162.v
64 lines (52 loc) · 1.3 KB
/
74162.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
// 4-bit BCD decade counter with parallel load, synchronous clear
module ttl_74162 #(parameter WIDTH = 4, DELAY_RISE = 0, DELAY_FALL = 0)
(
input Clear_bar,
input Load_bar,
input ENT,
input ENP,
input [WIDTH-1:0] D,
input Clk,
output RCO,
output [WIDTH-1:0] Q
);
//------------------------------------------------//
wire RCO_current;
reg [WIDTH-1:0] Q_current;
wire [WIDTH-1:0] Q_next;
assign Q_next = Q_current + 1;
always @(posedge Clk)
begin
if (!Clear_bar)
begin
Q_current <= 4'b0000;
end
else
begin
if (!Load_bar)
begin
Q_current <= D;
end
if (Load_bar && ENT && ENP)
begin
case (Q_current)
// abnormal inputs above BCD 9: return to the count range
4'b1010: Q_current <= 4'b1001;
4'b1100: Q_current <= 4'b1001;
4'b1110: Q_current <= 4'b1001;
4'b1011: Q_current <= 4'b0100;
4'b1101: Q_current <= 4'b0000;
4'b1111: Q_current <= 4'b0000;
// normal inputs
4'b1001: Q_current <= 4'b0000;
default: Q_current <= Q_next;
endcase
end
end
end
// output
assign RCO_current = ENT && Q_current == 4'b1001;
//------------------------------------------------//
assign #(DELAY_RISE, DELAY_FALL) RCO = RCO_current;
assign #(DELAY_RISE, DELAY_FALL) Q = Q_current;
endmodule