Project

General

Profile

Extend the format specifiers in the sprintf block

Added by Johan Henning almost 2 years ago

At this moment only these specifiers are supported:
%u, %i, %o, %x: uint32
%d: int32
%e, %g, %f: single
%c: int8
%s: vector of data type uint8

It would be very nice if flags, width, .precision and modifiers can be specified as well (like in the standard (s)printf functions to align values in colums.
Examples:
%5u
%2.4f
%04d

See: https://cplusplus.com/reference/cstdio/printf/


Replies (2)

RE: Extend the format specifiers in the sprintf block - Added by Shawn Sebastian Pulle (ฌอน) almost 2 years ago

Hi Johan,

Thank you for the feedback.

The Xilinx tools use a slightly different version of the printf function named xil_printf. It does not contain the same functionality of the printf function commonly used.
https://docs.xilinx.com/r/2021.2-English/oslib_rm/xil_printf

One of the differences is, it not supporting floating point numbers. Currently the floating point numbers are processed as strings in our block set as a work around for this problem. Therefore, getting precision would be difficult for certain data types.
It is possible to give width/padding for other data types, but it would be inconsistent across all data types and ultimately a bit confusing as to why one thing works and the other doesn't work.

We will consider your suggestion to be implemented in the future after testing, as long as it can be implemented without creating further confusion to the users.

RE: Extend the format specifiers in the sprintf block - Added by Johan Henning almost 2 years ago

Hello Shawm,
There is a very nice (native) Simulink block (compose string). According to the documentation and in simulation mode it does everything I want. But when using it for the 7000 it does not work right. Do you understand why not?
Regards,
johan.

    (1-2/2)