----------------------------------------------------------------------------------
-- 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;