| Link for ModelSim | ![]() |
Typically, at this point you would create or edit a MATLAB function that meets Link for ModelSim requirements. For this tutorial, open and examine the existing file manchester_iqconv.m. This function
Disables resets, marking the start of a cycle.
Establishes a random cycle length of 15, 16, or 17.
icycle = 15 + floor(rand*3);
Generates three vectors of random binary states. One vector represents a data sample. The other two vectors represent the inphase and quadrature waveforms of that data sample.
samp_vect = randbin(icycle); i_wf_vect = randbin(icycle); q_wf_vect = randbin(icycle);
Uses the function binary_xor to compute the sum of XOR operations on the generated sample and I/Q waveforms and compares the results with the isum and qsum values received from the VHDL entity. Here, computation results produced by MATLAB are being used to verify the convolved results produced by the VHDL model.
test_isum = binary_xor(i_wf_vect,samp_vect);
test_qsum = binary_xor(q_wf_vect,samp_vect);
if (test_isum ~= bin2dec(oport.isum')),
disp(['Failed on iteration ' num2str(iters) ',...
Expected ISUM = 'dec2bin(test_isum,5) ',...
Received ISUM = ' oport.isum']);
end
if (test_qsum ~= bin2dec(oport.qsum')),
disp(['Failed on iteration ' num2str(iters) ',...
Expected QSUM = 'dec2bin(test_qsum,5) ',...
Received QSUM = ' oport.qsum']);
end
Enables resets, marking the end of a cycle.
iport.reset = '1';
Forces the values of the test-generated sample data and I/Q waveforms onto signals connected to the VHDL entity's input ports, samp, i_wf, and q_wf.
iport.i_wf = i_wf_vect(icycle); iport.q_wf = q_wf_vect(icycle); iport.samp = samp_vect(icycle);
The rest of this section highlights areas of code in manchester_iqconv.m required for MATLAB to verify iqconv.vhd:
Start MATLAB, if it is not already running.
In MATLAB, change your current directory to the directory you created in Setting Up Tutorial Files. If you set up the files elsewhere, adjust the path accordingly:
cd C:/MyPlayArea
Open manchester_iqconv.m in the MATLAB Edit/Debug window. Use the menu option File>Open and double-click the filename manchester_iqconv.m or enter the edit command as follows:
edit manchester_iqconv.m
Look at line 1. This is where you specify the MATLAB function name and required parameters:
function [iport,tnext] = manchester_iqconv(oport,tnow,portinfo)
This function definition is significant in that it represents the entity test bench. When coding the function definition, consider the following:
Names the function manchester_iqconv. Because this name does not match the name of the corresponding VHDL entity, you need to specify the test bench name explicitly later when you register the test bench with ModelSim.
You must define the function with two input parameters, iport and tnext, and three output parameters, oport, tnow, and portinfo.
| iport | Forces (by deposit) values onto signals connected to input ports of the VHDL entity reset, i_wf, q_wf, and samp. |
| tnext | Specifies an optional time at which the MATLAB function is to be called back. |
| oport | Receives signal values from the output ports of the VHDL entity isum and qsum at the time specified by tnow. |
| tnow | Receives the simulation time at which the MATLAB function is called. By default, time is represented in seconds. |
| portinfo | For the first invocation of the MATLAB function (at the start of a simulation) only, receives an array of information that describes the ports defined for the VHDL entity. |
Note You can substitute your own names for the preceding parameters. For example, the following function definition is valid: function [a, b] = foo(c, d, e) |
For more information on the required MATLAB function parameters, see Setting up Expected Parameters.
You can use the iport parameter to drive input signals instead of, or in addition to, using other signal sources, such as ModelSim force commands. Depending your application, you might use any combination of input sources. However, keep in mind that if multiple sources drive signals to a single iport, a resolution function is required for handling signal contention.
Make note of the data types of ports defined for the entity under simulation. The Link for ModelSim interface converts VHDL data types to comparable MATLAB data types and vice versa. As you develop your MATLAB function, you must know the types of the data that it receives from and needs to return to ModelSim.
The entity iqconv consists of six input ports of type STD_LOGIC and two output ports of type STD_LOGIC_VECTOR. The interface converts scalar data of type STD_LOGIC to a character that matches the character literal for the corresponding enumerated type. Data of type STD_LOGIC_VECTOR consists of a column vector of characters with one bit per character.
For more information on interface data type conversions, see Data Type Conversions.
Search for iport.reset. This assignment statement marks the start of a cycle by disabling resets.
Search for oport.isum. This line of code shows how the data that a MATLAB function receives from ModelSim might be converted to a numeric value and compared.
if (test_isum ~= bin2dec(oport.isum')),
In this case, the function receives STD_LOGIC_VECTOR data on oport.isum. The MATLAB function bin2dec converts the bit vector to a decimal value that can be compared to the numeric value test_isum.
Just below this area of code, the same conversion is performed for the bit vector oport.qsum.
Search for iport.reset. This assignment statement marks the end of a cycle by enabling a reset.
Search for iport.i_wf. This line of code and the two lines that follow force values onto the signals connected to VHDL entity ports i_wf, q_wf, and samp.
Browse through the rest of manchester_iqconv.m.
Close the MATLAB Edit/Debug window.
| Developing the Manchester Receiver MATLAB Functions | MATLAB Function for the Decoder | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |