読者です 読者をやめる 読者になる 読者になる

7セグメント・デコーダ

7セグメントLEDのデコーダをモジュール化した。
iValue(4bit)に応じた値 (0-F) を出力する。

デコード値はconstantで設定している。 kDigitがデコード値を格納した2次元配列になっていて、
例えばkDigit(3)は7セグメントLEDで3を表示する値となる。

iValueの値をconv_integerでintegerに変換するだけ。

library IEEE;
    use IEEE.std_logic_1164.all;
    use IEEE.std_logic_misc.all;
    use IEEE.std_logic_arith.all;
    use IEEE.std_logic_unsigned.all;

entity Decoder7seg is
    port (
        CLOCK_50          : in    std_logic;
        RESET_N           : in    std_logic;     
        
        iEnable           : in    std_logic;
        iValue            : in    std_logic_vector( 3 downto 0);
        oEncValue         : out   std_logic_vector( 6 downto 0)
    );
end Decoder7seg;

architecture RTL of Decoder7seg is

    --  -- 0 --
    --  5     1
    --  -- 6 --
    --  4     2
    --  -- 3 --
    constant kDigit0 : std_logic_vector(6 downto 0) := "1000000";
    constant kDigit1 : std_logic_vector(6 downto 0) := "1111001";
    constant kDigit2 : std_logic_vector(6 downto 0) := "0100100";
    constant kDigit3 : std_logic_vector(6 downto 0) := "0110000";
    constant kDigit4 : std_logic_vector(6 downto 0) := "0011001";
    constant kDigit5 : std_logic_vector(6 downto 0) := "0010010";
    constant kDigit6 : std_logic_vector(6 downto 0) := "0000010";
    constant kDigit7 : std_logic_vector(6 downto 0) := "1111000";
    constant kDigit8 : std_logic_vector(6 downto 0) := "0000000";
    constant kDigit9 : std_logic_vector(6 downto 0) := "0010000";
    constant kDigitA : std_logic_vector(6 downto 0) := "0001000";
    constant kDigitB : std_logic_vector(6 downto 0) := "0000011";
    constant kDigitC : std_logic_vector(6 downto 0) := "1000110";
    constant kDigitD : std_logic_vector(6 downto 0) := "0100001";
    constant kDigitE : std_logic_vector(6 downto 0) := "0000110";
    constant kDigitF : std_logic_vector(6 downto 0) := "0001110";

    type tDigitSelect is array(0 to 15) of std_logic_vector(6 downto 0);

    constant kDigit : tDigitSelect := ( kDigit0, kDigit1, kDigit2, kDigit3,
                                        kDigit4, kDigit5, kDigit6, kDigit7,
                                        kDigit8, kDigit9, kDigitA, kDigitB,
                                        kDigitC, kDigitD, kDigitE, kDigitF
                                    );
    
    signal sEnable : std_logic;
    signal sValue  : std_logic_vector( 3 downto 0);
    
begin

    -- Retiming Input signal
    process (CLOCK_50, RESET_N) is
    begin
        if RESET_N = '0' then
            sEnable <= '0';
            sValue  <= (others => '0');
        elsif rising_edge(CLOCK_50) then
            sEnable <= iEnable;
            sValue  <= iValue;
        end if;
    end process;

    -- Encode data
    process (CLOCK_50, RESET_N) is
    begin
        if RESET_N = '0' then
            oEncValue <= (others => '1');
        elsif rising_edge(CLOCK_50) then
            if (sEnable = '0') then
                oEncValue <= (others => '1');
            else
                oEncValue <= kDigit(conv_integer(sValue));
            end if;
        end if;
    end process;

end RTL;