Filter löschen
Filter löschen

Get error using hdl.ram

2 Ansichten (letzte 30 Tage)
Wayne Radochonski
Wayne Radochonski am 4 Jan. 2023
Kommentiert: Ryan Baird am 6 Jan. 2023
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

Antworten (1)

Ryan Baird
Ryan Baird am 5 Jan. 2023
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 Kommentare
Wayne Radochonski
Wayne Radochonski am 6 Jan. 2023
Ryan,
Appreciate the help. I definitely 'get' the idea that there's a clock somewhere and after one operation to an hdl.ram object, I must wait for the next clock.
What I don't see is what I need to do on the matlab code side to wait until the next clock.
I can see a workaround for now.
All in all, I am totally in love with hdlcoder. This is nothing short of magic.
I almost went to work for Mathworks about 10 years ago after a stint at USRobotics. Met Jack Little and Rich Rovner; great guys, really really smart.
Kurt
Ryan Baird
Ryan Baird am 6 Jan. 2023
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

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by