MATLAB: Is the value of a Constant block with fixed point data type scaled incorrectly when I generate code from a Simulink model

codeEmbedded Coderfixedformatfractiongeneratedgenerationincorrectlengthpointq

Why is the value of a Constant block with fixed point data type scaled incorrectly when I generate code from a Simulink model?
I have a Constant block in my Simulink model whose value is 1.25. I have set the data type of this block to be "fixdt(1,32,15)", which means that the value should be scaled to 1.25 * 2^15 = 40960. However when I generate code from this model, the constant appears as 5120, which would be the case if the fraction length was 12 instead of 15 (1.25 * 2^12 = 5120). 
Why is this happening?

Best Answer

This issue can occur when Simulink performs some optimizations to reduce redundancies in the model. In some cases the optimization decides that the additional fraction length is not needed and a shorter fraction length is used.
In order to observe the original fraction length in the generated code, the "Block Reduction" option in "Configuration Parameters -> Optimization" (or "Configuration Parameters -> All Parameters") can be turned off.