| Link for ModelSim | ![]() |
Add the script code for the I/Q convolver 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 iqconv.vhd...');
disp('Checks isum and qsum output for a randomly generated');
disp('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 I/Q convolver 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 follows:
tclcmd = { ['cd ' unixprojectdir ],...
'catch {wm geometry . 500x200+0+0}',...
'vlib work',...
['vcom -performdefaultbinding ' unixsrcfile],...
'vsimmatlab work.iqconv',...
'force /iqconv/clk 1 0, 0 5 ns -repeat 10 ns ',...
'force /iqconv/enable 1',...
'force /iqconv/reset 1',...
'run 100',...
['matlabtb iqconv -rising /iqconv/clk -mfunc,...
Manchester_iqconv -socket ' num2str(portnum)],...
'run 1000',...
'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 iqconv for MATLAB verification. This command is a Link for ModelSim extension to the ModelSim command set.
The force commands drive the entity's clk, enable, and reset signals, which get passed on to the test bench as oport data. The first force command sets clk at time equals 0, clears it after 5 nanoseconds, and repeats the high-to-low cycle every 10 nanoseconds. The second and third force commands set the enable and reset signals.
The run command starts and runs the ModelSim simulation for 100 iterations of the current limit. By default, the simulation runs for 100 nanoseconds. This accounts for the startup phase.
The matlabtb command initiates a MATLAB test bench session for the loaded instance of entity iqconv. This command is a Link for ModelSim extension to the ModelSim command set. The command specifies
The entity instance iqconv.
The -rising option, which triggers an invocation of the MATLAB function when clk experiences a rising edge.
The -mfunc option, which specifies the MATLAB function that is to test the entity (manchester_iqconv.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 runs the ModelSim simulation for 1000 iterations of the current resolution limit. By default, the simulation runs for 1000 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','iqconv.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 iqconv.do for future reference or use.
Add the following lines of code to display informational messages and wait for manchester_iqconv.m to run to completion:
while testisdone == 0,
pause(0.001);
end
pause(1);
disp('MATLAB test of iqconv.vhd is complete.');
disp('If the test fails, an error message is displayed.');
disp('Press any key to continue to the next test.');
pause; | Writing Script Code for the Decoder Test | Writing Script Code for the State Counter Test | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |