How to get the stored integer representation of a single-precision floating point in simulink (HDL Coder)?

8 views (last 30 days)
I need to get the stored integer representation of a floating point single precision value in Simulink (synthetisable for HDL Coder), to get the Sign, Exponent and Mantissa. Something like the first stage of Generate Target-Independent HDL Code with Native Floating-Point - MATLAB & Simulink - MathWorks France. However trying to reproduce this flowchart using data type conversion with Stored Integer (SI) parameters results in null output (see below, expected 00111101110011001100110011001101 (0x3dcccccd) for 0.1). Running on Matlab R2021b.
How can I achieve that?
Thank you

Accepted Answer

Kiran Kintali
Kiran Kintali on 11 Jan 2024
Edited: Kiran Kintali on 11 Jan 2024
Float Typecast
Typecast a floating-point type to an unsigned integer or vice versa
>> openExample('hdlcoder/SimulateAndGenerateHDLCodeFloatTypecastBlockExample')

More Answers (2)

Hassaan
Hassaan on 11 Jan 2024
Edited: Hassaan on 11 Jan 2024
Data Type Conversion: Use a Data Type Conversion block to convert the single type to a fixdt(1,32,0) data type. This conversion block will interpret the bits of the single-precision floating-point number as a fixed-point number with one sign bit, 32-bit word length, and zero fractional bits.
Output as Integer: To get the output as an integer, you can then convert the fixed-point number to an integer type using another Data Type Conversion block.
However, you mentioned that you are getting null output with this method. This issue could be due to several reasons, such as block configuration issues or Simulink model settings that are not compatible with the expected operation.
Here are some troubleshooting steps:
  • Ensure Correct Configuration: Double-check the configuration of the Data Type Conversion block to make sure it's set up to convert from single to fixdt(1,32,0).
  • Check Simulation Mode: Make sure you're running the simulation in a mode that supports the required data type conversions (for example, normal mode).
  • Update Blocks and Settings: If you're working with an older version of Simulink or your blocks are deprecated, update them to the latest versions.
  • Model Configuration Parameters: Access the Model Configuration Parameters (Ctrl+E) and ensure that the Hardware Implementation settings are compatible with your intended target and data types.
Try using Float Typecast block:
If these steps don't resolve the issue, please provide more specific details or error messages you might be receiving. That would help in diagnosing the issue further. If it's a bug or a version-specific issue, checking the MathWorks support forums or contacting MathWorks support may be necessary.
---------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

Fangjun Jiang
Fangjun Jiang on 11 Jan 2024
Use a MATLAB Function block
sprintf('%tx',single(0.1))
ans = '3dcccccd'

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!