3
for循環工作正常,但一切都在單個時鐘週期內發生。我如何讓它每個週期運行一次迭代?如何在多個時鐘週期內執行for循環?
`timescale 1ns/10ps
module multiplier (clock,multiplier,multiplicand,start,done,product);
input [7:0] multiplier ,multiplicand;
input start;
input clock;
output [15:0] product;
output done;
reg [15:0] multiplierF ,multiplicandF;
reg [15:0] productF;
reg doneF;
integer i;
assign product = productF;
assign done = doneF;
task rpa_16;
input [15:0] multiplierF;
inout [15:0] productF;
assign productF = multiplierF + productF;
endtask
always @ (posedge clock or posedge start)
begin
if(start)
begin
multiplierF = 0 ;
multiplicandF = 0 ;
productF = 0 ;
doneF = 0 ;
end
else
begin
multiplierF = {8'b0,multiplier};
multiplicandF = {8'b0,multiplicand};
end
end
always @(posedge clk)
begin
if(!doneF)
begin
for (i=0;i<7;i=i+1)
begin
if(multiplicand[i])
begin
rpa_16(multiplierF,productF);
multiplierF = multiplierF << 1;
productF = productF;
end
else
begin
multiplierF = multiplierF << 1;
end
end
doneF = 1;
end
end
我不能粘貼波形的圖片,但我希望我在每個積極的邊緣後增加。但是,最近發生的事情是,for循環在單個時鐘週期中執行並且我得到輸出。 – user2128682 2013-04-09 04:52:03