Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Help with simple function call

 
Thread Tools Search this Thread
Old 10-23-2006, 04:22 AM   #1
Default Help with simple function call


Hi, just started learning functions in VHDL.

Making a simple mux4 function. I cannot seem to figure out what type
of conditional statements are allowed in functions. Trying quite a few
as you can see, but all of them are giving errors.

Any suggestions?

Thanks.

RishiD

Here is the complete code.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity hw4_mux4 is
Port ( OpSel : in std_logic_vector(1 downto 0);
A : in std_logic_vector(7 downto 0);
B : in std_logic_vector(7 downto 0);
C : in std_logic_vector(7 downto 0);
D : in std_logic_vector(7 downto 0);
E : in std_logic_vector(7 downto 0);
F : in std_logic_vector(7 downto 0);
G : in std_logic_vector(7 downto 0);
H : in std_logic_vector(7 downto 0);
Z : out std_logic_vector(7 downto 0));
end hw4_mux4;

architecture behav of hw4_mux4 is
signal X : std_logic_vector(7 downto 0);
signal Y : std_logic_vector(7 downto 0);
function mux4 (fA, fB, fC, fD : std_logic_vector(7 downto 0); fOpSel :
std_logic_vector(1 downto 0))
return std_logic_vector is
variable result : std_logic_vector(7 downto 0);
begin


-- WITH fOpSel SELECT
-- result := fA WHEN "00",
-- fB WHEN "01",
-- fC WHEN "10",
-- fD WHEN "11",
-- NULL WHEN OTHERS;


result := fA when fOpSel = '00' ELSE
fB when fOpSel = '01' ELSE
fC when fOpSel = '10' ELSE
fD;



-- process (OpSel, A, B, C, D)
-- begin
-- case OpSel is
-- when "00" => result := A;
-- when "01" => result := B;
-- when "10" => result := C;
-- when "11" => result := D;
-- end case;
-- end process;

return result;

end mux4;

begin
X <= mux4(A, B, C, D, OpSel);
Y <= mux4(E, F, G, H, OpSel);
Z <= X - Y;
end behav;



Rishi Dhupar
  Reply With Quote
Old 10-23-2006, 02:11 PM   #2
KJ
 
Posts: n/a
Default Re: Help with simple function call

Rishi Dhupar wrote:
> Hi, just started learning functions in VHDL.
>
> Making a simple mux4 function. I cannot seem to figure out what type
> of conditional statements are allowed in functions. Trying quite a few
> as you can see, but all of them are giving errors.
>
> Any suggestions?


This should get you started.

function mux4 (fA, fB, fC, fD : std_logic_vector; fOpSel :
std_logic_vector(1 downto 0)) return std_logic_vector is
variable result : std_logic_vector(7 downto 0);
begin
case fOpSel is
when "00" => result := fA;
when "01" => result := fB;
when "10" => result := fC;
when others => result := fD;
end case;
return(result);
end function mux4;
KJ



KJ
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Call Manager 6 CDR CSV file level_3rd General Help Related Topics 0 06-12-2008 09:16 AM
Cisco Call Manager 6 CSV Format level_3rd General Help Related Topics 0 06-12-2008 09:14 AM
TRADING FEMALE CELEB INTERVIEWS ON DVD stu DVD Video 1 05-26-2008 09:39 AM
How to assign a returns value of a javascript function to a hiddenfield in a webpart Chander Software 0 12-20-2007 09:14 AM
How to call C# function in javascript visj4u Software 2 04-23-2007 03:24 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

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