1.普通4bit计数器,n位计数,2^n个状态:
module top_module ();
reg clk=0;
always #5 clk = ~clk; // Create clock with period=10
initial `probe_start; // Start the timing diagram
`probe(clk); // Probe signal "clk"
// A testbench
reg reset;
initial begin
reset=0;
#10 reset=1;
$display ("Hello world! The current time is (%0d ps)", $time);
#50 $finish; // Quit the simulation
end
count inst1 (.clk(clk),.reset(reset)); // Sub-modules work too.
endmodule
module count(clk, reset, out);
output [3:0] out;
reg [3:0] out;
input clk,reset;
always @(posedge clk) begin
if (reset==0)
out<=0;
else
out<=out+1;
end
`probe(clk); // Sub-modules can also have `probe()
`probe(out);
endmodule
结果:

最低0.47元/天 解锁文章
975

被折叠的 条评论
为什么被折叠?



