Seven Segment for decimal numbers

Discussion in 'VHDL' started by Elnikety, May 7, 2007.

  1. Elnikety

    Elnikety

    Joined:
    May 7, 2007
    Messages:
    3
    Hi;
    i'm new with vhdl.
    well, i'm facing a problem which i believe that it's very easy, but it's really getting on my nerves :motz: .

    To display a value of a STD_LOGIC_VECTOR(7 downto 0); lets say the value
    valueBus <= "0010 1101" // Thats 2D
    VALUE <= conv_integer(ValueBus); // it will hold 45
    what i need is!
    VEC0 <= "0101" // 5
    VEC1 <= "0100" // 4

    SO, HOW CAN I DO SUCH THING?
    I tried arithmetic operations.
    {
    4 = 45/10 ; ---> this makes an error also 4 = 45 * (.1)
    5 = 45 - 4 * 10 ;
    }

    But the division always makes an error. I need a way to do such thing, or just a way to convert a vector into a decimal vector.
     
    Elnikety, May 7, 2007
    #1
    1. Advertising

  2. Elnikety

    scottcarl

    Joined:
    May 4, 2007
    Messages:
    49
    Location:
    USA
    hex --> decimal conversion

    Elnikety,

    This is not a trivial endevour when working with real hardware. Here is how it's done. You must compare the input value and translate it into a decimal value.

    Code:
    LIBRARY std, ieee;
    USE ieee.std_logic_1164.ALL;
    USE ieee.std_logic_unsigned.all;  -- note unsigned here
    
    -ENTITY and ARCHITECTURE not shown
    signal valbus      : std_logic_vector(7 downto 0);
    signal upper_bus : std_logic_vector(3 downto 0);
    signal lower_bus : std_logic_vector(7 downto 0);
    signal Output     : std_logic_vector(7 downto 0);
     
    Selectorama: process(clk, reset)
      begin
        if (reset = '1') then
          upper_bus       <= (others => '0');
          lower_bus       <= (others => '0'); 
        elsif rising_edge(clk) then
          if (valbus > X"63") then -- > decimal 99 (overflow condition)
            upper_bus       <= (others => '1);  -- assign to whatever you want
            lower_bus       <= (others => '1'); 
          elsif (valbus > X"59") then -- > decimal 89
            upper_bus       <= X"9";
            lower_bus       <= valbus - X"5A";  -- value-90=remainder
         elsif (valbus > X"4F") then -- > decimal 79
            upper_bus       <= X"8";
            lower_bus       <= valbus - X"50";   -- value-80=remainder
         elsif (valbus > X"45") then -- > decimal 69
             upper_bus       <= X"7";
            lower_bus       <= valbus - X"46";   -- value-70=remainder
         elsif (valbus > X"3B") then -- > decimal 59 
            upper_bus       <= X"6";
            lower_bus       <= valbus - X"3C";    -- value-60=remainder
    .
    .
    .
    .
        else
            upper_bus       <= X"0";
            lower_bus       <= valbus;    -- <10 gets the whole bus
      end if;
    end process;
    
    Output <= upper_bus & lower_bus(3 downto 0);
    Regards,
    Scottcarl
     
    scottcarl, May 7, 2007
    #2
    1. Advertising

  3. Elnikety

    Elnikety

    Joined:
    May 7, 2007
    Messages:
    3
    scottcarl ;
    u know?! i just thought that there might be a clever way to convert from hex to decimal. But u gave me the lesson --> IT'S HARDWARE <--.

    Thanks alot for ur time and ur effort, ur reply has been of a great assistance. I really appreciate it.

    Thanks again,
    Elnikety
     
    Elnikety, May 7, 2007
    #3
    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. Fangs
    Replies:
    3
    Views:
    9,863
    darshana
    Oct 26, 2008
  2. Leo Wong

    Seven Java Screensavers

    Leo Wong, Mar 1, 2006, in forum: Java
    Replies:
    13
    Views:
    3,442
    andrewthommo@gmail.com
    Mar 16, 2006
  3. Felipe Ribeiro

    Simulating a seven-segment display

    Felipe Ribeiro, Jul 1, 2009, in forum: C Programming
    Replies:
    16
    Views:
    1,057
    Squeamizh
    Jul 22, 2009
  4. lovecreatesbeauty@gmail.c0m

    Re: Simulating a seven-segment display

    lovecreatesbeauty@gmail.c0m, Jul 2, 2009, in forum: C Programming
    Replies:
    2
    Views:
    992
    Richard Bos
    Jul 5, 2009
  5. luserXtrog

    Re: Simulating a seven-segment display

    luserXtrog, Jul 3, 2009, in forum: C Programming
    Replies:
    1
    Views:
    364
    luserXtrog
    Jul 4, 2009
Loading...

Share This Page