Get error using hdl.ram
조회 수: 1 (최근 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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!