我需要修改这个环计数器,以从最重要的位转移到最小的位,然后重置回最重要的位。输出应该如下所示:
100000
010000
001000
000100
000010
000001
100000 环计数器
module ringcounter(clk, rst, count);
input clk, rst;
output [5:0] count;
wire clk, rst;
reg [5:0] count = 6'b1;
// Respond to the positive-going pulse edge
always @ ( posedge clk )
begin
if ( ~rst )
begin
count <= count << 1;
count[0] <= count[5];
end
end
// Respond to the positive-going reset signal
always @ ( posedge rst )
begin
count <= 6'b1;
end
endmodule 环计数器测试平台
module ringcounter_tb();
reg clk = 0, rst = 0;
wire [5:0] count;
always #1 clk = !clk; // Create a clock pulse
initial begin
$monitor("At time %4t, count = %b", $time, count );
#20 rst = 1;
#1 rst = 0;
#20 $finish;
end
ringcounter cntr01 ( .clk(clk), .rst(rst), .count(count) );
endmodule 我对数字逻辑还是很陌生的,所以请容忍我。我只是有点困惑,不知道该如何修改这个戒指计数器。任何类型的帮助,或解释这将如何工作,将是非常感谢的。
发布于 2015-12-07 04:47:14
这里的问题不太清楚。但是有几件事情要被修改。
首先,从不在两种不同的 always块中使用相同的变量。只需将rst添加到敏感性列表即可。如下所示:
// sensitive to clock and reset both
always @ ( posedge clk, posedge rst )
begin
if ( ~rst )
begin
count <= count << 1;
count[0] <= count[5];
end
else
count <= 8'b1;
end 使用边缘敏感的 always块会导致触发器创建。如果这是在两个不同的块中完成的,那么综合问题就会出现。这可以由您想要的逻辑在门和寄存器方面可视化。
此外,在时钟生成期间,建议使用按位否定(~)。
!符号表示布尔值或逻辑否定。而~符号则表示按位否定。
// Replace this
always #1 clk = !clk;
// With this
always #1 clk = ~clk;在rst之后应用20ns,在20ns之后终止模拟,这不是您想要的。您可能想要使用#200 $finish;代替。
这些都是我想要说清楚的几点。我在EDAPlayground在这里模拟了代码,也许您想要看到波形,这似乎是根据所讨论的那个。
从此PDF中可以得到更多关于合成的指南。
发布于 2015-12-07 04:27:42
https://gist.github.com/vividvilla/4605985
这应该是可行的,它包含测试工作台以及程序的输出:)
https://stackoverflow.com/questions/34126238
复制相似问题