zcy0517 发表于 2014-3-14 08:58:04

verilog模块调用

本帖最后由 zcy0517 于 2014-3-14 09:28 编辑

虽然是基础,但想做个记录,并且和大家分享一下~{:lol:}
调用方法有两种:
1、模块名 实例化名(连接端口1信号名,连接端口2信号名);(位置要严格与调用模块端口对应)
2、模块名 实例化名(.端口1名(连接端口1信号名),.端口2名(连接端口2信号名));

对于调用子模块内有parameter的,可如下把parameter里的参数改成4和1
模块名#(4,0)实例化名 (连接端口1信号名,连接端口2信号名);

zcy0517 发表于 2014-3-14 09:47:13

module Multplier(Outcome,A,B);
parameter size_A=8,size_B=8;
input A;
input B;
output[(size_A+size_B):1] Outcome;
reg[(size_A+size_B):1] temp_a,Outcome;
reg temp_b;
always @(A or B)
begin
Outcome=0;
temp_a=A;
temp_b=B;
repeat(size_B)
begin
if(temp_b)
Outcome=Outcome+temp_a;
temp_a=temp_a<<1;
temp_b=temp_b>>1;
end
end
endmodule

module Photoprocessor(Dat,R,G,B);
input Dat;
output R,G,B;
wire A_r,A_g,A_b;
wire Out_r,Out_g,Out_b;
parameter B_r=10,B_g=19,B_b=5;
assign {A_r,A_g,A_b}=Dat;
assign R=Out_r+Out_g+Out_b;
assign G=R;
assign B=G;
Multplier #(5,4) mult_r(.Outcome(Out_r),.A(A_r),.B(B_r));
Multplier #(5,4) mult_g(.Outcome(Out_g),.A(A_g),.B(B_g));
Multplier #(5,4) mult_b(.Outcome(Out_b),.A(A_b),.B(B_b));
endmodule

就像这个例子
页: [1]
查看完整版本: verilog模块调用