Problem With Signed Number in Vhdl

Discussion in 'VHDL' started by mohammadyou, Dec 25, 2010.

  1. mohammadyou

    mohammadyou

    Joined:
    Dec 25, 2010
    Messages:
    1
    hi
    i am newbie in vhdl
    when i want compare signed Number in vhdl
    i cant get true answer
    my code is :
    Code:
    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    use IEEE.NUMERIC_STD.signed;
    
    entity test_compare is
    end test_compare;
    
    architecture Behavioral_Fl of test_compare is
    type Bound_of_Function is Array (0 to 2) of signed (15 downto 0);
    constant Bound_Data : Bound_of_Function :=(x"FFF6",x"0000",x"000A");
    signal Net_Test : signed (15 downto 0);
    signal Output :   STD_LOGIC_VECTOR (15 downto 0);
    begin
    sim: process 
    begin
        Net_Test<= x"FFF5"; -- -11
      wait for 100ns;  
        Net_Test<= x"FFF6"; -- -10
      wait for 100ns;
        Net_Test<= x"0000";  -- 0
      wait for 100ns;
        Net_Test<= x"000B"; -- 10
      wait for 100ns;
    end process; 
    
    Fl:process(Net_Test)
        begin
         if (Net_Test < (Bound_Data(0))) then 
             Output <= (x"7FFF");
         elsif (Net_Test < (Bound_Data(1))) then 
             Output <= std_logic_vector(Bound_Data(1));
         elsif (Net_Test < (Bound_Data(2))) then
             Output <= std_logic_vector(Bound_Data(2)); 
         elsif (Net_Test >= (Bound_Data(2))) then  
             Output <= (x"8000"); 
         end if;
       end process;
    end Behavioral_Fl;
    
    when Net_Test=0x"FFF6" (-10 < 0 ) i expected Output =x"0000" but
    output =x"8000" !!
    output of my code is:

    images.elektroda.net/95_1293235188.jpg

    where is my problem? :-x
    thank you
     
    mohammadyou, Dec 25, 2010
    #1
    1. Advertising

  2. mohammadyou

    bmackin

    Joined:
    Jan 2, 2011
    Messages:
    1
    Location:
    Iowa
    Library is wrong

    If you use the library statements:

    use IEEE.STD_LOGIC_1164.ALL;
    use IEEE.std_logic_arith.all;
    -- use IEEE.NUMERIC_STD.signed;

    it works as you would expect it to.

    By the way, you have one other error/typo:

    Net_Test<= x"000B"; -- 10

    Hex B is 11, not 10.
     
    bmackin, Jan 2, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mostafa

    VHDL SIGNED datatype

    Mostafa, Jul 1, 2003, in forum: VHDL
    Replies:
    6
    Views:
    28,629
    hussain.elsaid
    Dec 1, 2008
  2. hari
    Replies:
    6
    Views:
    7,130
    hamilton
    May 2, 2004
  3. afd
    Replies:
    1
    Views:
    8,562
    Colin Paul Gloster
    Mar 23, 2007
  4. kyrpa83
    Replies:
    1
    Views:
    657
    kyrpa83
    Oct 17, 2007
  5. Rob1bureau
    Replies:
    1
    Views:
    840
    joris
    Feb 27, 2010
Loading...

Share This Page