Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

HOW TO DISPLAY 8'b VALUE INTO TWO 7-SEG DISPLAY

Status
Not open for further replies.

koolslash

Junior Member level 3
Joined
May 24, 2009
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,467
I WANT TO SHOW THE INPUT(7 DOWNTO 0) TO 2-DIGITS OF 7-SEGMENT ON FPGA.
LIKE 8b'11111111 means 100%
8b'00001111 means 50%
8b'00000000 means 00%
now i want to display this 00,01,...10,11..... 50,...99 on two 7segments.
one thing more how will i calculate 11111111 is 100% and so on.


I hope my question is clear.

Added after 1 minutes:

VHDL CODE IS NEEDED
 

Well, the most straightforward 'solution' would be to use simple translation tables, like this (note that the 'translation' values here are not correctly filled in):

Code:
----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date:    09:29:54 07/04/2009 
-- Design Name: 
-- Module Name:    Test - Behavioral 
-- Project Name: 
-- Target Devices: 
-- Tool versions: 
-- Description: 
--
-- Dependencies: 
--
-- Revision: 
-- Revision 0.01 - File Created
-- Additional Comments: 
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity Test is
end Test;

architecture Behavioral of Test is

  signal Percentage  : std_logic_vector(7 downto 0);   -- Translated percentage (x"44" == 44%)
  signal Input       : std_logic_vector(7 downto 0);   -- Value to convert (255 == 100%)
  signal LeftDisplay : std_logic_vector(7 downto 0);   -- 7 segments data to display for left display
  signal RightDisplay: std_logic_vector(7 downto 0);   -- 7 segments data to display for right display

