Effacer les filtres
Effacer les filtres

Generic data type configuration based on reference precision.

2 vues (au cours des 30 derniers jours)
Eirik Nordeng
Eirik Nordeng le 4 Déc 2023
I am trying to create a generic model that interfaces a hardware component that has a fixed 44-bit data interface. The input signal data type should allow for any value in the range [-1, 1).
I will try to explain via this example:
A signal with data type sfix_27_En29 feeds into the modelled hardware component. I want the system to automatically shift the signal so that it is placed in the 43 downto 14 range (29 bit) of the input of the hardware component, based on the 29-bit precision of the input signal. I tried to accomplish this by using data type propagation, but I cannot understand how to select the range in a generic fashion, i.e. without having to manually specify the range based on the signal data type parameters. Is there any mechanisms in Simulink/HDL Coder that can help me accomplish this?

Réponses (3)

Tom Richter
Tom Richter le 4 Déc 2023
Hi Eirik,
Okay, I think I understand now what you need. First, you only have 27 bits data not 29. Therefore, you want to map the 27 bits from 43 downto 16 (15, 14, and 13 downto 0 would be 0). I found a solution which HDL Coder understands good enough. See the model with comments below:
The Data Type Conversion and 0-Constant block use Inherit via Back Propagation. The 1-Constant block is set to unsigned, no fraction. First step is the conversion from signed with fraction to unsigned without fraction (all bits stay the same - Stored Integer). The important thing here -> no hardware will be required for all the data type calculations as long as the signals involved are only converted and concatenated. Even the MATLAB Function block only outputs a prototype which is not used directly. Here the code:
function diff_prototype = fcn(reference, data)
persistent diff_prototype_temp
if isempty(diff_prototype_temp)
if isfi(reference) && isfi(data)
diff_prototype_temp = fi(0,0,reference.WordLength-data.WordLength,0);
else
warning('The two inputs should be fixed-point.')
diff_prototype_temp = fi(0,0,1,0);
end
end
diff_prototype = diff_prototype_temp;
I did not make it 100% safe. For simulation it only runs at initialization and later just copies the prototype. Would be nice if the Data Type Propagation block would have a subtraction rule for 1.4.1. So I required this work around.
The generated VHDL:
Note: The reference here was an input. It could be a constant with the right data type or just a parameter for the MATLAB Function block. You can make the Area a Subsystem, mask it, and add it to a custom library.
Best regards,
Tom

Tom Richter
Tom Richter le 4 Déc 2023
Here the file I used (R2023b).

Eirik Nordeng
Eirik Nordeng le 19 Déc 2023
Thank you, Tom. Your response does not completely match what I was trying to ask, but it turns out that I had made my issue a lot more complex than it actually was.
I was trying to create a wrapper around a model for a Microchip RTG4 DSP block (which will be black-boxed) that I intend to use as an accumulator component in an NCO. I have to do this because the synthesis tool sometimes does not infer DSP blocks with input and output resgisters and I wish to save as many fabric registers as possible. The accumulator wrapper is to be part of a library and I wanted it to be generic wrt. input and output data types.
The input to the DSP block and its accumulator register is 44 bit wide. Since this is part of an NCO, I want the accumulator value to wrap at 1. Consequenty, the example input data type sfix_27_En29 must be mapped to the 29 MSBs of the DSP block input.
I achieved this by simply converting to sfix44_44 before stripping the scaling of the signal. The scaling was later reintroduced to the accumulator output via data type propagation (referred to the input signal).

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by