0

amux という配列があり、配列A内に信号の整数倍を保存したいと考えています。以下の疑似コードはアイデアを提供します:

amux(0) <= "00001101";
amux(1) <= amux(0);

....

amux(n) <= amux(n-1); 

私の完全なコードは次のようになります。

-- n is 4 and m is 3, amux is an array, mzeros is 0's
regA: process(clk)
variable r : integer := 2**m;
begin
    if rising_edge(clk) then
        if ld_a = '1' then
            amux(0) <= std_logic_vector(to_unsigned((0),n*m+m));
            amux(1) <= mzeros & A;

            for i in 2 to r-1 loop 
              if (i mod 2) = 0 then
                   amux(i) <= amux(i/2)(n*m+m-2 downto 0) & '0';
                else
                  amux(i) <= std_logic_vector(unsigned(amux(i-1))+unsigned(amux(1)));
                end if;
            end loop;

        end if;
    end if;

プロセス regA を終了します。

私の現在の実装では、amux(0) を除いてすべて「00000000」が出力されます。私のアプローチの問題は何ですか?

4

1 に答える 1

0

私たちがあなたを正しく理解していれば、問題は、割り当てを行った直後のプロセスでシグナルの値を使用できないことです。割り当てられた値は、プロセスが終了した後にのみ使用できます。これが意図したものである場合は、その目的のために変数を使用できます。変数の値はすぐに更新されます。

以下のコード例は、あなたが望むものに近いはずです:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity array_loader is
    generic (
        N: integer := 4;
        M: integer := 3;
        DATA_WIDTH: integer := N * M + M;
        ARRAY_DEPTH: integer := 2**M
    );
    port (
        clk: in std_logic;
        ld_a: in std_logic;
        A: in unsigned(DATA_WIDTH-1 downto 0)
    );
end;

architecture rtl of array_loader is
    type amux_type is array (0 to ARRAY_DEPTH-1) of unsigned(DATA_WIDTH-1 downto 0);
    signal amux: amux_type;

begin
    regA: process(clk)
        variable multiple: unsigned(DATA_WIDTH-1 downto 0);
    begin
        if rising_edge(clk) then
            if ld_a then
                multiple := to_unsigned(0, multiple);
                amux(0) <= multiple;

                for i in 1 to amux'high loop
                    multiple := multiple + A;
                    amux(i) <= multiple;
                end loop;
            end if;
        end if;
    end process;
end;

上記のコードは VHDL-2008 のみ有効であることに注意してください。以前のバージョンでは、明示的に「1」と比較する必要があり、ジェネリック定数を使用して後続のジェネリックの値を計算するld_aことはできませんでした。NM

于 2013-10-25T15:55:27.223 に答える