Efficient packing of data for BlockRAMs, UltraRAMs
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Ryan Baird
2023-3-22
编辑:Ryan Baird
2023-3-22
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 个评论
Ryan Baird
2023-3-23
编辑:Ryan Baird
2023-3-23
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
更多回答(2 个)
Charles
2023-3-29
1 个评论
Ryan Baird
2023-3-29
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:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parrot Minidrones 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!