Reputation: 456
I'm trying to write SV code for the model below using the always_ff procedure and it is not working.
My system-verilog code is here:
module circuit
(
input clk,
output logic reg_1, reg_2, reg_3, reg_4 ,reg_5, reg_6, reg_7, reg_8
);
logic reg4_in, reg3_in, reg2_in;
assign reg4_in = reg_5 ^ reg_1;
assign reg3_in = reg_4 ^ reg_1;
assign reg2_in = reg_3 ^ reg_1;
always_ff @(posedge clk)
begin
{reg_1,reg_2,reg_3,reg_4,reg_5,reg_6,reg_7,reg_8} <= {reg_2,reg2_in,reg3_in,reg4_in,reg_6,reg_7,reg_8,reg_1};
end
endmodule
My testbench is here:
module test;
logic clk;
logic reg_1,reg_2,reg_3,reg_4,reg_5,reg_6,reg_7,reg_8;
always
#5 clk = ~clk; //generation of clock
circuit U_circuit (.*); //Instantiation
initial begin
$dumpfile("dump.vcd"); $dumpvars;
reg_1 = 1'b1;
reg_2 = 1'b0;
reg_3 = 1'b0;
reg_4 = 1'b0;
reg_5 = 1'b0;
reg_6 = 1'b0;
reg_7 = 1'b0;
reg_8 = 1'b0;
clk = 1'b0;
#100 $finish; //end of simulation
end
initial begin
$recordfile("waves.trn"); //creation of waveforms
$recordvars();
end
endmodule
When I attempt to run the simulation, I receive these errors (it's repeated a couple more times):
> > # ** Error (suppressible): (vsim-3839) Variable '/test/reg_8', driven via a port connection, is multiply driven. See testbench.sv(9).
> > # Time: 0 ns Iteration: 0 Instance: /test File: testbench.sv Line: 21
> > # ** Error (suppressible): (vsim-3839) Variable '/test/reg_7', driven via a port connection, is multiply driven. See testbench.sv(9).
> > # Time: 0 ns Iteration: 0 Instance: /test File: testbench.sv Line: 20
EDA link for easier reading: https://www.edaplayground.com/x/8KfD
Upvotes: 1
Views: 1418
Reputation: 42698
Your testbench is trying to make procedural assignments to reg_1...reg_8
, but they are already being driven by the outputs of your circuit
module. You need to add a reset input. Also, you should be declaring arrays rather than individually named signals. It makes it much easier to work with.
module circuit
(
input clk, rst,
output logic [1:8] reg_out; //
);
logic [2:4] reg_in;
assign reg_in[4] = reg_out[5] ^ reg_out[1];
assign reg_in[3] = reg_out[4] ^ reg_out[1];
assign reg_in[2] = reg_out[3] ^ reg_out[1];
always_ff @(posedge clk or negedge rst)
begin
if (rst)
reg_out = 8'b10000000
else
reg_out <= {reg_out[2],reg_in,reg_out[6:8],reg_outt[1]};
end
endmodule
Upvotes: 2