여기는 testbench가있는 fsm dut입니다.
이 fsm dut은 상태 전환 1 - 0 - 1 - 0을 순서대로 수행합니다.
테스트 벤치가 제대로 작동하는지 확인합니다.
를 Verilog 모듈 코드 (DUT) :
module melay_fsm(o,clk,rst,i);
output o;
input i,clk,rst;
reg o;
reg [1:0]state;
// [1:0]state;
[email protected](posedge clk,posedge rst)
begin
if(rst)
begin
state <=2'b00;
end
else
begin
case(state)
2'b00:
begin
if(i)
state<=2'b01;
else
state<=2'b00;
end
2'b01:
begin
if(!i)
state<=2'b10;
else
state<=2'b01;
end
2'b10:
begin
if(i)
state<=2'b11;
else
state<=2'b00;
end
2'b11:
begin
if(!i)
state<=2'b00;
else
state<=2'b01;
end
endcase
end
end
[email protected](posedge clk,negedge rst)
begin
if(rst)
o<=1'b0;
else if(state==2'b11 && i==0)
o<=1'b1;
else
o<=1'b0;
end
endmodule
시스템을 Verilog 모듈 코드 (테스트 벤치) :
interface melay_intf(input bit clk);
logic o,rst,i;
wire clk;
clocking [email protected](posedge clk);
input o;
output i,rst;
endclocking
modport tes(clocking c1);
endinterface
module top;
bit clk;
always
#1 clk = ~clk;
melay_intf i1(clk);
melay_fsm a1(.o(i1.o),.clk(i1.clk),.rst(i1.rst),.i(i1.i));
melay_tes(i1);
endmodule
program melay_tes(melay_intf i1);
initial
#100 $finish;
initial
begin
i1.rst <= 0;
#4 i1.rst <= 1;
#4 i1.rst <= 0;
i1.i = 1;
#2 i1.i = 0;
#2 i1.i = 1;
#2 i1.i = 0;
#2 i1.i = 1;
#2 i1.i = 0;
repeat(10)
begin
i1.i = 1;
#2 i1.i = $urandom_range(0,1);
end
end
initial
$monitor("output = %d clk = %d rst = %d i = %d",i1.o,i1.clk,i1.rst,i1.i);
initial
begin
$dumpfile("mem.vcd");
$dumpvars();
end
endprogram
중요한 것은 여기로주의해야 할 최고 모듈에 신호 연결입니다 .
melay_fsma1 (.o (i1.o), .clk (i1.clk), .st (i1.rst) ,. i (i1.i));
제대로 testbench 및 dut와 인터페이스를 바인딩하는 방법을 준수하십시오. 다음 사항을 준수하십시오.
나는 모든 dut의 신호와 인터페이스를 정의합니다.
맨 위 모듈에서 인터페이스 (melay_intf)의 인스턴스 (i1)을 가져 왔습니다.
상단 모듈에서 dut (melay_fsm) 인스턴스 (a1)를 가져 왔습니다.
지금 melay_fsm A1 (.o 인 (i1.o) ,. CLK (i1.clk) ,. 처음 (i1.rst) ,. 난 (i1.i))
모든 DUT의 관찰 신호는 인터페이스로 연결됩니다.
테스트 벤치에서 인터페이스 (i1)의 인스턴스를 전달했습니다. melay_tes (i1)
따라서 testbench는 인터페이스 신호에 액세스 할 수 있으며 인터페이스 신호는 dut의 신호에 연결됩니다.
이제 인터페이스를 통해 테스트 벤치에서 dut의 신호에 액세스 할 수 있습니다.
이제 올바른 흐름을 이해할 수 있다고 생각합니다.
의심되는 항목이 있으면 질문 해주세요.내 혼란이 대신 인터페이스는 다음과 같이 정의되는 경우 인터페이스의, 어디
안녕 AndresM, 이는 다음과 같습니다 인터페이스 simple_bus (입력 로직 CLK 인터페이스 입력 로직 REQ를 정의 //, 입력 로직 GNT , 입력 논리 [7 : 0] addr, 입력 논리 데이터, 입력 논리 [1 : 0] 모드, 출력 논리 시작, 출력 rdy); end interface : simple_bus 그러면이 인터페이스를 어떻게 연결해야합니까? 나는 똑같은 좋은 예를 찾을 수 없었다. – justrajdeep
테스트 케이스 프로그램에서 신호를 보내는 방법을 알 수 있도록 일부 코드를 제 답변에 추가했습니다. 그것을 확인하십시오 - 이것은 당신이 가지고 있을지도 모르는 질문을 분명히 명확히해야합니다. – AndresM