Fixed-Point Blockset | ![]() ![]() |
Convert a Simulink data type to a Fixed-Point Blockset data type
Library
Description
The Gateway In block is a masked S-function that converts a built-in Simulink data type to a Fixed-Point Blockset data type.
The Input and Output to have equal parameter list controls how the input is processed. The possible values are Real World Value and Stored Integer. In terms of the general encoding scheme described in Scaling, Real World Value treats the input as V = SQ + B where S is the slope and B is the bias. V is used to produce Q = (V - B)/S, which is stored in the output. Stored Integer treats the input as a stored integer, Q. The value of Q is directly used to produce the output. In this mode, the input and output are identical except that the input is a raw integer lacking proper scaling information. In both modes, the output data type includes the scaling information needed to correctly interpret the signal as a real-world value.
For a detailed description of all other block parameters, refer to Block Parameters.
Parameters and Dialog Box
Examples
This example uses the Gateway In block to help you understand the difference between a real-world value and a stored integer. Consider the two fixed-point models shown below.
In the top model, the Gateway In block treats the input as a real-world value, and maps that value to an 8-bit signed generalized fixed-point data type with a scaling of 2-2. If the value is output from the Gateway Out block as a real-world value, then the scaling and data type information is retained and the output value is 001111.00, or 15. If the value is output from the Gateway Out block as a stored integer, then the scaling and data type information is not retained and the stored integer is interpreted as 00111100, or 60.
In the bottom model, the Gateway In block treats the input as a stored integer, and the data type and scaling information is not applied. If the value is output from the Gateway Out block as a real-world value, then the scaling and data type information is applied to the stored integer, and the output value is 000011.11, or 3.75. If the value is output from the Gateway Out block as a stored integer, then you get back the original input value of 15.
The model shown below illustrates how a summation operation applies to real-world values and stored integers, and how scaling information is dealt with in generated code.
Note that the summation operation produces the correct result when the Gateway Out block outputs a real-world value. This is because the specified scaling information is applied to the stored integer value. However, when the Gateway Out block outputs a stored integer value, then the summation operation produces an unexpected result due to the absence of scaling information.
If you generate code for the above model, then the code captures the appropriate scaling information. The code for the Sum block is shown below. The inputs to this block are tagged with the specified scaling information so that the necessary shifts are performed for the summation operation.
/* Sum Block: <Root>/Sum * * y = u0 + u1 * * Input0 Data Type: Fixed Point S16 2^-2 * Input1 Data Type: Fixed Point S16 2^-4 * Output0 Data Type: Fixed Point S16 2^-5 * * Round Mode: Floor * Saturation Mode: Wrap * */ sum = ((in1) << 3); sum += ((in2) << 1);
Characteristics
Input Port |
Any built-in Simulink data type |
Output Port |
Any data type supported by the blockset |
Direct Feedthrough |
Yes |
Scalar Expansion |
No |
See Also
![]() | Gain | Gateway In Inherited | ![]() |