Download Block Parameters
Transcript
MCode
c = xl_slice(a, xl_nbits(a)-1, xl_nbits(a)-1);
Concatenate Function: xl_concat
Function x = xl_concat(hi, mid, ..., low) concatenates two or more fixed-point
numbers to form a single fixed-point number. The first input argument occupies the most
significant bits, and the last input argument occupies the least significant bits. The output
is an unsigned fixed-point number with binary point position at zero.
Reinterpret Function: xl_force
Function x = xl_force(a, arith, binpt) forces the output to a new type with arith
as its new arithmetic type and binpt as its new binary point position. The arith argument
can be one of xlUnsigned, xlSigned, or xlBoolean. The binpt argument must be
from 0 to the bit width inclusively. Otherwise, the block will throw an error.
State Variables: xl_state An MCode block can have internal state variables that hold their values from one simulation
step to the next. A state variable is declared with the MATLAB keyword persistent and must
be initially assigned with an xl_state function call.
The following code models a 4-bit accumulator:
function q = accum(din, rst)
init = 0;
persistent s, s = xl_state(init, {xlSigned, 4, 0});
q = s;
if rst
s = init;
else
s = s + din;
end
The state variable s is declared as persistent, and the first assignment to s is the result of
the xl_state invocation. The xl_state function takes two arguments. The first is the
initial value and must be a constant. The second is the precision of the state variable. It can
be a type cell array as described in the xfix function call. It can also be an xfix number.
In the above code, if s = xl_state(init, din), then state variable s will use din as the
precision. The xl_state function must be assigned to a persistent variable.
The xl_state function behaves in the following way:
1. In the first cycle of simulation, the xl_state function initializes the state variable with
the specified precision.
2. In the following cycles of simulation, the xl_state function retrieves the state value
left from the last clock cycle and assigns the value to the corresponding variable with
the specified precision.
Vivado: Designing with System Generator
UG958 (v2012.3) November 16, 2012
www.xilinx.com
209