Need help for Error happened during using SIMULINK HDL coder
1 view (last 30 days)
Show older comments
I have next code , and related SIMULINK model , want to convert to VHDL code , using SIMULINK HDL coder , but error happened :
clear clf
I1=1989;I2=1876;I3=407;h=53.66;m1=257.419;m2=154.062;b3=6.86157e-8;n=.0042; a=[0 0 1 0;0 0 0 1;-h*n/I1 0 0 -h/I1;0 -n*h/I2 h/I2 0]; %a =[0 0 1 0;0 0 0 1;-0.0017 0 0 -0.0270;0 -0.0018 0.0286 0]; b=[0;0;m2*b3/I1;m1*b3/I2]; %b = 1.0e-008 *[0;0;0.5315;0.9415]; c=[1.0e-7 1.0e-6 8.0e-4 1.0e-3]; %roots=-4.3741+--89.274i,-1.2517 g=22; % g < 1/4*max eigen tf=43200; [Ad,Bd]=c2d(a,b,g);
% desired output lamda=1.0e-7 ; a4=1.0e-3 ; a3=1.0e-4; a2=1.0e-6 ; xd=0 ; q=50 ; k=10 ; x=[.5;0;0;.007]; t=0; u=0 ; i=1 ;
while t<tf x1=x(1);x2=x(2);x3=x(3);x4=x(4); xx1(i)=x1;xx2(i)=x2; xx3(i)=x3;xx4(i)=x4;uu(i)=u;t1(i)=t; s =a4*x4+a3*x3+a2*x2+lamda*(x1-xd); % switching surface I4 = [1 0 0 0;0 1 0 0;0 0 1 0;0 0 0 1]; u =-c*(a+q*I4/abs(c*x)+k*I4)*x -k*s ; x = Ad*x+Bd*u ; i=i+1; t=t+g; end subplot(2,2,1), plot(t1,xx1);grid;title('Roll Response'); subplot(2,2,2), plot(t1,uu);grid; title('U input Response'); subplot(2,2,3), plot(t1,xx4);grid; title('Yaw Response'); subplot(2,2,4), plot(t1,xx3);grid; title('Yaw Rate Response');
best regards
0 Comments
Accepted Answer
Tim McBrayer
on 9 May 2013
If you are starting with MATLAB code and not a Simulink model, I would suggest using HDL Coder to generate VHDL directly from your MATLAB code, as opposed to attempting to convert your MATLAB code to a Simulink model. To learn how to do this, please consult the documentation and demos, which will walk you through the process.
Some things immediately come to mind upon looking at your code, though. You have a section of code that creates plots. This can not be converted to hardware. You will need to separate your code into your design (the part which implements your algorithm) and the test bench (that provides stimulus to the algorithm and displays the results).
2 Comments
Tim McBrayer
on 10 May 2013
I see. Support for direct MATLAB to VHDL code generation was not added to HDL Coder until R2012a. Using R2008(a or b), you will need to convert your design into Simulink. You will need to figure out what your core computational kernel is and implement it in a MATLAB Function block. You'll need to convert it manually to fixed-point if you want to be able to synthesize it. And, of course, you'll need to determine how to drive your input vectors using Simulink.
More Answers (0)
See Also
Categories
Find more on HDL Coder in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!