Efficient packing of data for BlockRAMs, UltraRAMs
2 views (last 30 days)
Show older comments
Hi,
I have a system where there's four channels of 18-bit data processed simultaneously and written to a RAM as 4096 words x 4 channels of data. HDL Coder seems to want to instantiate four separate RAMs (appears that way in the Verilog), and Vivado shows this too.
I'd like to see the four channels packed into a 72-bit word and written to one location in an UltraRAM. I specified "ultra" for the RAMDirective, and this "works" - the netlist shows four UltraRAMs in use, so at least we've got UltraRAMs.
But how do I get the data packed into a single 72-bit word? Is that something I need to do in the Simulink diagram?
Thanks,
Charles
0 Comments
Accepted Answer
Ryan Baird
on 22 Mar 2023
Edited: Ryan Baird
on 22 Mar 2023
The RAM block interprets vectors of data to mean you want separate RAM banks. In order to store and retreive the data as a single value, you currently need to combine the data before writing and separate the data after reading outside of the RAM block. The easiest way I'm aware of to do this is with the Bit Concat and Bit Slice blocks. You could use a Bit Concat block before the RAM block to combine the data, and use Bit Slice blocks after the RAM block to separate the read data back into 4 different values.
5 Comments
Ryan Baird
on 23 Mar 2023
Edited: Ryan Baird
on 23 Mar 2023
One possibility is that you could concatenate one type and not the other. That might be easier to do with MATLAB Function blocks, e.g.:
function out = concatIfNotDouble(v)
if(isa(v(1), 'double'))
out = v;
else
% Assumed array of four 18 bit fixpt values
out = bitconcat(v(4), v(3), v(2), v(1));
end
end
function out = splitIfNotDouble(v)
if(isa(v(1), 'double'))
% 4 double values
out = v;
else
% Assumed 72 bit value to be split into four 18 bit values
out = fi(zeros(1,4), 0, 18, 0);
for i = 0:3
start=18*i+1;
out(i+1) = bitsliceget(v,start+17,start);
end
end
end
More Answers (2)
Charles
on 29 Mar 2023
1 Comment
Ryan Baird
on 29 Mar 2023
There's a function "typecast" for converting between integer and floating point types, keeping the same underlying data (similar to a c++ reinterpret_cast), and there's a function "reinterpretcast" for converting between integer and fixedpoint types while keeping the same underlying data:
See Also
Categories
Find more on Parrot Minidrones in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!