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

105 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

MathWorks Fixed Point Team
MathWorks Fixed Point Team am 27 Aug. 2020
Bearbeitet: MathWorks Fixed Point Team am 22 Mär. 2023
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.
Limitation removed in R2021b
The limitation with displaying binary, hex, and octal in port value displays (yellow boxes) for the six integer types int8, uint8, int16, uint16, int32, and uint32 was removed in R2021b. The yellow boxes now display binary, hex, and octal, as requested, for ALL integer and fixed-point types.
  3 Kommentare
Andy Bartlett
Andy Bartlett am 10 Nov. 2021
Bearbeitet: Andy Bartlett am 10 Nov. 2021
Hi Mohit,
Hmm ...
Display Block
For the Display Block, the four stored integer options hex, binary, octal, and decimal should work as expected for both fixed-point types and integer types. These choices do not apply to floating point types.
Simulink Display Values (yellow boxes)
For Simulink Display Values, as mentioned in the last sentence of my answer and in the image above it, there is a known limitation where six of the built-in integer types do not show binary, hex, or octal. As a result with Simulink Display Values, binary, hex, and octal will only be shown with int64, uint64, and fixed-point types. The work around to this limitation would be to use the Display Block instead of or in addition to the Simulink Display Values yellow boxes.
With regard to floating-point type, neither Simulink Display Values nor Display block will show binary, hex or octal for inputs using those data types.
Does the case you are having trouble with fall into the known limitation just described?
If the case is outside the known limitation, then that would likely be a bug. Please upload a simplifed example model showing the issue that's beyond the known limitation.
Mohit
Mohit am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by