Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to convert Matlab function to VHDL????

Status
Not open for further replies.

EngHussein

Newbie level 3
Newbie level 3
Joined
Feb 5, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,301
Dear all
I have wrote the below code in matlab function - simulink in order to act as a Fuzzy controller, that code has been simplified in order to be converted to VHDL code to be run on Quartus - Altera KIT

I have faced several essential errors can anyone help by this..... thanks in advance for your coopration

here is the code

Code:
function y = fcn(u)

%#codegen
sf = 9;
      CnN=-1*sf;
      CnP=1*sf;
      Cz=0;
      cj= 0.5*sf;

cen=(abs(CnN-u))/cj;
cep=(abs(CnP-u))/cj;
cez=(abs(Cz-u))/cj;

%-----------------------------------%
    if (cen >1)
   men=0;
else
    men=1-cen;
    end;

    if(cep >1)
   mep=0;
else
    mep=1-cep;
    end;

    if(cez >1)
   mez=0;
else
    mez=1-cez;
    end
%-------------------------------------%

    if (men<=0)
    men = 0;
    end
    
    if (mez<=0)
   mez = 0;
    end
    
    if (mep<=0)
    mep = 0;
    end 
%----------------------
sca=(men+mez+mep); 
nca11=CnN*men;
nca21=CnP*mep;
nca31=Cz*mez;
nnca= (nca11+nca21+nca31);
    if sca==0;
      y=0;
    else
      y=1*((nnca/sca)/sf);
    end;
end
 
Last edited by a moderator:

Have you tried HDL coder?
Or how about learning VHDL yourself and writing it yourself?

You havent said what the errors are, so we cant really help much.
 

Have you tried HDL coder?
Or how about learning VHDL yourself and writing it yourself?

You havent said what the errors are, so we cant really help much.

thanks all for your interest I had figure out the problem that is: "fuzzytest/Subsystem Warning : HDLCoder can not find a valid sample time for the model. All rates are 0 (so the result is Zero)."
 

Have you tried HDL coder?
Or how about learning VHDL yourself and writing it yourself?

You havent said what the errors are, so we cant really help much.

Dear Tricky
after using the HDL coder I had that warning "HDLCoder can not find a valid sample time for the model. All rates are 0" can you please check the code mentioned up and modify it in order to work appropriate?
 

This sounds like a setup issue. I wont be modifying the code for you as I really dont know matlab (or how easily it translates to HDL).
But I do know you need to set the timing of the model to discrete stepped rather than variable.

Also note that only a subset of matlab code is translatable to HDL. You're supposed to use simulink for HDL translation.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top