how to convert c function to verilog module?

Status
Not open for further replies.

adnan_88

Newbie level 1
Joined
May 26, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,286
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. Any guidance would be appreciated.Thanks

Code:
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; 
}
 

Hi adnan

your code cannot be converted *directly* to usable Verilog. However, you can do one of the following:

- convert the data types from float to your definition of a fixed-point datatype. Then, you can compare these directly
- if float is mandatory, you have to perform "approximate" comparisons within an "epsilon" range

Best regards,
the_penetrator
 
Last edited by a moderator:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…