hello. i am new learner of system verilog. right now am trying to connect two modules using an interface. is it necessary to connect two modules via a top module when using interface…??? is there a way to connect directly from one module to another using interface…? like in verilog we simply instantiate second module from first module…??
following is the code which i wrote…
interface datamem;
logic [2:0] count;
logic [7:0] inst_out;
endinterface
module IF_Inter( input logic rst,clk,inst_en,
datamem data);
always_ff @(posedge clk or posedge rst) begin
if (rst)
begin
data.count <= 3'b000;
end
else if(inst_en)
data.count <= data.count + 3'b001;
end
inst_mem_inter U_inst_mem_inter( .mem(data));
endmodule
module inst_mem_inter(datamem mem);
always_comb begin
case (mem.count)
3'b000: mem.inst_out<=8'b00000000;
3'b001: mem.inst_out<=8'b00000101;
3'b010: mem.inst_out<=8'b01001010;
3'b011: mem.inst_out<=8'b01001111;
3'b100: mem.inst_out<=8'b10010000;
3'b101: mem.inst_out<=8'b10010101;
3'b110: mem.inst_out<=8'b11011010;
3'b111: mem.inst_out<=8'b11011111;
endcase
end
endmodule
this is not working and throwing an error because i have not instantiated the interface as we do in a top module. i am able to do it using top module and instantiating it. just want to know whether we can do directly or not ?