//2digit BCD counter verilog + Modelsim simulation
//top-level module for 2-digit BCD counter 00-->99
//
module bcdcounter(clk,reset,one_out,ten_out);
input clk,reset;
output [3:0] one_out,ten_out;
wire nreset,ones_en,tens_en,tc_ones; //tc_ones --> 1's carry out
wire [3:0] one_out , ten_out;
// module cnt_10(ce,clk,clr,tc,qout);
cnt_10 _1s (.ce(ones_en),
.clk(clk),
.clr(nreset),
.tc(tc_ones), //1's carry out
.qout(one_out));
cnt_10 _10s (.ce(tens_en),
.clk(clk),
.clr(nreset),
.tc(), //10's carry out ignore
.qout(ten_out));
assign tens_en=tc_ones;
assign ones_en =1'b1;
assign nreset=~reset;
endmodule
//===========================================
//BCD counter counts 0 to 9 and then rolls over
module cnt_10(ce,clk,clr,tc,qout);
input ce,clk,clr;
output tc; //carry out
output [3:0] qout;
reg [3:0] count;
always @(posedge clk or posedge clr)
begin
if (clr) //clear
count <=4'b0;
else
if (ce)
if (count==4'h9)
count <=4'h0;
else
count <= count +1;
end
assign qout = count ;
assign tc=(count==4'h9); //if count=9 then carry out=1
endmodule
//============================================
module testbench();
//inputs
reg clk,reset;
//outputs
wire [3:0] one_out ,ten_out;
//Instantiate UUT
bcdcounter UUT (.clk(clk),
.reset(reset),
.one_out(one_out),
.ten_out(ten_out));
//initial inputs
initial
$monitor ($time,"clk=%b, reset=%b ,ten_out=%d , onr_out=%d",clk,reset,ten_out,one_out);
initial
begin
clk=0;
reset=0;
#35 reset=1;
end
initial
begin
forever #10 clk=~clk;
end
initial
#400 $finish;
endmodule
//============================================
訂閱:
張貼留言 (Atom)
WOKWI DHT22 & LED , Node-Red + SQLite database
WOKWI DHT22 & LED , Node-Red + SQLite database Node-Red程式 [{"id":"6f0240353e534bbd","type":"comment&...
-
python pip 不是内部或外部命令 -- 解決方法 要安裝 Pyqt5 1. 首先,開啟命令提示字元。 2. 輸入 pip3 install pyqt5 好像不能執行 ! ! 錯誤顯示 : ‘ pip3 ’ 不是內部或外部命令、可執行的程式或批...
-
課程講義 下載 11/20 1) PPT 下載 + 程式下載 http://www.mediafire.com/file/cru4py7e8pptfda/106%E5%8B%A4%E7%9B%8A2-1.rar 11/27 2) PPT 下載...
-
• 認 識 PreFix、InFix、PostFix PreFix(前序式):* + 1 2 + 3 4 InFix(中序式): (1+2)*(3+4) PostFix(後序式):1 2 + 3 4 + * 後 序式的運算 例如: 運算時由 後序式的...
沒有留言:
張貼留言