Simulink data type conversion, single to uint16.

Hello,
I'm using simulink and I need to convert from a single to a uint16.
Could a kind soul kindly explain why the output of a single (with range 0-2pi) equates to an uint16 of zero?
Here is an example:
And here is the output of that example:
There are a number of uint16 signals in my model with range 0-4000 (I am reading from sevreral ADC). All behave as expected. Just this conversion, in this instance.

5 comentarios

Daniel
Daniel el 18 de Sept. de 2024
What is happening to that value downstream? Are you generating code? Is it being used for trigonometry?
Walter Roberson
Walter Roberson el 18 de Sept. de 2024
Are you using the Data Type Conversion Block? https://www.mathworks.com/help/simulink/slref/datatypeconversion.html
Walter Roberson
Walter Roberson el 18 de Sept. de 2024
I would expect single range 0 to 2*pi to convert to uint16 values 0, 1, 2, 3, 4, 5 or 6.
Data type conversion does not do any scaling to match the range. For example it is not going to scale 0 to 2*pi to 0 to 62831
Jamie
Jamie el 19 de Sept. de 2024
Editada: Jamie el 20 de Sept. de 2024
Thanks Daniel, Walter. The signal is being output to a host model using a data serial output. The data serial output transmits two signals of type uint16. An example from the mcb;
Yes, I'm using data type conversion block. Sending multiple signals (more than 2), using PU units / a different data type would be preferable.
Jamie
Jamie el 25 de Sept. de 2024
I still continue to see scaling during data type conversions. This seems very unusual.
Ex. Scaling from 0-1 to 0-4045

Iniciar sesión para comentar.

 Respuesta aceptada

Hitesh
Hitesh el 19 de Sept. de 2024
Editada: Hitesh el 19 de Sept. de 2024

0 votos

Hi Jamie,
I am assuming that you have used "Data Type Conversion" block, and the conversion to "uint16" resulted in unexpected values due to the default integer rounding mode being set to "floor" in Block Parameters. If you change the rounding mode to "round," you will achieve the expected results when converting from "single" to "uint16".

1 comentario

Jamie
Jamie el 21 de Sept. de 2024
Editada: Jamie el 21 de Sept. de 2024
Thanks all for the comments! Got around it by altering the model and removing the uint conversin blocks.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 18 de Sept. de 2024

Comentada:

el 25 de Sept. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by