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.

function declaration error in VHDL

Status
Not open for further replies.

harerama

Member level 4
Joined
Sep 21, 2011
Messages
79
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Bangalore,India
Activity points
1,747
HI..in my program i declared below to perform rational division in VHDL .But i ran in GHDL simulatior gave an error "no function declarations for operator "/" " whats the problem in my code.


Code VHDL - [expand]
1
2
3
4
5
6
variable w,x : integer;
 variable num : real;
 begin
  w := numerator(a);
  x := denominator(a);
  num :=(a(numer))/(a(denom));

 
Last edited by a moderator:

You have to define the coresponding library at the top of your code:

library ieee ;
use ieee.math_real.all ;
 

Thanks shaiko.. Defined library at the top now also not working ,same error.I Attached my program for your refference.

Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
library ieee ;
use ieee.math_real.all ;
package ratpack_extras_rational_real is 
  constant numer : INTEGER := 0; -- numerator
  constant denom : INTEGER := 1; -- denominator
  type rational is array (natural range numer to denom) of 
  integer; -- range -16384 to 16383;
  constant RAT_ZERO : rational := (0, 1);
  constant RAT_ONE  : rational := (1, 1);
  function to_rational (a, b : integer) return rational;
  function int2rat (a : integer) return rational;
  function numerator (a : rational) return integer;
  function denominator (a : rational) return integer;
  function rational_to_real(a:rational)return real;
  end ratpack_extras_rational_real;
package body ratpack_extras_rational_real is
  function to_rational (a, b : integer) return rational is
  variable r : rational;
  begin
  r(numer) := a;
  r(denom) := b;
  return r;
  end to_rational;
  function int2rat (a : integer) return rational is
  variable r : rational;
  begin
  r(numer) := a;
  r(denom) := 1;
  return r;
  end int2rat;
  function numerator (a : rational) return integer is
  variable n : integer;
  begin
  n := a(numer);
  return n;
  end numerator;
  function denominator (a : rational) return integer is
  variable d : integer;
  begin
  d := a(denom);
  return d;
  end denominator;
 function rational_to_real(a:rational)return real is 
 variable w,x:integer;
 variable num :real;
 begin
 w:=a(numer);
 x:=a(denom);
num :=(w/x);
  return num;
end rational_to_real;
end ratpack_extras_rational_real;

 
Last edited by a moderator:

The operation integer / integer should be defined internally with the VHDL compiler. But it doesn't give the intended result, because it's truncated to integer. You need to perform a division of real numbers instead.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top