What Is a VHDL Testbench?
A VHDL® testbench is used to define stimulus to a logic design and check that the design’s outputs match its specification. Engineers who use MATLAB® and Simulink® to develop models of new algorithms for FPGAs and ASICs often create system testbenches in these environments as well. When they write register-transfer level (RTL) VHDL code, though, they may want to produce VHDL testbenches based on the system testbenches.
MATLAB or Simulink users have several options for verifying that HDL algorithm realizations are correct without manually coding VHDL testbenches.
Verification Using HDL Cosimulation
Instead of writing a VHDL testbench, you can use MATLAB and Simulink testbenches along with an HDL simulator to verify your design under test (DUT). HDL Verifier™ automates this cosimulation process. The MATLAB or Simulink testbench compares output values from the HDL simulator with expected values from a truth model and reports "miscompares."
Verification Using FPGA-in-the-Loop Testing
You can also use MATLAB and Simulink testbenches with DUTs that have been programmed into a Xilinx®, Intel®, or Microchip FPGA development board through FPGA-in-the-loop simulation. You can use HDL Verifier with FPGA vendor tools to automate the process of synthesizing the HDL, running place and route, generating a programming file, loading the file onto the development board, and setting up communication between the MATLAB or Simulink session and the board. With FPGA-in-the-loop, there is no need to generate a VHDL testbench because MATLAB or Simulink serves this purpose.
Verification Using SystemVerilog DPI Testbench
Another alternative to using a VHDL testbench involves exporting verification components to HDL simulators for use in FPGA and ASIC verification. SystemVerilog, an extension of Verilog used for testbench development, is supported by all popular HDL simulators. With the SystemVerilog Direct Programming Interface (DPI), you can integrate C/C++ code with simulators such as Synopsys® VCS®, Cadence Xcelium™, Xilinx Vivado®, Siemens EDA ModelSim® or Questa®, and the Xilinx® Vivado® Simulator. Using HDL Verifier in combination with MATLAB Coder™ or Simulink Coder™, you can generate SystemVerilog DPI testbenches to verify products.
HDL Verifier generates SystemVerilog DPI testbenches in two different forms:
- Component testbench: You can generate a SystemVerilog testbench by generating C code from a Simulink subsystem for use as a DPI component. The testbench verifies the generated DPI component against data vectors from your Simulink model. (See Generate SystemVerilog DPI Component.)
- HDL code testbench: If you generate HDL code from a Simulink subsystem using HDL Coder, you can generate a SystemVerilog testbench. This testbench compares the output of the HDL implementation generated by HDL Coder against the results of the Simulink model. (See Verify HDL Design Using SystemVerilog DPI Testbench.)
Verification of Generated HDL using a VHDL Testbench
When you use HDL Coder to generate HDL, you can generate a VHDL testbench for a subsystem. HDL Coder generates a VHDL testbench by running a simulation in Simulink to capture input vectors and expected output data for your DUT. HDL Coder outputs the DUT stimulus and reference data from your MATLAB® or Simulink simulation to data files (.dat).
During HDL simulation, the HDL testbench reads the saved stimulus from the .dat files. The testbench compares the actual DUT output with the expected output.