| Link for ModelSim | ![]() |
Add the script code for the state counter test as follows:
Clear the testisdone flag and display informational messages that inform users about what the test does.
testisdone = 0;
disp('====================================================');
disp('MATLAB testing Manchester Receiver component statecnt.vhd...');
disp('Creates and checks isum and qsum outputs for a randomly');
disp('generated stream of data samples.');Set the project directory to a directory that has write access and is suitable for holding a ModelSim project. This tutorial assumes the writable project directory is unixprojectdir.
projectdir = pwd;
Change the format of the project directory and state counter VHDL file specifications to the UNIX format, which ModelSim and Tcl use, by replacing backslashes (\) with forward slashes (/).
% ModelSim and Tcl use the UNIX file specification format unixprojectdir = strrep(projectdir,'\','/'); unixsrcfile = strrep(fullfile(matlabroot,'toolbox','modelsim',... 'modelsimdemos','vhdl','manchester','iqconv.vhd'),'\','/');
Define a sequence of Tcl commands to be executed in the context of ModelSim. Define tclcmd as
tclcmd = { ['cd ' unixprojectdir ],...
'catch {wm geometry . 500x200+0+0}',...
'vlib work',...
['vcom -performdefaultbinding ' unixsrcfile],...
'vsimmatlab -t 1ns work.statecnt ',...
'force /statecnt/clk 1 0, 0 5 ns -repeat 10 ns ',...
['matlabtb statecnt -mfunc Manchester_statecnt,...
-socket ' num2str(portnum)],...
'run 30000',...
'quit -f'};The following list explains what each Tcl command does:
The cd command changes to the writable UNIX style project directory.
The wm command adjusts the placement of the ModelSim window so it does not obscure the MATLAB window. This command works in ModelSim SE environments only.
The vlib command creates the design library work.
The vcom command compiles the VHDL file. The -performdefaultbinding option enables default bindings in the event that they have been disabled in the modelsim.ini file.
The vsimmatlab command loads an instance of the VHDL entity statecnt for MATLAB verification. This command is a Link for ModelSim extension to the ModelSim command set. The -t option specifies a ModelSim simulator time resolution of 1 nanosecond (the default).
The force command drives the entity's clk signal, which gets passed on to the test bench as oport data. The command specifies that clk be set at time equals 0, cleared after 0 after 5 nanoseconds, and that the high-to-low cycle be repeated every 10 nanoseconds.
The matlabtb command initiates a MATLAB test bench session for the loaded instance of entity statecnt. This command is a Link for ModelSim extension to the ModelSim command set. The command specifies
The entity instance statecnt.
The -mfunc option, which specifies the MATLAB function that is to test the entity (manchester_statecn.m). This option is required because the MATLAB function name is not the same as the entity name.
TCP/IP socket communication with socket port portnum. For a link to be established between ModelSim and MATLAB, the value specified with -socket must match the socket port that was specified when the MATLAB server (hdldaemon) was started.
The run command starts and runs the ModelSim simulation for 30000 iterations of the current resolution limit. By default, the simulation runs for 30000 nanoseconds.
The quit command quits ModelSim. The -f option causes the command to quit without asking for confirmation.
Start ModelSim for use with the Link for ModelSim with the following call to function vsim:
vsim ('startupfile','statecnt.do', 'tclstart',tclcmd);This command starts ModelSim with a Tcl command script that executes some general-purpose startup commands and then the user-defined commands specified with the property-value pair‘tclstart' tclcmd.
The ‘startupfile' property causes vsim to write the entire startup Tcl command script to statecnt.do for future reference or use.
Add the following lines of code to display informational messages and wait for manchester_statecnt.m to run to completion:
while testisdone == 0,
pause(0.001);
end
pause(1);
disp('MATLAB test of statecnt.vhd is complete. Check the');
disp('generated plot for results.');
disp('Press any key to exit test script.');
pause;Save the test script file as manchester_tb.m and close the Edit/Debug window.
| Writing Script Code for the I/Q Convolver Test | Running the Manchester Receiver Simulation | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |