1.1 目录
(1)目录
(2)题目要求
(3)原理
(4)代码
1.2 题目要求
From a 1000 Hz clock, derive a 1 Hz signal, called OneHertz, that could be used to drive an Enable signal for a set of hour/minute/second counters to create a digital wall clock. Since we want the clock to count once per second, the OneHertz signal must be asserted for exactly one cycle each second. Build the frequency divider using modulo-10 (BCD) counters and as few other gates as possible. Also output the enable signals from each of the BCD counters you use (c_enable[0] for the fastest counter, c_enable[2] for the slowest).
The following BCD counter is provided for you. Enable must be high for the counter to run. Reset is synchronous and set high to force the counter to zero. All counters in your circuit must directly use the same 1000 Hz signal.
翻译:就是题目中给你一个1000hz的时钟,然后让你生成一个1hz的时钟(1hz时钟的名字就是OneHertz),题目中给了一个bcd计数器这个计数器,你要驱动这个给的bcd计数器去生成一个1hz的计数器。时钟为1000hz就是一个周期1ms,1hz代表一个周期1s,所以我们只需要计数1000个时钟周期就可以生成周期为1s的OneHertz信号。
“c_enable[0]用于最快的计数器,c_enable[2]用于最慢的计数器”这句话的意思c_enable[0]负责1000个数的个位计数,c_enable[1]负责1000个数的十位计数,c_enable[2]负责1000个数的百位计数
module bcdcount ( input clk,//就是1000hz的时钟 input reset, input enable,//使能信号,为高电平时才进行计数 output reg [3:0] Q//Q就是bcd计数器当前的计数值 );
1.3 原理
我们使用3个bcd计数器分别计数1000个数(0-999)的个位,十位,百位就可以了.当个位,十位,百位为3个9时就代表计数1000次,这时使OneHertz变为高电平就可以生成1hz的信号。
1.4 代码
module top_module (
input clk,//1000hz的时钟
input reset,
output OneHertz,
output [2:0] c_enable
); //
wire [3:0]Q1,Q2,Q3;//Q1,Q2,Q3分别代表个位,十位,百位的计数器输出
always@(*)
if(reset)begin
c_enable<=0;
OneHertz<=0;end
else
begin
c_enable[0]<=1;
c_enable[1]<=(Q1==9&&c_enable[0])? 1:0;//0~9是十个数,因此十位计数器只有当个位为9的时候才开始运行一次
c_enable[2]<=(Q2==9&&c_enable[1])? 1:0;//因此百位计数器只有当十位为9的时候才开始运行一次
OneHertz<=(Q1==9&&Q2==9&&Q3==9)?1:0;//当为999时,其实已经有0~999一共1000个数字了,此时为1s。
//1000HZ就是代表clk的周期为1ms。
end
bcdcount counter0 (clk, reset, c_enable[0],Q1);
bcdcount counter1 (clk, reset, c_enable[1],Q2);
bcdcount counter2 (clk, reset, c_enable[2],Q3);
endmodule