我是靠谱客的博主 高兴水杯,这篇文章主要介绍习题笔记 HDLBits Count clock,现在分享给大家,希望可以做个参考。

Create a set of counters suitable for use as a 12-hour clock (with am/pm indicator). Your counters are clocked by a fast-running clk, with a pulse on ena whenever your clock should increment (i.e., once per second).

reset resets the clock to 12:00 AM. pm is 0 for AM and 1 for PM. hh, mm, and ss are two BCD (Binary-Coded Decimal) digits each for hours (01-12), minutes (00-59), and seconds (00-59). Reset has higher priority than enable, and can occur even when not enabled.

The following timing diagram shows the rollover behaviour from 11:59:59 AM to 12:00:00 PM and the synchronous reset and enable behaviour.

复制代码
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
module top_module( input clk, input reset, input ena, output pm, output [7:0] hh, output [7:0] mm, output [7:0] ss); wire enable_s_10; wire enable_s_6; wire enable_m_10; wire enable_m_6; wire enable_h_12_10; wire enable_am_pm; assign enable_s_10 = ena; assign enable_s_6 = (ena & ss[3:0]==4'd9) ; assign enable_m_10 = (enable_s_6 & ss[7:4]==4'd5); //前一位的enable信号已经包含了ena=1,所以直接用前一数位的enable信号与前一数位的输出作进位条件 assign enable_m_6 = (enable_m_10 & mm[3:0]==4'd9); assign enable_h_12_10 = (enable_m_6 & mm[7:4]==4'd5); assign enable_am_pm = (enable_h_12_10 & hh[7:0]=={4'd1,4'd1}); //题干中为:a.m.12:00:00经过1、2、3...到a.m. 11:59:59 后变为p.m.12:00:00 到p.m. 11:59:59 //小时为11,且分,秒各个数位都要进位时,a.m.p.m翻转 //调用各个计数器 BCD_10_s_m ss_10 (clk,reset,enable_s_10,ss[3:0]); BCD_6 ss_6 (clk,reset,enable_s_6,ss[7:4]); BCD_10_s_m mm_10 (clk,reset,enable_m_10,mm[3:0]); BCD_6 mm_6 (clk,reset,enable_m_6,mm[7:4]); BCD_12_h hh_12 (clk,reset,enable_h_12_10,hh[7:0]); am_pm am_pm (clk,reset,enable_am_pm,pm); endmodule //秒、分个位的十进制计数器 module BCD_10_s_m ( input clk, input reset, input enable, output [3:0]q ); always @(posedge clk) begin if (reset) q <= 4'd0; else if (enable) q <= (q==4'd9 ? 4'd0: (q+4'b1)); end endmodule //秒、分十位的六进制计数器 module BCD_6 ( input clk, input reset, input enable, output [3:0]q ); always @(posedge clk) begin if (reset) q <= 4'd0; else if (enable) q <= (q==4'd5 ? 4'd0: (q+4'b1)); end endmodule //小时的两个数位的十二进制计数器 module BCD_12_h ( input clk, input reset, input enable, output [7:0]q ); always @(posedge clk) begin if (reset) q <= {4'd1,4'd2}; //reset时,小时为12 else if (enable) begin if (q[7:4]==4'd0) begin q[7:4] <= (q[3:0]==4'd9 ? 4'd1 : 4'd0); q[3:0] <= (q[3:0]==4'd9 ? 4'd0 : (q[3:0]+4'd1)); end else if (q[7:4]==4'd1) begin q[7:4] <= (q[3:0]==4'd2 ? 4'd0 : 4'd1); q[3:0] <= (q[3:0]==4'd2 ? 4'd1 :(q[3:0]+4'd1)); end end end endmodule //a.m. p.m. module am_pm ( input clk, input reset, input enable, output am_pm ); always @(posedge clk) begin if (reset) am_pm <= 1'b0; else if (enable) am_pm <= ~am_pm; end endmodule

最后

以上就是高兴水杯最近收集整理的关于习题笔记 HDLBits Count clock的全部内容,更多相关习题笔记内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(95)

评论列表共有 0 条评论

立即
投稿
返回
顶部