Efficient way to dispatch a pack of values to vector of uint8 in Simulink style
27 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dimitri
am 1 Sep. 2025 um 12:55
Kommentiert: Dimitri
vor etwa eine Stunde
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 Kommentare
Akzeptierte Antwort
Abhipsa
am 3 Sep. 2025 um 5:42
Bearbeitet: Abhipsa
am 3 Sep. 2025 um 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulink Functions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!