Passing Parameters into the MCode Block - 2025.2 English - UG1483

Vitis Model Composer User Guide (UG1483)

Document ID
UG1483
Release Date
2025-11-20
Version
2025.2 English

This example shows how to pass parameters into the MCode block. An input argument to an M-function can be interpreted either as an input port on the MCode block, or as a parameter within the block.

The following M-code defines an M-function xl_sconvert that is in the file xl_sconvert.m:

function dout = xl_sconvert(din, nbits, binpt)
  proto = {xlSigned, nbits, binpt};
  dout = xfix(proto, din);

The following diagram shows a Subsystem containing two MCode blocks that use M-function xl_sconvert. The arguments nbits and binpt of the M-function are specified differently for each block by passing different parameters to the MCode blocks. The parameters passed to the MCode block labeled signed convert 1 cause it to convert the input data from type Fix_16_8 to Fix_10_5 at its output. The parameters passed to the MCode block signed convert 2 cause it to convert the input data from type Fix_16_8 to Fix_8_4 at its output.

Figure 1. Subsystem with Two MCode Blocks Generated by Your Tool

To pass parameters to each MCode block in the diagram, click Edit M-File in the block GUI. Then set the M-function argument values. The following figure shows the mask for MCode block signed convert 1.

Figure 2. Masking MCode Block

The above interface window sets the M-function argument nbits to be 10 and binpt to be 5. The following figure shows the mask for the MCode block signed convert 2.

Figure 3. Mask for MCode Block Signed Convert 2