User guide

System Generator for DSP User Guide www.xilinx.com 57
UG640 (v 12.2) July 23, 2010
Compiling MATLAB into an FPGA
Passing Parameters into the MCode Block
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 internal to the block.
The following M-code defines an M-function xl_sconvert is contained in 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 labeled signed convert2 causes it to convert the input data from type
Fix_16_8 to Fix_8_4 at its output.