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.

Using functions with many iterations (Package)

Status
Not open for further replies.

Anissa85

Newbie level 1
Joined
Dec 28, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,297
I want to program a function but it contains many iteration, i do it like this:

LIBRARY ieee ;
USE ieee.numeric_std.all ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_arith.all ;
-----------------------------------
package pack_A is
Constant N: integer := 7;
function Substraction ( rin: STD_LOGIC; A: STD_LOGIC_VECTOR (N downto 0); B: STD_LOGIC_VECTOR (N downto 0)) return STD_LOGIC_VECTOR;
end package;
----------------------------------------------
package body pack_A is
function Substraction ( rin: STD_LOGIC; A: STD_LOGIC_VECTOR (N downto 0); B: STD_LOGIC_VECTOR (N downto 0)) return STD_LOGIC_VECTOR is

variable r: STD_LOGIC_VECTOR (N+1 downto 0):=(others => '0');
variable s: STD_LOGIC_VECTOR (N+1 downto 0):=(others => '0');
variable i: integer :=2;
begin
r(0) := rin;
s(0) := a(0) xor b(0) xor r(0);
r(1) := ((not a(0)) and (b(0) or r(0))) or (b(0) and r(0));
if ( i > 0) then
s(i) := a(i) xor b(i) xor r(i);
r(i+1) := ((not a(i)) and (b(i) or r(i))) or (b(i) and r(i));
i := i+1;
if (i=N+1) then
s(N+1) := r(N+1);
end if;
end if;

return s;
end Substraction;

--------------------------------------------------------------
end pack_A;


But it given't any result, however when i did it in process (component) it give result.
Please i need help, THANKS.
 

whats the problem? functions have to vbe called in processes.
 
The line after begin is also wrong, you're trying to put a 9 bit vector into one bit(r(0).
Furthermore, what is the point of this function?
 

There are other errors:
You should not mix numeric_std and std_logic_arith in the same file. You should only use numeric_std
There is no loop in the function (that I think you intended to have there) so only bits 0,1 and 2 will get set (once you've fixed the problem 153rd pointed out).
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top