System object methods can only be called once
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I get a error in HDL coder when using hdl.RAM objects. The testbench is test.m, and the calling fuction is gamma_table_new.m. In this gamma_table_new function, a MAT file was loaded to initiallized the hdl.RAM gamma_table_ram. The original scripts are attached as attchments and also posted as below.
Actually I've been trying to load experiment data into ram(not register), applying to FPGA. The pasted gamma_table was just for test. I just came up with initiallization with MAT file and I'm not sure if there are other solutions.Can anyone help?Thanks!
%%%%%%%%%%%%%%%%%%%test.m%%%%%%%%%%%%%%%
im_width=1080;
im_height=20;
indata=double(imread('1.bmp'));
for i=1:im_height
for j=1:im_width
R_in=indata(i,j,1);G_in=indata(i,j,2);B_in=indata(i,j,3);
[R_out,G_out,B_out]=gamma_table_new(R_in,G_in,B_in);
outdata(i,j,1)=R_out;
outdata(i,j,2)=G_out;
outdata(i,j,3)=B_out;
end
end
figure;
subplot(2,1,1);imshow(indata,[]);
subplot(2,1,2);imshow(outdata,[]);
%%%%%%%%%%%%%%%%%%%test.m%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%gamma_table_new.m%%%%%%%%%%%%%%%
function [R_out,G_out,B_out]=gamma_table_new(R_in,G_in,B_in)
persistent gamma_table_ram;
data_gamma=0;
data_in=0;
if isempty(gamma_table_ram)
gamma_table_ram=hdl.RAM('RAMType','Single port','WriteOutputValue','Old data');
gamma_table_struct= coder.load('gamma_table.mat');
gamma_table=gamma_table_struct.g1;
for i=0:255
data_in=gamma_table(i+1);
data_gamma=step(gamma_table_ram,data_in,i,true);
end
end
step(gamma_table_ram,data_in,R_in,false);
R_out=step(gamma_table_ram,data_in,R_in,false);
step(gamma_table_ram,data_in,G_in,false);
G_out=step(gamma_table_ram,data_in,G_in,false);
step(gamma_table_ram,data_in,B_in,false);
B_out=step(gamma_table_ram,data_in,B_in,false);
end %%%%%%%%%%%%%%%%%%%gamma_table_new.m%%%%%%%%%%%%%%%
0 commentaires
Réponses (1)
Kiran Kintali
le 16 Mai 2021
Consider splitting the logic into reset, update, output secttions.
Persistent variables result in registers. Persistent variable initalization should be in its own if isempty() condition. The logic moves to reset section of the generated HDL Code.
See following pages for best practices on this topic.
Persistent Variables and Persistent Array Variables
Initialize Persistent Variables in MATLAB Functions
Map Persistent Arrays and dsp.Delay to RAM
https://www.mathworks.com/help/hdlcoder/ug/how-to-map-persistent-arrays-to-ram.html
0 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!