标签:
1 同步复位
异步复位指复位不受时钟控制,但其他操作仍然与clk有关;同步复位指复位信号和时钟同步。
2 四位计数器的电路运行流程图
1)计数器verilog代码
`timescale 1ns/1ns
module count4(out,reset,clk);
input reset,clk;
output[3:0] out;
reg[3:0] out;
always @(posedge clk)
begin
if (reset)
out<=0; //同步复位
else
out<=out+1‘b1; //计数
end
endmodule
2) testbench测试文件
`timescale 1 ns/ 1 ns
module count4_vlg_tst();
/*Make a reset that pulses once.*/
reg reset=0;
initial
begin
#2 reset = 1; //reset
#3 reset = 0; //start count
#24 reset = 1; //reset
#2 reset = 0; //start count
#48 reset = 1; //reset
#1 reset = 0; //start count
#60 reset = 1; //reset
#3 reset = 0; //start count
#100 $stop;
end
/*Make a regular pulsing closk*/
parameter clk_period = 4;
reg clk;
initial
clk = 0;
always #(clk_period/2)
clk = ~clk;
wire[3:0] out;
count4 i1 (.clk(clk),.out(out),.reset(reset));
endmodule
标签:
原文地址:http://www.cnblogs.com/ffpp/p/4209121.html