در این مثال، یک تست بنچ جامع برای بررسی عملکرد طراحی VHDL ارائه میشود. این تست بنچ شامل موارد زیر است:
- تولید سیگنال کلاک
- ریست اولیه
- خواندن ورودیها از فایل متنی
- نوشتن خروجی در فایل متنی
شما میتوانید طراحی تحت تست خود را به آن اضافه کنید و با تغییراتی جزئی ورودی و خروجی های با عرض بیت بیشتر داشته باشید.
کد تست بنچ:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use std.textio.all;
use ieee.std_logic_textio.all;
entity my_design_tb is
end entity;
architecture behavior of my_design_tb is
signal clk : std_logic := '0';
signal rst : std_logic := '1';
signal a, b : std_logic;
signal y : std_logic;
file infile : text open read_mode is "input.txt";
file outfile : text open write_mode is "output.txt";
begin
uut: entity work.my_design
port map (
clk => clk,
rst => rst,
a => a,
b => b,
y => y
);
clk_process: process
begin
while true loop
clk <= '0'; wait for 5 ns;
clk <= '1'; wait for 5 ns;
end loop;
end process;
rst_process: process
begin
rst <= '1';
wait for 20 ns;
rst <= '0';
wait;
end process;
stimulus_process: process
variable L : line;
variable va : std_logic;
variable vb : std_logic;
variable vy : std_logic;
variable LO : line;
begin
wait for 25 ns;
while not endfile(infile) loop
readline(infile, L);
read(L, va);
read(L, vb);
a <= va;
b <= vb;
wait for 10 ns;
vy := y;
write(LO, string'("a="));
write(LO, va);
write(LO, string(", b="));
write(LO, vb);
write(LO, string(", y="));
write(LO, vy);
writeline(outfile, LO);
end loop;
wait;
end process;
end behavior;
نمونه فایل ورودی (input.txt):
0 0
0 1
1 0
1 1
پس از اجرای شبیهسازی، خروجی در فایل output.txt ذخیره خواهد شد.