MATLAB Function for the Decoder

Open and examine the existing file manchester_decoder.m. This MATLAB function

  1. Provides a mechanism that allows you to easily reset the plot that it generates by calling manchester_decoder directly from the MATLAB command line with no arguments.

  2. Sets up a timing parameter such that the simulator calls back the MATLAB function every nanosecond.

    tnext = tnow+1e-9;
    
  3. Sets up the layout of the plot figure window — positioning of two subplots, axis lines, and labels. One plot shows clock adjustments for phase errors. The second plot shows instances of invalid data and the values of valid data. Invalid data is data for which the clock cycle is less than 15 or greater than 17. As part of this setup, the VHDL entity's isum and qsum values are cleared. These actions are applied during the first callback from ModelSim only.

  4. Gets the phase error adjustment values, data valid setting, and actual sample data values from the decoder VHDL entity.

  5. For each cycle

    1. Plots the clock adjustment data.

      • Black o indicates inphase data

      • Red < indicates data leads

      • Blue > indicates data lags

    2. Plots the instances of invalid data and values of valid data.

      • Red x indicates invalid data

      • Green o indicates valid and 0

      • Black . indicates valid and 1

    3. Creates new test values for isum and qsum and drives them to the VHDL entity.

The rest of this section highlights areas of code in manchester_decoder.m required for MATLAB to verify decoder.vhd:

  1. Start MATLAB, if it is not already running.

  2. 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
    
  3. Open manchester_decoder.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_decoder.m
    
  4. Look at line 1. This line defines the name and required parameters of the MATLAB function that is to service VHDL entity decoder:

    function [iport,tnext] = manchester_decoder(oport,tnow,portinfo)
    

    In this case, the function definition:

  5. Make note of the data types of ports defined for the entity under simulation.

    The entity decoder consists of two input ports — isum and samp — of type STD_LOGIC_VECTOR and three output ports — adj, dvalid, and odata — of type STD_LOGIC. The interface converts the scalar data to a character that matches the character literal for the corresponding enumerated type. Data of type STD_LOGIC_VECTOR is converted to a column vector of characters with one bit per character.

    For more information on interface data type conversions, see Data Type Conversions.

  6. Search for tnext =. This assignment statement registers a callback to occur one nanosecond after the current callback.

  7. Search for iport.isum. This line and the line that follows, clears the entity's isum and qsum values.

  8. Search for adj(isum). This line of code and the line below it show how the data that a MATLAB function receives from ModelSim might need to be converted for use in the MATLAB environment.

    adj(isum) = bin2dec(oport.adj');
    data(isum) = bin2dec(oport.dvalid oport.odata]);
    

    In the first case, the function receives STD_LOGIC_VECTOR data on oport.adj. The MATLAB function bin2dec converts the bit vector to a decimal value that is assigned to adj(isum). The decimal value is used later for numeric comparisons that determine how to plot the adjustment for each qsum value.

    In the next line of code, the function receives STD_LOGIC data on oport.dvalid and oport.odata. The bin2dec function converts the bits to a decimal value that is assigned to data(isum). This decimal value is used later for numeric comparisons that determine how to plot the data validity and value information for each qsum value.

  9. Search for iport.isum. This line of code and similar lines below it force values onto the signals connected to VHDL entity ports isum and qsum. Before the values are forced, the function dec2bin converts a decimal value to a bit vector. This is necessary because the VHDL entity defines isum and qsum as STD_LOGIC_VECTOR data.

  10. Browse through the rest of manchester_decoder.m.

  11. Close the MATLAB Edit/Debug window.


Learn more about the latest releases of MathWorks products:

 © 1994-2009 The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS