- To create a custom block that supports inputs of different sizes.
- To create a custom block that accepts signals with different fixed-point lengths and fractional lengths.
- To perform simple arithmetic operations using template variables.
- Navigate to the Lab2/section2 folder.
- Double-click the template_design.h
file to view the source code in the MATLAB
Editor. There are two functions: Demux and Mux. These two functions are a
multiplexing and demultiplexing of inputs as shown in the following
- In the piece of code, note the
#pragma XMC INPORT vector_in. This is a way to manually specify port directions using pragmas. Here, we are specifying the function argument
vector_inas the input port. Similarly, we can define
XMC OUTPORTalso.Note: For additional information about specifying ports, see Vitis Model Composer User Guide (UG1483).
- Notice the use of template before the function declaration. To support the inputs of
NUMOFELEMENTSis declared as a parameter and used the same while defining an array
vector_inas shown in the following figure. This allows you to connect signals of different sizes to the input port of the block.
- Notice the template parameters
Iwhich are declared to accept signals with different word lengths and integer lengths.
Note: The same library is specified for both the functions.
- Observe the arithmetic operations performed using template variables as shown below,
indicating the output signal length is half of the input signal length.
- Similar explanation follows for Mux function.
Now create the library blocks for Mux and Demux functions using the
xmcImportFunctioncommand and complete the design below with custom blocks.
- Double-click the import_function.m
script file in the MATLAB command window and
observe the following commands that generate library blocks to embed into your
- Run the import_function.m script from
the MATLAB command
- Observe the generated library blocks in the design_lib.slx library
model file and save it to working directory.
- Copy the Demux and Mux blocks and paste them in the
design.slx file and connect them as shown in the
- Note the following after embedding the custom blocks:
- Double-click the Constant block and observe the vector input of type double. SSR is a workspace variable, initially set to 8 from the initFcn model callback.
- Using the Data Type Conversion (DTC) block, double type is converted to
fixed type with 16-bit word length and 8-bit fractional length.
Input is configurable to any word length since the design is templatized.
- Double-click the Demux block and observe the Template parameters section
and Dimension column in the Interface section of the function tab.
- Next, double-click the Mux block and observe the Template parameters and Dimension.
- Add a Display block at the input and output as shown in the following figure and
simulate the model to observe the results.
- To understand how templatized inputs add advantage and flexibility to your
design, perform the following:
- Double-click the DTC block.
- In the Block Parameters dialog box, change the Word length from 16 to 32.
- Change the Fractional length from 8 to 16.
- Click OK and
press Ctrl+D. Observe the signal
dimensions in the design.
To make sure the output is correct, run the simulation and observe that the same block can still be used in a generic way for different values of Word length and Fractional length. This is possible only because we have templatized the
Ivalues in our
- For an additional understanding of template parameters, perform the
- Click the arrow mark beside the Model Configuration Parameters icon and select the
Model Properties option.
- In the Model Properties window, go to the
Callbacks tab and select
initFcn and edit the SSR value from 8 to 16
as shown in the following figure.
- Click OK and press Ctrl+D
to observe the change in the number of elements in the Constant block
output vector. The bitwidth changes when we change the datatype on the
input DTC. This is possible only because of the template parameter
- Run the simulation and validate the output according to the input values.
- Click the arrow mark beside the Model Configuration Parameters icon and select the Model Properties option.