Clear Filters
Clear Filters

how can i show figure in my m-file?

2 views (last 30 days)
Hi Im going to execute these codes in matlab in order tc generate hdl code
:function [iport,tnext] = ADD_TESTER (oport, tnow, portinfo)
persistent ud; %Create a struct to store persistent user data
tnext = []; %initialize tnext to null
iport = struct(); %initialize iport to null
if(nargin ==3) %First call has 3 arguments
ud.call_count = 0; %Initialize call counter
tnext = tnow+100e-9;%Next invocation after 100 ns
iport.a = '0';
iport.b = '0';
iport.cin = '0';
else
ud.call_count = ud.call_count + 1;
if ud.call_count < 8 %run for 8 cycles
tnext = tnow+100e-9; %Next invocation after 100 ns
bin = dec2bin(ud.call_count,3);%Convert counter to binary string
iport.a = bin(1); %Assign bits of bin to 3 inputs
iport.b = bin(2);
iport.cin = bin(3);
else
disp('Over'); %If 8 cycles are over, don’t invoke with tnext
end
end
AND THE ERROR IS:Error in ADD_TESTER (line 15)
ud.call_count = ud.call_count + 1;
>> ADD_TESTER
15 ud.call_count = ud.call_count + 1;
K>>
PLZ HELP ME THANK YOU SO MUCH!
  2 Comments
Walter Roberson
Walter Roberson on 28 Feb 2013
What error message is given?
shide agani
shide agani on 1 Mar 2013
Error in ADD_TESTER (line 15)
ud.call_count = ud.call_count + 1;
>> ADD_TESTER
15 ud.call_count = ud.call_count + 1;
K>>

Sign in to comment.

Accepted Answer

Tim McBrayer
Tim McBrayer on 28 Feb 2013
The MATLAB HDL Coder demos are an excellent way to learn how to generate HDL code from MATLAB. They are probably the best place to start to get the answers to your questions.
I'm not sure what you are trying to model here. For HDL Coder to generate code from MATLAB, you need a design and a testbench. You do not need to model time. You cannot use MATLAB functions like 'disp' that have no hardware equivalent.
I suggest you determine what hardware you wish to build and write a MATLAB function that implements that function. If you wish to build a counter, build a function that increments its output value each time it is called. Then, implement a testbench that exercises the model by calling it in a loop, providing any inputs that are necessary. Once this simulates correctly, then you can try the code in HDL Coder.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!