Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Seven Segment for decimal numbers

Reply
Thread Tools

Seven Segment for decimal numbers

 
 
Elnikety Elnikety is offline
Junior Member
Join Date: May 2007
Posts: 3
 
      05-07-2007
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 .

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.
 
Reply With Quote
 
 
 
 
scottcarl scottcarl is offline
Member
Join Date: May 2007
Location: USA
Posts: 51
 
      05-07-2007
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
 
Reply With Quote
 
 
 
 
Elnikety Elnikety is offline
Junior Member
Join Date: May 2007
Posts: 3
 
      05-07-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simulating a seven-segment display Felipe Ribeiro C Programming 16 07-22-2009 08:41 PM
Re: Simulating a seven-segment display lovecreatesbeauty@gmail.c0m C Programming 2 07-05-2009 11:31 AM
Re: Simulating a seven-segment display luserXtrog C Programming 1 07-04-2009 10:50 PM
(8-bit binary to two digit bcd) or (8-bit binary to two digit seven segment) Fangs VHDL 3 10-26-2008 06:41 AM
Decimal to Packed Decimal Conversion in C++ Ven C++ 3 08-01-2006 03:56 PM



Advertisments