Efficient way to dispatch a pack of values to vector of uint8 in Simulink style
29 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have a low-lever function for calculating CRC-8 SAE J1850 to be sent over CAN.
This function takes a vector of [uint8 x N].
But in my model I have different entry variables (uint8, uint16 and uint32).
I'm searching for elegant way to dispatch model variables to a vector of corresponding [uint8 x N].
I've tried to use a Concat block and the Matlab function, but got an error while propagating ufix values.

0 件のコメント
採用された回答
Abhipsa
2025 年 9 月 3 日 5:42
編集済み: Abhipsa
2025 年 9 月 3 日 5:43
I have invesstigated your model and understand your concern on how to turn a few mixed-width scalars (uint8/uint16/uint32) into a single "uint8[1×N]" buffer for CRC-8 block without getting the ufix type-propagation error.
To mitigate this issue, "Byte Pack" block instead of "bit concat" block should be used. As, the bit cooncat block uses the "bitconact" function to perform the operation. When you use "bitconcat", the output is an unsigned fixed-point array. Its word length is the total of all input word lengths, and its fraction length is set to zero. Due to this reason you were getting output as ufix56 as 8+16+32 = 56.
You can refer to the official MATLAB documentation for "bitconcat" here:
After using the Byte Pack block, the signal u is already a plain uint8 vector, not a fixed-point scalar. So, the MATLAB function block "dispatch to" can be modified as below:
function y = fcn(u)
%#codegen
% u is a uint8 vector from Byte Pack
% ensure row shape
y = uint8(u(:).'); % force [1xN] row vector
This ensures that your model works without any error. I am attaching the updated model.
I hope this resolved your query.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Simulink Functions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!