實(shí)驗(yàn)描述:
輸入:
Clock:如果計(jì)數(shù)器enable信號(hào)為1,那么在時(shí)鐘上升沿,count加1
Enable:如果enable為1,那么在時(shí)鐘上升沿,count加1;如果enable為0,count保持不變
Reset:重置信號(hào),如果reset為0,count重置為0
輸出:
Count[3:0]:4位計(jì)數(shù)信號(hào),范圍:4‘b0000 – 4’b1111
實(shí)現(xiàn)代碼:
/********************
* By VastCosmic
* 2021/12/27
********************/
module count4(count,reset,clk,enable);
output[3:0] count;
input reset,clk;
input enable;
reg[3:0] count;
always @(posedge clk)
begin
if (reset)
count<=0;
else
begin
if(enable)
count<=count+1'b1;
end
end
endmodule
TestBench:
/******************
* By VastCosmic
* 2021/12/27
******************/
`timescale 1ns/1ns
module test;
reg reset = 0;
reg enable = 1;
initial
begin
#2 reset = 1; //reset
#5 reset = 0; //start count
#40 enable = 0; //stop count
#41 enable = 1; //count
#50 reset = 1; //reset
#50 reset = 0; //start count
#6000 $stop;
end
reg clk;
initial
clk = 0;
always #(clk)
clk = ~clk;
wire[3:0] out;
count4 ctr(out,reset,clk,enable);
endmodule
使用Vivado進(jìn)行仿真,仿真結(jié)果如下:
1.首先進(jìn)行reset,隨后開始正常計(jì)數(shù)
2.當(dāng)enable=0時(shí),暫停計(jì)數(shù),out保持不變
3.enable=1,繼續(xù)計(jì)數(shù)。
4.當(dāng)reset信號(hào)再次發(fā)出時(shí),將計(jì)數(shù)out重置為0。
5.下圖為正常計(jì)數(shù)狀態(tài):文章來源:http://www.zghlxwxcb.cn/news/detail-502193.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-502193.html
到了這里,關(guān)于(數(shù)字邏輯筆記)用Verilog實(shí)現(xiàn)4位計(jì)數(shù)器。(時(shí)序邏輯)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!