我正在尝试使用 SystemVerilog 实现 FIR 滤波器,但是当我尝试模拟它时,我遇到了这个错误:
驱动程序和程序赋值给变量的非法组合 检测到 inStream(在初始块中找到程序分配 文件 ./testbench.sv 中的第 22 行)。
有人可以帮我解决这个问题吗?我对 SystemVerilog 还很陌生。
过滤模块是这样的:
module lpf900 (input real inStream, output real outStream);
localparam int nCampioni = 101;
real campioni[0:nCampioni-1] = '{0.0018, 0.0011, 0.0002, -0.0006, -0.0015, -0.0025, -0.0034, -0.0043, -0.0051, -0.0060, -0.0067, -0.0074, -0.0080, -0.0084, -0.0088, -0.0090, -0.0090, -0.0089, -0.0087, -0.0082, -0.0076, -0.0068, -0.0059, -0.0047, -0.0034, -0.0019, -0.0002, 0.0016, 0.0035, 0.0056, 0.0077, 0.0100, 0.0123, 0.0147, 0.0171, 0.0195, 0.0219, 0.0242, 0.0265, 0.0287, 0.0308, 0.0327, 0.0346, 0.0362, 0.0377, 0.0389, 0.0400, 0.0408, 0.0414, 0.0418, 0.0419, 0.0418, 0.0414, 0.0408, 0.0400, 0.0389, 0.0377, 0.0362, 0.0346, 0.0327, 0.0308, 0.0287, 0.0265, 0.0242, 0.0219, 0.0195, 0.0171, 0.0147, 0.0123, 0.0100, 0.0077, 0.0056, 0.0035, 0.0016, -0.0002, -0.0019, -0.0034, -0.0047, -0.0059, -0.0068, -0.0076, -0.0082, -0.0087, -0.0089, -0.0090, -0.0090, -0.0088, -0.0084, -0.0080, -0.0074, -0.0067, -0.0060, -0.0051, -0.0043, -0.0034, -0.0025, -0.0015, -0.0006, 0.0002, 0.0011, 0.0018};
real firMemory [0:nCampioni-1];
function void initFirMemory();
/* the finite memory is initialized at all-zeros */
for(int j = 0; j < nCampioni; j++) begin
firMemory[j] = 0.0;
end
endfunction
function void shiftFirMemory(input real newSample);
for(int j = nCampioni-1; j > 0; j--) begin
firMemory[j] = firMemory[j-1];
end
firMemory[0] = newSample;
endfunction
function real computeSingleOut();
real res;
res = 0;
for(int j = 0; j < nCampioni; j++) begin
res += firMemory[j] * campioni[j];
end
return res;
endfunction
initial begin //initialize the result to all-zeros at time zero
initFirMemory();
end
always @(inStream) begin
shiftFirMemory(inStream);
outStream = computeSingleOut();
end
endmodule
代码还包含此程序来详细说明左声道和右声道:
program stimulus #(localparam qBits = 8)
(input logic clk, output real inStream, input real outStream);
localparam int nChannels = 2;
import soundPackage::*;
typedef logic signed [qBits-1:0] qType;
typedef qType queValueType_q[0:nChannels-1];
typedef real queValueType_r[0:nChannels-1];
queValueType_q myQueue_q[$];
queValueType_r myQueue_r[$];
real myChannel[$];
soundErrorType myError;
soundSequence #(.nChannels(nChannels), .qBits(8), .qLSB(-15)) inSequence;
soundSequence #(.nChannels(1), .qBits(8), .qLSB(-15)) outSequence;
clocking myCk @ (posedge clk);
default input #1step output #1ps;
input outStream;
output inStream;
endclocking
task acquireoutStream();
real myVal[0:0];
myVal[0] = myCk.outStream; // pre-clock
outSequence.putSample_r(myVal);
endtask
initial begin
inSequence = new;
outSequence = new;
//elaborate left channel
$display("[%0d] elaborating channel 0 of read sequence",$time);
inSequence.getChannel_r(myChannel, 0);
$display("[%0d] the channel has %d values",$time,myChannel.size);
void'(outSequence.cleanSequence());
myCk.inStream <= myChannel.pop_front();
@(myCk);
while (myChannel.size>0) begin
myCk.inStream <= myChannel.pop_front();
acquireoutStream;
@(myCk);
end
acquireoutStream;
void'(outSequence.storeToFile(.fname("outStream_r_0.txt"), .RnQ(1)));
void'(outSequence.storeToFile(.fname("outStream_q_0.txt"), .RnQ(0)));
//elaborate right channel
$display("[%0d] elaborating channel 1 of read sequence",$time);
inSequence.getChannel_r(myChannel, 1);
$display("[%0d] the channel has %d values",$time,myChannel.size);
void'(outSequence.cleanSequence());
myCk.inStream <= myChannel.pop_front();
@(myCk);
while (myChannel.size>0) begin
myCk.inStream <= myChannel.pop_front();
acquireoutStream;
@(myCk);
end
acquireoutStream;
void'(outSequence.storeToFile(.fname("outStream_r_1.txt"), .RnQ(1)));
void'(outSequence.storeToFile(.fname("outStream_q_1.txt"), .RnQ(0)));
end
endprogram
我尝试使用以下测试平台测试此代码:
`include "packages.sv"
/*the packages must be loaded before this point*/
`include "programs.sv"
module myTB();
real inStream, outStream;
logic clk = 1'b0;
always #5 clk = ~clk;
stimulus myStim (clk, inStream, outStream);
lpf900 mylpf900 (inStream, outStream);
initial begin
$dumpfile("dump.vcd"); $dumpvars;
end
initial begin
// Inizializzazione
clk = 0;
inStream = 0.0;
// Applicazione dei test
$display("Inizio test");
// Generazione di un segnale di ingresso
// Simuliamo una sequenza di campioni per testare il filtro FIR
#10 inStream = 0.2;
#10 inStream = 0.4;
#10 inStream = 0.6;
#10 inStream = 0.8;
#10 inStream = 1.0;
#10 inStream = 0.8;
#10 inStream = 0.6;
#10 inStream = 0.4;
#10 inStream = 0.2;
#10 inStream = 0.0;
// Continuazione dei test
#10 inStream = -0.2;
#10 inStream = -0.4;
#10 inStream = -0.6;
#10 inStream = -0.8;
#10 inStream = -1.0;
// Fine del test
#10;
$display("Fine test");
$finish; // Terminare la simulazione
end
// Monitoraggio dei segnali
initial begin
$monitor("Time = %0t, inStream = %f, outStream = %f", $time, inStream, outStream);
end
endmodule
问题是您从 2 个源驱动相同的信号
inStream
:
inStream = 0.0;
program
实例输出端口 inStream
您不能从 2 个来源驱动它。 您必须只选择一个:测试平台或程序实例。