我嘗試設計一個乘法器BIST(內置自測系統)。我創建了一個工作正常的乘法器,現在我嘗試將其結果(乘法器輸出)與(ORA輸出)的正確結果進行比較。我正在模擬Modelsim的模擬器。我不明白爲什麼波形顯示的結果與$display
任務不同。 .......我現在的空白,不知道該怎麼辦.........幫我
這裏是我的代碼(頂層模塊)----
module top(input wire clk,input wire sw1,input wire sw2,input wire sw3,input wire start,output reg[7:0 ]out,output reg rs,output reg rw,output reg en);
//Slow Clock Instance
wire sclk;
sender send1(clk,sclk);
//Releated to Braun Multiplier
reg [3:0]a=4'b0000;
reg [3:0]b=4'b0000;
wire [7:0]outb;
reg[7:0]hold;//Used for Holding Output/Return of Function
braun sd(.x(a),.y(b),.out(outb));
integer state5=0; //State for start checking
//Integer for Array for a & b
integer s=0;
reg cnt=1'b0;
always @(posedge sclk)
begin
//Fault Checking Condition
if((start==1'b0) & (sw3==1'b0) & (cnt==1'b0))
begin:close
case(state5)
0:begin
a=4'b0100;
s=s+1;
b=b + 1'b1;
hold=ora(a,b);
$display("hold=%b",hold);
$display("outb=%b",outb);
if(s!=15)
begin
if(outb==hold)
begin
state5=0;
end
else if(outb!=hold)
begin
cnt=1'b1;
disable close;
end
end
else if(s==15)
begin
if(outb==hold)
begin
s=0;
state5=1;
end
else if(outb!=hold)
begin
cnt=1'b1;
disable close;
end
end
end
1:begin
a=4'b0001;
s=s+1;
b=b+ 1'b1;
hold=ora(a,b);
$display("hold=%b",hold);
$display("outb=%b",outb);
if(s!=15)
begin
if(outb==hold)
begin
state5=1;
end
else if(outb!=hold)
begin
cnt=1'b1;
disable close;
end
end
else if(s==15)
begin
if(outb==hold)
begin
s=0;
state5=2;
end
else if(outb!=hold)
begin
cnt=1'b1;
disable close;
end
end
end
2:begin
a=4'b0010;
s=s+1;
b=b+ 1'b1;
hold=ora(a,b);
$display("hold=%b",hold);
$display("outb=%b",outb);
if(s!=15)
begin
if(outb==hold)
begin
state5=2;
end
else if(outb!=hold)
begin
cnt=1'b1;
disable close;
end
end
else if(s==15)
begin
if(outb==hold)
begin
s=0;
state5=3;
end
else if(outb!=hold)
begin
cnt=1'b1;
disable close;
end
end
end
endcase
end //if end
end//always end
//Function For ORA Checking Purpose......
function [7:0]ora (input reg [3:0]X,input reg [3:0]Y);
begin
$display("X=%b & Y=%b",X,Y);
//Positive-Positive Operations
ora=X * Y;
end
endfunction
endmodule
這裏是反我的另一個文件(我把它命名爲sender.v)文件 -
`timescale 1ns/1ps
module sender(input wire clkin, output reg clkout);
reg [2:0]tmp=3'b000;
//Delay Generation////////
[email protected](posedge clkin)
begin
tmp <= tmp+1'b1;
clkout<=tmp[2];
end
endmodule
和乘數(百靈乘數)的文件是這裏 -
module braun(x,y,out);
input wire [3:0]x;
input wire [3:0]y; //Input/Output Port Declarations
output [7:0]out;
wire [5:0]a;
wire [8:0]b;
wire [5:0]sa;
wire [1:0]cc;
//If we place 1'b0 in place of "zero"then this was not work so we use this...
wire k[8:0];
//There are 16 And Gates used here....
and a1(out[0],x[0],y[0]);
and a2(a[0],x[1],y[0]);
and a3(a[1],x[2],y[0]);
and a4(a[2],x[3],y[0]);
and a5(b[0],x[0],y[1]);
and a6(b[1],x[1],y[1]);
and a7(b[2],x[2],y[1]);
and a8(a[3],x[3],y[1]);
and a9(b[3],x[0],y[2]);
and a10(b[4],x[1],y[2]);
and a11(b[5],x[2],y[2]);
and a12(a[4],x[3],y[2]);
and a13(b[6],x[0],y[3]);
and a14(b[7],x[1],y[3]);
and a15(b[8],x[2],y[3]);
and a16(a[5],x[3],y[3]);
//There are 12 Full Adder used here....
full_adder f1(out[1],k[0],a[0],b[0],1'b0);
full_adder f2(sa[0],k[1],a[1],b[1],1'b0);
full_adder f3(sa[1],k[2],a[2],b[2],1'b0);
full_adder f4(out[2],k[3],sa[0],b[3],k[0]);
full_adder f5(sa[2],k[4],sa[1],b[4],k[1]);
full_adder f6(sa[3],k[5],a[3],b[5],k[2]);
full_adder f7(out[3],k[6],sa[2],b[6],k[3]);
full_adder f8(sa[4],k[7],sa[3],b[7],k[4]);
full_adder f9(sa[5],k[8],a[4],b[8],k[5]);
full_adder f10(out[4],cc[0],sa[4],k[6],1'b0);
full_adder f11(out[5],cc[1],sa[5],k[7],cc[0]);
full_adder f12(out[6],out[7],a[5],k[8],cc[1]);
endmodule
module full_adder(output reg sum,output reg carry,input wire a,input wire b,input wire c);
[email protected](a,b,c)
begin
case({a,b,c})
3'b000:begin
sum=1'b0;
carry=1'b0;
end
3'b001:begin
sum=1'b1;
carry=1'b0;
end
3'b010:begin
sum=1'b1;
carry=1'b0;
end
3'b011:begin
sum=1'b0;
carry=1'b1;
end
3'b100:begin
sum=1'b1;
carry=1'b0;
end
3'b110:begin
sum=1'b0;
carry=1'b1;
end
3'b111:begin
sum=1'b1;
carry=1'b1;
end
3'b101:begin
sum=1'b0;
carry=1'b1;
end
endcase
end
endmodule
因爲我沒有10美譽我無法張貼圖片,請在您的ModelSim檢查這個...
和成績單窗口的輸出中是在這裏它表現出不同的結果是這裏 -
# X=0100 & Y=0001
# hold=00000100
# outb=00000000
先生我很困惑......根據你的先生我的邏輯是正確的,或者在模擬器中有任何問題嗎?幫助 –
@Rocky_s它是*非常*不太可能(雖然不是不可能),你看到在模擬器中的問題。我建議你花點時間閱讀調度程序的工作原理以及Verilog中固有的競爭條件(由於調度算法)。這將幫助您瞭解如何編寫避免這些情況的代碼,從而達到您的期望。 – Chiggs