MATLAB: Uint8 vs. double in Simulink

doublesimulinkuint8

Hi,
Some blocks in Simulink supports several output formats. Is it better to set it as unit8 for byte based data rather than double? I remember such way is recommended for VHDL programming.
Thanks Senmeis

Best Answer

Hello Owen, Your question is somewhat generic. For instance, if you are using a source, say a constant, and you expect it to be a uint8 then that would be fine. But if you are doing an operation, say an addition, with two double signals then I would strongly advise you against having the add block output anything other than the input signal types. It can lead to hard to find bugs and also the MISRA Autocode Design Guidelines for Simulink and Stateflow http://www.misra.org.uk/Publications/tabid/57/Default.aspx#label-ac-slsf Rule ID 003 requires you not to do that, literally it reads:
"Only the DATA TYPE CONVERSION block must be used where signal data type conversion is required, i.e. data type conversion must not be performed by any other Simulink block, e.g. gain, product, divide, sum, inport, outport."
Hope this helps.
Related Question