Get error using hdl.ram
2 次查看(过去 30 天)
显示 更早的评论
I'm implementing a matched filter. Error occurs in Step_PN.m on call to
Rxr = (step(ram_RxQueue,dataIn,ixRx,WR,ixRx));
Error says 'can only run object once'.
How to fix this?
Test Bench:
function MF = Init_Rx_RAM(RW, WrAddressIn, dataIn) %#codegen
% RW = 0; % read RAM
% RW = 1; % write RAM
%
persistent ram_RxQueue
PNLen = 4096;
%
%% Initialize RAM
%
%
if isempty(ram_RxQueue)
ram_RxQueue = hdl.RAM('RAMType','Dual port');
end
%% Write NewSample to RxQueue @ wrAddress
RW = logical(RW);
% data = 4095;
data = (step(ram_RxQueue,dataIn,WrAddressIn,RW,WrAddressIn));
% now run MF using PN and RxQueue
RW = logical(0); % set for READ only
MF = Step_PN(ram_RxQueue, RW, WrAddressIn,dataIn);
end
Test Bench Calls Init_Rx_RAM (writes an audio sample to hdl.ram, then runs matched filter
function MF = Init_Rx_RAM(RW, WrAddressIn, dataIn) %#codegen
% RW = 0; % read RAM
% RW = 1; % write RAM
%
persistent ram_RxQueue
PNLen = 4096;
%
%% Initialize RAM
%
%
if isempty(ram_RxQueue)
ram_RxQueue = hdl.RAM('RAMType','Dual port');
end
%% Write NewSample to RxQueue @ wrAddress
RW = logical(RW);
% data = 4095;
data = (step(ram_RxQueue,dataIn,WrAddressIn,RW,WrAddressIn));
% now run MF using PN and RxQueue
RW = logical(0); % set for READ only
MF = Step_PN(ram_RxQueue, RW, WrAddressIn,dataIn);
end
After writing audio sample, calls Step_PN which runs a matched filter.
function MF = Step_PN(ram_RxQueue, RW, WrAddressIn, dataIn) %#codegen
% RW = 0; % read RAM
% RW = 1; % write RAM
%
% persistent ram_RxQueue
PNLen = 4096;
%
%% Initialize RAM
%
PNr = 0;
RxR = 0;
ixRx = WrAddressIn; % ix into RxQueue (last first)
MF = 0; % will be sum(maxval-abs(PN-(MFBuf)));
WR = logical(0); % set for READ only
% rng(211); % see for randi driving PN
maxval = 2048;
for k = 1:128
% PNr = Init_RAM(WR, wradr, MF,ixPN); % read PN
% Gen PN Code bipolar
PNr = randi([0 1],1,1);
PNr= (PNr.*2 -1).*0.5;
PNr = PNr.*8192;
%
Rxr = (step(ram_RxQueue,dataIn,ixRx,WR,ixRx));
%
MF = MF + (maxval - abs(PNr-RxR));
%
ixRx = ixRx-1; if ixRx == 0, ixRx = PNLen; end % wrap ixRx
end
end
0 个评论
回答(1 个)
Ryan Baird
2023-1-5
Calling "step" inside of a loop is not currently supported.
Instead of having this loop inside of the design executing 128 times, you could consider having a design that represents a single iteration of this loop and a single update to ram_RxQueue.
2 个评论
Ryan Baird
2023-1-6
Right now for code with system objects, there isn't a way to signify that you want to wait until the next clock cycle. The next clock cycle will be the next call to your design's top level function.
We do map portions of the code to faster clock rates than the base rate for loop streaming, but loop streaming doesn't currently support system objects.
The general structure of your code will likely end up looking something like this:
function MF = Step_PN(ram_RxQueue, RW, WrAddressIn, dataIn)
persistent k;
persistent iRx;
if(isempty(k))
k = 1;
ixRx = WrAddressIn;
end
% ...
Rxr = (step(ram_RxQueue,dataIn,ixRx,WR,ixRx));
% ...
k = k + 1;
ixRx = ixRx - 1; if ixRx == 0, ixRx = PNLen; end % wrap ixRx
if(k > 128)
k = 1;
ixRx = WrAddressIn;
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Hardware Modeling with MATLAB Code 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!