begin

  -- Most elementary translation table from Input (0..255) to percentage (0..99)
  with Input select 
    Percentage <= x"00" when (x"00"), x"01" when (x"01"), x"01" when (x"02"), x"01" when (x"03"),
                  x"02" when (x"04"), x"02" when (x"05"), x"02" when (x"06"), x"03" when (x"07"),
                  x"01" when (x"08"), x"01" when (x"09"), x"01" when (x"0A"), x"01" when (x"0B"),
                  x"01" when (x"0C"), x"01" when (x"0D"), x"01" when (x"0E"), x"01" when (x"0F"),
                  x"00" when (x"10"), x"01" when (x"11"), x"01" when (x"12"), x"01" when (x"13"),
                  x"01" when (x"14"), x"01" when (x"15"), x"01" when (x"16"), x"01" when (x"17"),
                  x"01" when (x"18"), x"01" when (x"19"), x"01" when (x"1A"), x"01" when (x"1B"),
                  x"01" when (x"1C"), x"01" when (x"1D"), x"01" when (x"1E"), x"01" when (x"1F"),
                  x"00" when (x"20"), x"01" when (x"21"), x"01" when (x"22"), x"01" when (x"23"),
                  x"01" when (x"24"), x"01" when (x"25"), x"01" when (x"26"), x"01" when (x"27"),
                  x"01" when (x"28"), x"01" when (x"29"), x"01" when (x"2A"), x"01" when (x"2B"),
                  x"01" when (x"2C"), x"01" when (x"2D"), x"01" when (x"2E"), x"01" when (x"2F"),
                  x"00" when (x"30"), x"01" when (x"31"), x"01" when (x"32"), x"01" when (x"33"),
                  x"01" when (x"34"), x"01" when (x"35"), x"01" when (x"36"), x"01" when (x"37"),
                  x"01" when (x"38"), x"01" when (x"39"), x"01" when (x"3A"), x"01" when (x"3B"),
                  x"01" when (x"3C"), x"01" when (x"3D"), x"01" when (x"3E"), x"01" when (x"3F"),
                  x"00" when (x"40"), x"01" when (x"41"), x"01" when (x"42"), x"01" when (x"43"),
                  x"01" when (x"44"), x"01" when (x"45"), x"01" when (x"46"), x"01" when (x"47"),
                  x"01" when (x"48"), x"01" when (x"49"), x"01" when (x"4A"), x"01" when (x"4B"),
                  x"01" when (x"4C"), x"01" when (x"4D"), x"01" when (x"4E"), x"01" when (x"4F"),
                  x"00" when (x"50"), x"01" when (x"51"), x"01" when (x"52"), x"01" when (x"53"),
                  x"01" when (x"54"), x"01" when (x"55"), x"01" when (x"56"), x"01" when (x"57"),
                  x"01" when (x"58"), x"01" when (x"59"), x"01" when (x"5A"), x"01" when (x"5B"),
                  x"01" when (x"5C"), x"01" when (x"5D"), x"01" when (x"5E"), x"01" when (x"5F"),
                  x"00" when (x"60"), x"01" when (x"61"), x"01" when (x"62"), x"01" when (x"63"),
                  x"01" when (x"64"), x"01" when (x"65"), x"01" when (x"66"), x"01" when (x"67"),
                  x"01" when (x"68"), x"01" when (x"69"), x"01" when (x"6A"), x"01" when (x"6B"),
                  x"01" when (x"6C"), x"01" when (x"6D"), x"01" when (x"6E"), x"01" when (x"6F"),
                  x"00" when (x"70"), x"01" when (x"71"), x"01" when (x"72"), x"01" when (x"73"),
                  x"01" when (x"74"), x"01" when (x"75"), x"01" when (x"76"), x"01" when (x"77"),
                  x"01" when (x"78"), x"01" when (x"79"), x"01" when (x"7A"), x"01" when (x"7B"),
                  x"01" when (x"7C"), x"01" when (x"7D"), x"01" when (x"7E"), x"01" when (x"7F"),
                  x"00" when (x"80"), x"01" when (x"81"), x"01" when (x"82"), x"01" when (x"83"),
                  x"01" when (x"84"), x"01" when (x"85"), x"01" when (x"86"), x"01" when (x"87"),
                  x"01" when (x"88"), x"01" when (x"89"), x"01" when (x"8A"), x"01" when (x"8B"),
                  x"01" when (x"8C"), x"01" when (x"8D"), x"01" when (x"8E"), x"01" when (x"8F"),
                  x"00" when (x"90"), x"01" when (x"91"), x"01" when (x"92"), x"01" when (x"93"),
                  x"01" when (x"94"), x"01" when (x"95"), x"01" when (x"96"), x"01" when (x"97"),
                  x"01" when (x"98"), x"01" when (x"99"), x"01" when (x"9A"), x"01" when (x"9B"),
                  x"01" when (x"9C"), x"01" when (x"9D"), x"01" when (x"9E"), x"01" when (x"9F"),
                  x"00" when (x"A0"), x"01" when (x"A1"), x"01" when (x"A2"), x"01" when (x"A3"),
                  x"01" when (x"A4"), x"01" when (x"A5"), x"01" when (x"A6"), x"01" when (x"A7"),
                  x"01" when (x"A8"), x"01" when (x"A9"), x"01" when (x"AA"), x"01" when (x"AB"),
                  x"01" when (x"AC"), x"01" when (x"AD"), x"01" when (x"AE"), x"01" when (x"AF"),
                  x"00" when (x"B0"), x"01" when (x"B1"), x"01" when (x"B2"), x"01" when (x"B3"),
                  x"01" when (x"B4"), x"01" when (x"B5"), x"01" when (x"B6"), x"01" when (x"B7"),
                  x"01" when (x"B8"), x"01" when (x"B9"), x"01" when (x"BA"), x"01" when (x"BB"),
                  x"01" when (x"BC"), x"01" when (x"BD"), x"01" when (x"BE"), x"01" when (x"BF"),
                  x"00" when (x"C0"), x"01" when (x"C1"), x"01" when (x"C2"), x"01" when (x"C3"),
                  x"01" when (x"C4"), x"01" when (x"C5"), x"01" when (x"C6"), x"01" when (x"C7"),
                  x"01" when (x"C8"), x"01" when (x"C9"), x"01" when (x"CA"), x"01" when (x"CB"),
                  x"01" when (x"CC"), x"01" when (x"CD"), x"01" when (x"CE"), x"01" when (x"CF"),
                  x"00" when (x"D0"), x"01" when (x"D1"), x"01" when (x"D2"), x"01" when (x"D3"),
                  x"01" when (x"D4"), x"01" when (x"D5"), x"01" when (x"D6"), x"01" when (x"D7"),
                  x"01" when (x"D8"), x"01" when (x"D9"), x"01" when (x"DA"), x"01" when (x"DB"),
                  x"01" when (x"DC"), x"01" when (x"DD"), x"01" when (x"DE"), x"01" when (x"DF"),
                  x"00" when (x"E0"), x"01" when (x"E1"), x"01" when (x"E2"), x"01" when (x"E3"),
                  x"01" when (x"E4"), x"01" when (x"E5"), x"01" when (x"E6"), x"01" when (x"E7"),
                  x"01" when (x"E8"), x"01" when (x"E9"), x"01" when (x"EA"), x"01" when (x"EB"),
                  x"01" when (x"EC"), x"01" when (x"ED"), x"01" when (x"EE"), x"01" when (x"EF"),
                  x"00" when (x"F0"), x"01" when (x"F1"), x"01" when (x"F2"), x"01" when (x"F3"),
                  x"01" when (x"F4"), x"01" when (x"F5"), x"01" when (x"F6"), x"01" when (x"F7"),
                  x"01" when (x"F8"), x"01" when (x"F9"), x"01" when (x"FA"), x"01" when (x"FB"),
                  x"01" when (x"FC"), x"01" when (x"FD"), x"01" when (x"FE"), x"01" when (x"FF"),
                  x"FF" when others;  -- not really necessary here ...

  with Percentage(7 downto 4) select
    LeftDisplay <= x"AA" when (x"0"),
                   x"BB" when (x"1"),
                   x"BB" when (x"2"),
                   x"BB" when (x"3"),
                   x"BB" when (x"4"),
                   x"BB" when (x"5"),
                   x"BB" when (x"6"),
                   x"BB" when (x"7"),
                   x"BB" when (x"8"),
                   x"BB" when (x"9"),
                   x"00" when others;

  with Percentage(3 downto 0) select
    RightDisplay <= x"AA" when (x"0"),
                    x"BB" when (x"1"),
                    x"BB" when (x"2"),
                    x"BB" when (x"3"),
                    x"BB" when (x"4"),
                    x"BB" when (x"5"),
                    x"BB" when (x"6"),
                    x"BB" when (x"7"),
                    x"BB" when (x"8"),
                    x"BB" when (x"9"),
                    x"00" when others;

