本帖最后由 石田宇 于 2010-10-31 16:21 编辑
程序:
`timescale 1ns/1ps
module mux16(
clk,
rst_n,
start,
ain,
bin,
yout,
done
);
parameter WIDTH=16;
parameter LONGWIDTH=32;
input clk;
input rst_n;
input start;
input[WIDTH-1:0] ain;
input[WIDTH-1:0] bin;
output[LONGWIDTH-1:0] yout;
output done;
//-----------------------------------------------------------------------------------------------
reg [4:0] cnt=0;
reg [LONGWIDTH-1:0] shift_ain;
reg [LONGWIDTH-1:0] shift_bin;
reg done_r;
reg yout_r;
always @ (posedge clk or negedge rst_n or posedge start)
begin
if(!rst_n)
begin
yout_r<=32'd0;
done_r<=1'b0;
cnt<=0;
shift_ain<=0;
shift_bin<=0;
end
else
begin
if(start)
begin
if(cnt<5'd17)
begin
shift_ain<=ain;
shift_bin<=bin;
yout_r<=0;
for(cnt=5'd1;cnt<5'd17;cnt=cnt+1'b1)
begin
if(shift_bin[0]) yout_r<=yout_r+shift_ain;
shift_ain<=shift_ain<<1;
shift_bin<=shift_bin>>1;
if(cnt==5'd17) done_r<=1'b1;
end
end
end
else if(!start)
begin
cnt<=0;
done_r<=1'b0;
end
end
end
assign done=done_r;
assign yout=yout_r;
endmodule
testbentch:
`timescale 1 ns/ 1 ps
module mux16_vlg_tst();
// test vector input registers
reg [15:0] ain;
reg [15:0] bin;
reg clk;
reg rst_n;
reg start;
// wires
wire done;
wire [31:0] yout;
// assign statements (if any)
mux16 i1 (
// port map - connection between master ports and signals/registers
.ain(ain),
.bin(bin),
.clk(clk),
.done(done),
.rst_n(rst_n),
.start(start),
.yout(yout)
);
initial
begin
clk=0;
forever
#10 clk=~clk;
end
initial
begin
rst_n=0;
#1000;
rst_n=1;
#19000;
$stop;
end
initial
begin
start=0;
#2000;
start=1;
#18000;
$stop;
end
initial
begin
ain=16'd0;
#5000;
ain=16'd10;
#15000;
$stop;
end
initial
begin
bin=16'd0;
#5000;
bin=16'd20;
#15000;
$stop;
end
endmodule
然后调用modelsim仿真的时候没有输出结果,只有输入的波形,而且报错:# ERROR: No extended dataflow License exists
|