Accumulator Data Type not used in ERT generated code
古いコメントを表示
Here's an example model (Made/tested using R2017b):

As you can see I've made sure all data types used anywhere in this model are 'uint16' data type. I've also configured the 'sum' block to use this as the accumulator data type by matching the first input.
Here is the _step() function that gets generated when building this model using embedded coder (ERT target):
/* Model step function */
void testCounter_step(void)
{
/* UnitDelay: '<Root>/Unit Delay' */
testCounter_B.UnitDelay = testCounter_DW.UnitDelay_DSTATE;
/* Outport: '<Root>/count' incorporates:
* Constant: '<Root>/Constant1'
* Sum: '<Root>/Sum'
*/
testCounter_Y.count = (uint16_T)(((uint32_T)testCounter_B.UnitDelay) +
((uint32_T)((uint16_T)1U)));
/* Update for UnitDelay: '<Root>/Unit Delay' incorporates:
* Outport: '<Root>/count'
*/
testCounter_DW.UnitDelay_DSTATE = testCounter_Y.count;
}
The actual sum operation is converting both inputs to uint32, then performing the addition, then converting back to uint16. Why is it doing this? I thought that specifying the accumulator data type to use the same as first input would avoid these unnecessary conversions?
For reference, here are the hardware settings (should support 16-bit native math using 'short'). Let me know if there are any other model settings which need looked at.

採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Simulink Coder についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!