Velocity Reviews > VHDL > Seven Segment for decimal numbers

# Seven Segment for decimal numbers

Elnikety
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.

scottcarl
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

Elnikety
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