首先在reg qout處就錯了,應該為reg 【15:0】 qout;
其次always @(posedge clk);後面沒有分號的,應去掉;
再者 qout[3:0]<=qout[3:0]+1後面缺少分號,應加上;
最後還沒有cout輸出訊號;
我在你的基礎上稍微改了下,仿了下是正確的,可以見模擬的波形圖
程式如下:
module count16 (
qout,clk,clear_n,incr_n,cout
);
output[15:0] qout;
output cout;
input clk; //clock
input clear_n;
input incr_n; //1start or 0stop
reg [15:0] qout;
reg cout;
always @(posedge clk)
begin
if (clear_n==0)
qout <= 16"b0;
cout <= 1"b0;
end
else begin
if(incr_n==0) qout <= qout;
else
if(qout[3:0]==4"h9)
qout[3:0] <=4"b0;
if(qout[7:4]==4"h9)
qout[7:4] <=4"b0;
if(qout[11:8]==4"h9)
qout[11:8] <=4"h0;
if(qout[15:12]==4"h9)
qout[15:12] <=4"b0;
cout <= 1"b1;
qout[15:12]<=qout[15:12]+1;
qout[11:8]<=qout[11:8]+1;
qout[7:4]<=qout[7:4]+1;
qout[3:0]<=qout[3:0]+1;
endmodule
首先在reg qout處就錯了,應該為reg 【15:0】 qout;
其次always @(posedge clk);後面沒有分號的,應去掉;
再者 qout[3:0]<=qout[3:0]+1後面缺少分號,應加上;
最後還沒有cout輸出訊號;
我在你的基礎上稍微改了下,仿了下是正確的,可以見模擬的波形圖
程式如下:
module count16 (
qout,clk,clear_n,incr_n,cout
);
output[15:0] qout;
output cout;
input clk; //clock
input clear_n;
input incr_n; //1start or 0stop
reg [15:0] qout;
reg cout;
always @(posedge clk)
begin
if (clear_n==0)
begin
qout <= 16"b0;
cout <= 1"b0;
end
else begin
if(incr_n==0) qout <= qout;
else
begin
if(qout[3:0]==4"h9)
begin
qout[3:0] <=4"b0;
if(qout[7:4]==4"h9)
begin
qout[7:4] <=4"b0;
if(qout[11:8]==4"h9)
begin
qout[11:8] <=4"h0;
if(qout[15:12]==4"h9)
begin
qout[15:12] <=4"b0;
cout <= 1"b1;
end
else
qout[15:12]<=qout[15:12]+1;
end
else
qout[11:8]<=qout[11:8]+1;
end
else
qout[7:4]<=qout[7:4]+1;
end
else
qout[3:0]<=qout[3:0]+1;
end
end
end
endmodule