第1个回答 2015-07-27
module param_counter(
clk_in, reset, cnt_out
);
input clk_in;
input reset;
output [15:0] cnt_out;
//参数化调用,利用#符号将计数器的模值 10 传入被调用模块
cnt #(10) inst_cnt(
.clk_in(clk_in),
.reset(reset),
83
.cnt_out(cnt_out)
);
endmodule
被例化的参数化计数器的代码如下:
module cnt(
clk_in, reset, cnt_out
);
//定义参数化变量
parameter [15:0]Cmax = 1024;
input clk_in;
input reset;
output [15:0] cnt_out;
reg [15:0] cnt_out;
//完成模值可控的计数器
always @(posedge clk_in) begin
if(!reset)
cnt_out <= 0;
else
if(cnt_out == Cmax)
cnt_out <= 0;
else
cnt_out <= cnt_out + 1;
end
endmodule