How do I show the hex or binary representation for an integer or fixed-point signal in Simulink?

80 views (last 30 days)
When designing or debugging integer or fixed-point algorithms, there are many cases where it is helpful for the display of values to show their hexidecimal or binary representations. How do I get the display of a signal in Simulink to show my preference of hex or binary?

Accepted Answer

MathWorks Fixed Point Team
Edited: MathWorks Fixed Point Team on 28 Aug 2020
Simulink provides two ways to show hex and binary of signals, Display Block, and Simulink Value Display (yellow boxes).
Method 1: Using Display Blocks to show Binary and Hex
The dialogs for Display Blocks provide nine options for Numeric display format. These include hex, binary, decimal, and octal.
You'll notice that 4 options contain the postfix text '(Stored Integer)'.
That relates to the scaling equation
RealWorldValue = StoredIntegerValue * Slope + Bias
Real World Value is in units familiar to the human engineer.
Stored Integer is the value that's actually stored in the computer memory.
A special case is binary point scaling where Bias = 0 and Slope = 2^-FractionLength, so
RealWorldValue = StoredIntegerValue * 2^-FractionLength
Another special case are integers where Slope = 1 and Bias = 0,
so the equation is Trivial
RealWorldValue = StoredIntegerValue
and the two values are identical.
This model was configured such that
1st and 5th display blocks use long format (implies Real World Value).
2nd and 6th display blocks use decimal (Stored Integer) format.
3rd and 7th display blocks use hex (Stored Integer) format.
4th and 8th display blocks use binary (Stored Integer) format.
When we simulate the model, we notice a few things about the Display blocks.
|
In the 2nd, 3rd, and 4th, display blocks, we see that the text '(SI)' comes before the value.
This is indicating that the Stored Integer is being shown.
The 6th, 7th, and 8th, display blocks, could show the '(SI)' prefix, but do not.
For these blocks, the input is integer so Real World Value and Stored Integer Value are equal.
Thus the '(SI)' prefix is not needed to disambiguate the two kinds of values and is omitted.
Method 2: Using Simulink Display Values (yellow boxes) to Show Binary and Hex
There is another way to display Stored Integer binary, hex, decimal, or octal is Simulink Display Values. You'll remember these as the yellow boxes that appear under Simulink signals.
To turn on this capability, use the toolstrip Debug Tab.
After Toggle option is checked (i.e. ON), click the signal lines where you want the yellow boxes to be shown.
Next go back to the toolstrip Debug tab to open the Value Displays: Options dialog.
There in the lower right of the Options dialog, you will see the same 9 format choices from the Display Block.
After the Display Format is set to the desired value, close the dialog and simulate the model.
The yellow boxes will show your choice of format.
However, there is a known limitation. Six integer types int8, uint8, int16, uint16, int32, and uint32 do not display hex, binary, or octal in the yellow boxes. For these six exceptions, you will need to use the Display Block if you want to see hex, octal, or binary.
  3 Comments
Mohit Singh
Mohit Singh on 3 Feb 2022
Thank you so much for your response.🙌
Due to my failure to use the Stored Integer as an output for the Constant block, the Display block was not working.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by