Efficient way to dispatch a pack of values to vector of uint8 in Simulink style

29 visualizaciones (últimos 30 días)
Dimitri
Dimitri el 1 de Sept. de 2025 a las 12:55
Comentada: Dimitri el 4 de Sept. de 2025 a las 13:57
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.

Respuesta aceptada

Abhipsa
Abhipsa el 3 de Sept. de 2025 a las 5:42
Editada: Abhipsa el 3 de Sept. de 2025 a las 5:43
Hello @Dimitri,
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.

Más respuestas (0)

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by