1

below is the code in C that is used to fuzzify an input. I have been trying to convert it to verilog syntax but i am having a lot of problem regarding the data types and such. The errors keep on piling.

float fuzzify_MF(float x,a,b,c,d) //x=crisp input 
{ 
float dom; 
if ( x >a && x <b) 
{ dom=(x-a)/(b – a); } 
else if (x>c && x<d) 
{ dom=(d-x)/(d-c); } 
else if (x>=b && x<=c) 
{dom=1.0; } 
else 
{ dom=0; } 
return dom; 
} 
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Adnan Khalid
  • 19
  • 1
  • 2

3 Answers3

1

why dont you try using PLI. Try this link : PLI tutorial

nav_jan
  • 2,473
  • 4
  • 24
  • 42
0

You can use PLI to solve this, but if you want to look cool and still solve it, use DPI of SystemVerilog.

http://www.project-veripage.com/dpi_tutorial_1.php

sm535
  • 587
  • 7
  • 20
0

You can import a "C" function in the Verilog, by using PLIs.

Include following header file with the C function:

#include <svdip.h>

Now in the Verilog module:

module top;
  import "DPI-C" context function shortreal fuzzify_MF(shortreal x, shortreal a, shortreal b, shortreal c, shortreal d);
  shortreal t;

  initial
  begin
    t = fuzzify_MF(<Arguments>);
  end    
endmodule

You can read more on this topic in the link : DPI Tutorial

Karan Shah
  • 1,912
  • 1
  • 29
  • 42