Domanda

Voglio creare un indirizzo Decoder che è abbastanza flessibile per me di utilizzare quando si cambia il numero di bit del selettore e dei segnali di uscita decodificati.

Quindi, invece di avere una statica (ingresso fisso / formato di output) Decoder che sembra qualcosa di simile:

entity Address_Decoder is
Generic
(
    C_INPUT_SIZE: integer := 2
);
Port
(
    input   : in  STD_LOGIC_VECTOR (C_INPUT_SIZE-1 downto 0);
    output  : out STD_LOGIC_VECTOR ((2**C_INPUT_SIZE)-1 downto 0);
    clk : in  STD_LOGIC;
    rst : in  STD_LOGIC
);
end Address_Decoder;

architecture Behavioral of Address_Decoder is

begin        
        process(clk)
            begin
               if rising_edge(clk) then 
                  if (rst = '1') then
                     output <= "0000";
                  else
                     case <input> is
                        when "00" => <output> <= "0001";
                        when "01" => <output> <= "0010";
                        when "10" => <output> <= "0100";
                        when "11" => <output> <= "1000";
                        when others => <output> <= "0000";
                     end case;
                  end if;
               end if;
            end process;

end Behavioral;

avere qualcosa che è più flessibile / generale, che assomiglia a questo:

    entity Address_Decoder is
    Generic
    (
        C_INPUT_SIZE: integer := 2
    );
    Port
    (
        input   : in  STD_LOGIC_VECTOR (C_INPUT_SIZE-1 downto 0);
        output  : out STD_LOGIC_VECTOR ((2**C_INPUT_SIZE)-1 downto 0);
        clk : in  STD_LOGIC;
        rst : in  STD_LOGIC
    );
    end Address_Decoder;

    architecture Behavioral of Address_Decoder is

    begin        

DECODE_PROC:
    process (clk)
    begin

        if(rising_edge(clk)) then
         if ( rst = '1') then
           output <= conv_std_logic_vector(0, output'length);
         else
           case (input) is
             for i in 0 to (2**C_INPUT_SIZE)-1 generate
             begin
                when (i = conv_integer(input)) => output <= conv_std_logic_vector((i*2), output'length);        
             end generate;
            when others => output <= conv_std_logic_vector(0, output'length);
           end case;
         end if;
        end if;
    end process;

    end Behavioral;

So che questo codice non è valido e che il "quando" casi di test deve essere costanti e che non è possibile utilizzare il per-generare tra l'affermazione caso come questo, ma mostra che cosa è che io sono dopo :. un sufficiente un'entità intelligente per crescere alle mie esigenze

Ho cercato di trovare una soluzione elegante per questo problema senza molto successo, quindi, io sono aperto a qualsiasi suggerimento.

Grazie in anticipo, Erick

È stato utile?

Soluzione

A quanto pare si vuole l'ingresso sia l'indice del bit di uscita che dovrebbe essere insieme.

Scrivi così. Qualcosa di simile (tipi da numeric_std assumendo):

output <= (others => '0'); -- default
output(to_integer(input)) <= '1';

Altri suggerimenti

Ho sempre trovato questo tipo di cose più facili da seguire quando si è solo un ciclo su ogni bit, in modo da qualcosa come:

     if ( rst = '1') then
       output <= (others=>'0');
     else
       for i in 0 to (2**C_INPUT_SIZE)-1 generate
       begin
         if (i = conv_integer(input)) then
           output(i) <= '1';
         else
           output(i) <= '0';
         end if;
       end generate;
     end if;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top