module mux(clk,rst_n,ena,ain,bin,yout,ready
);
input clk,rst_n,ena;
input [7:0]ain;
input [7:0]bin;
output reg [15:0]yout;
output reg ready;
reg [4:0]i;
always@(posedge clk)
if(!rst_n) begin
yout<=0;
ready<=0;
i<=0;
end
else
begin
if(ena) begin
if(i<5'd8) begin
i<=i+1;
end
else i<=0;
if(i<5'd7) begin
if(ain
)
yout<=yout+({8'd0,bin}<<i);
else ;
end
else
if(i==5'd7) begin
if(ain) begin
yout<=yout+({8'd0,bin}<<i);
i<=5'd0;
end
else ;
ready<=1'b1;
end
else ready<=0;
end
else begin
i<=5'd0;
yout<=16'd0;
end
end
endmodule
上面是代码,综合没得问题
下面是testbench
module mux_test;
// Inputs
reg clk;
reg rst_n;
reg ena;
reg [7:0] ain;
reg [7:0] bin;
reg [8:0] i,j;
// Outputs
wire [15:0] yout;
wire ready;
// Instantiate the Unit Under Test (UUT)
mux uut (
.clk(clk),
.rst_n(rst_n),
.ena(ena),
.ain(ain),
.bin(bin),
.yout(yout),
.ready(ready)
);
initial begin
$display("this simulation is running.
");
// Initialize Inputs
clk = 0;
rst_n = 0;
ena = 0;
ain = 8'hzz;
bin = 8'hzz;
// Wait 100 ns for global reset to finish
#1000;
@(posedge clk);
rst_n=1;
for(i=0;i<256;i=i+1) begin
for(j=0;j<256;j=j+1) begin
mux_two(i,j);
end
end
// Add stimulus here
$display("mux simulation is over. All right.
");
$stop;
end
always #10 clk=~clk;
task mux_two;
input [7:0]a;
input [7:0]b;
begin
@(posedge clk);#3;
ain<=a;
bin<=b;
ena<=1;
@(posedge ready);
@(posedge clk);#3;
if(a*b==yout) $display("%3d * %3d = %5d , it is right.",a,b,yout);
else begin
$display("%3d * %3d = %5d , it is wrong.",a,b,yout);
$stop;
end
@(posedge clk);#3;
ena=0;
ain=8'hzz;
bin=8'hzz;
end
endtask
endmodule
在出波形的时候ain只能加到128就不能再继续加了。。加了也不出波形,没找出错误。。求大神。
# 127 * 247 = 31369 , it is right.
# 127 * 248 = 31496 , it is right.
# 127 * 249 = 31623 , it is right.
# 127 * 250 = 31750 , it is right.
# 127 * 251 = 31877 , it is right.
# 127 * 252 = 32004 , it is right.
# 127 * 253 = 32131 , it is right.
# 127 * 254 = 32258 , it is right.
# 127 * 255 = 32385 , it is right.
# 128 * 0 = 0 , it is right.仿真结果到这就一直仿真不出结果了。波形显示是ready挂高了一直没下降。。
一周热门 更多>