end Behavioral;
 

Alternative 'look-up' tables can be achieved with ROM tables:



Code:
...
  type Table is array(0 to 255) of std_logic_vector(7 downto 0);
  constant PercentageTable: Table :=
    (x"01", x"01", x"02", x"02", ...
      ...........
     x"..", ............x"99");

  ....

begin
  Percentage <= PercentageTable(Input);
  ...
end Behaviour;
 

CAn u send me a little complete example code of the procedure....
then i may follow it and contruct what i want.

Actually i dont have any concept of what u ppl are talking.... i know somple VHDL:cry:
 

Here is a 'compilable' example of the table method


Code:
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
-- 
-- Create Date:    09:29:54 07/04/2009
-- Design Name:
-- Module Name:    Test - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
-- 
-- Dependencies:
-- 
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
-- 
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;


---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity Test is
end Test;

architecture Behavioral of Test is

  type Table is array(0 to 255) of std_logic_vector(7 downto 0);
  -- The next table should have the translated values for 0..255 -> 0.99
  -- The current values are -not- correct, except for the very first and last!
  constant PercentageTable: Table :=
    (x"00", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"02", x"03", x"03", x"03", x"04", x"04", x"04", x"04",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"02", x"03", x"03", x"03", x"04", x"04", x"04", x"04",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"02", x"03", x"03", x"03", x"04", x"04", x"04", x"04",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02",
     x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"02", x"01", x"01", x"02", x"99");

  signal Percentage  : std_logic_vector(7 downto 0);   -- Translated percentage (x"44" == 44%)
  signal Input       : std_logic_vector(7 downto 0);   -- Value to convert (255 == 100%)
  signal LeftDisplay : std_logic_vector(7 downto 0);   -- 7 segments data to display for left display
  signal RightDisplay: std_logic_vector(7 downto 0);   -- 7 segments data to display for right display

begin

  -- Get translation value from table
  Percentage <= PercentageTable(conv_integer(Input));

  -- Convert percentage value to display data
  -- Note that the actual data, like x"AA" is -not- correct. These should reflect
  -- the actual 7 segment data for the display (what to switch on and off)
  with Percentage(7 downto 4) select
    LeftDisplay <= x"AA" when (x"0"),
                   x"BB" when (x"1"),
                   x"BB" when (x"2"),
                   x"BB" when (x"3"),
                   x"BB" when (x"4"),
                   x"BB" when (x"5"),
                   x"BB" when (x"6"),
                   x"BB" when (x"7"),
                   x"BB" when (x"8"),
                   x"BB" when (x"9"),
                   x"00" when others;

  with Percentage(3 downto 0) select
    RightDisplay <= x"AA" when (x"0"),
                    x"BB" when (x"1"),
                    x"BB" when (x"2"),
                    x"BB" when (x"3"),
                    x"BB" when (x"4"),
                    x"BB" when (x"5"),
                    x"BB" when (x"6"),
                    x"BB" when (x"7"),
                    x"BB" when (x"8"),
                    x"BB" when (x"9"),
                    x"00" when others;

end Behavioral;
 

    koolslash

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top