Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vhdl 如何填写和显示矩阵?[硬件描述语言]_Vhdl_Xilinx - Fatal编程技术网

Vhdl 如何填写和显示矩阵?[硬件描述语言]

Vhdl 如何填写和显示矩阵?[硬件描述语言],vhdl,xilinx,Vhdl,Xilinx,我有一个数据输入作为标准逻辑向量,我想用数据输入的位填充一个矩阵,然后显示它 如何填写和显示矩阵 这是我的密码: signal datain : std_logic_vector(39 downto 0) := "1111011101100110011001010110011001100110"; for i1 in 1 to 5 loop for j1 in 1 to 8 loop for j2 in datain'range loop ma

我有一个数据输入作为标准逻辑向量,我想用数据输入的位填充一个矩阵,然后显示它

如何填写和显示矩阵

这是我的密码:

    signal datain : std_logic_vector(39 downto 0) := "1111011101100110011001010110011001100110";

     for i1 in 1 to 5 loop 
     for j1 in 1 to 8 loop
     for j2 in datain'range loop
     mat1(i1,j1)<=datain(j2);
      end loop;
      end loop; 
      end loop;

      ------- display the matrix

        for i2 in 1 to 5 loop 
         for i3 in 1 to 8 loop  
          for i4 in dataout'range loop       
           dataout(i4) <= mat1(i2,i3);
          end loop;
        end loop;
       end loop;    
信号数据输入:标准逻辑向量(39向下至0):=“1111011101100101011001001011011011011011011011011011011010”;
对于1到5环路中的i1
对于1至8回路中的j1
对于datain'范围循环中的j2
mat1(i1,j1)首先,我们从您的代码片段构造一个:

library ieee;
use ieee.std_logic_1164.all;

entity abir is
end entity;

architecture foo of abir is

    type mat_type is array (1 to 5, 1 to 8) of std_logic;
    signal mat1: mat_type;
    signal datain : std_logic_vector(39 downto 0) := 
                "1111011101100110011001010110011001100110";
    signal dataout: std_logic_vector (39 downto 0);  -- MISSING

    -- this function is predefined in VHDL -2008:
    function to_string (inp: std_logic_vector) return string is
        variable image_str: string (1 to inp'length);
        alias input_str:  std_logic_vector (1 to inp'length) is inp;
    begin
        for i in input_str'range loop
            image_str(i) := character'VALUE(std_ulogic'IMAGE(input_str(i)));
        end loop;
        return image_str;
    end function;
begin

INITIALIZE_MATRIX:
    process  -- (datain)
    begin
        for i1 in 1 to 5 loop 
            for j1 in 1 to 8 loop
                for j2 in datain'range loop
                    mat1(i1,j1)<=datain(j2);
                end loop;
            end loop; 
        end loop;
        wait;   -- Do only once, depends on the initial value of datain
    end process; -- the wait statement can be removed if you add sensitivity

   ------- display the matrix
MATRIX_T0_DATAOUT:
    process (mat1)
    begin
        for i2 in 1 to 5 loop
            for i3 in 1 to 8 loop
                for i4 in dataout'range loop
                    dataout(i4) <= mat1(i2,i3);
                end loop;
            end loop;
        end loop;
    end process;

DISPLAY_DATAOUT:
    process -- (dataout)
    begin               -- wait statements so only disply valid datout
        wait for 0 ns;  -- first delta cycle all 'U's (dataout uninitialized)
        wait for 0 ns;  -- second delta cycle all 'U's (mat1 uninitialized)
        report LF &
               HT & "datain  = " & to_string(datain) & LF & 
               HT & "dataout = " & to_string(dataout);
        wait on dataout;
    end process;
end architecture;
因此,嵌套循环有问题(您也可以使用波形查看器验证这一点,以确定mat1实际上都是“0”)

这是因为内部的循环。使用datain,将矩阵mat1(i,j)的每个元素赋值N次,其中N是datain的长度(范围为j2)。使用dataout,可以为dataout(i4)的每个索引元素分配mat(i2,i3)的每个矩阵元素

那么有可能让三个循环执行这些赋值吗

嗯,没有

在初始化矩阵过程中,mat1的每个(i,j)位置都被datain的所有索引值覆盖。只有最后一个生效了。这使矩阵中充满了所有“0”

在矩阵_到_数据输出过程中,所有数据输出索引都被“安排”为每个i3循环迭代的最后一个mat1(i2,i3)值,以i2和i3的最后一个循环迭代值为“0”为基础

我们可以修改这两组循环,将j2或i4作为变量直接递减(datain和dataout的范围按降序排列):

在这里我们可以找到dataout和datain匹配。(一件好事。)

所以问题是每个进程中的三个嵌套循环都不正确。我们希望分别管理指向输入和输出数组的指针

我们还管理变量j2或i4的赋值,以防止边界冲突,使用if语句防止变量赋值超出变量的值范围时j2或i4被递减。分配边界检查失败将中止模拟

请注意,信号分配会导致将值写入投影输出波形(队列)。在任何挂起的进程运行并挂起之前,不会发生信号更新。在投影输出波形中,任何时间只有一个值。(包括当前模拟时间)

这两个经过修改的过程可用作转换函数的基础:

architecture fum of abir is

    type mat_type is array (1 to 5, 1 to 8) of std_logic;
    signal mat1: mat_type;
    signal datain : std_logic_vector(39 downto 0) := 
                "1111011101100110011001010110011001100110";
    signal dataout: std_logic_vector (39 downto 0);  -- MISSING

    -- this function is predefined in VHDL -2008:
    function to_string (inp: std_logic_vector) return string is
        variable image_str: string (1 to inp'length);
        alias input_str:  std_logic_vector (1 to inp'length) is inp;
    begin
        for i in input_str'range loop
            image_str(i) := character'VALUE(std_ulogic'IMAGE(input_str(i)));
        end loop;
        return image_str;
    end function;

    function to_matrix (inp: std_logic_vector) return  mat_type is
        alias input: std_logic_vector(0 to inp'length - 1) is inp; -- ascending
        variable mat: mat_type;
        variable inptr: natural range 0 to inp'length;
    begin
        assert input'length = mat'length(1) * mat'length(2)
        report LF & 
            "to_matrix call, input length (" &
            integer'image(inp'length) & ") " &
            "/= " & integer'image( mat'length(1) * mat'length(2))
        severity FAILURE;
        for i in mat'range(1) loop      -- first dimension
            for j in mat'range(2) loop  -- second dimension
                mat(i,j) := input(inptr);
                inptr := inptr + 1;  -- inptr range allows last increment
            end loop;
        end loop;
        return mat;
    end function;

    function to_std_logic_vector (mat: mat_type) return std_logic_vector is
        variable retval: 
            std_logic_vector(0 to mat'length(1) * mat'length(2) - 1);
        variable outptr: natural range 0 to retval'length;
    begin
        for i in mat'range(1) loop      -- first dimension
            for j in mat'range(2) loop  -- second dimension
                retval(outptr) := mat(i,j);
                outptr := outptr + 1; -- outptr range allows last increment
            end loop;
        end loop;
        return retval;
    end function;
begin

INITIALIZE_MATRIX:
    mat1 <= to_matrix(datain);

MATRIX_T0_DATAOUT:
    dataout <= to_std_logic_vector(mat1);

DISPLAY_DATAOUT:
    process -- (dataout)
    begin               -- wait statements so only disply valid datout
        wait for 0 ns;  -- first delta cycle all 'U's (dataout uninitialized)
        wait for 0 ns;  -- second delta cycle all 'U's (mat1 uninitialized)
        report LF &
               HT & "datain  = " & to_string(datain) & LF & 
               HT & "dataout = " & to_string(dataout);
        wait for 1 ns;
        wait on dataout;
    end process;
end architecture;
abir的架构框架是 类型mat_类型是标准_逻辑的数组(1到5,1到8); 信号mat1:mat_型; 信号数据输入:标准逻辑向量(39向下至0):= "1111011101100110011001010110011001100110"; 信号数据输出:标准逻辑向量(39向下至0);--丢失的 --此函数在VHDL-2008中预定义: 函数到_字符串(inp:std_逻辑_向量)的返回字符串为 变量image_str:字符串(1到inp'长度); 别名输入\u str:std\u逻辑\u向量(1到inp'长度)是inp; 开始 对于输入_str'range循环中的i 图像(i):=字符值(标准逻辑)图像(输入(i)); 端环; 返回图像; 末端功能; 函数到矩阵(inp:std逻辑向量)的返回矩阵类型为 别名输入:标准逻辑向量(0到inp'长度-1)是inp;--提升 可变材料:材料类型; 变量inptr:自然范围0到inp'长度; 开始 断言输入长度=材料长度(1)*材料长度(2) 报告LF& “到矩阵调用,输入长度(”& 整数‘图像(inp’长度)&“& “/=”&整数图像(材质长度(1)*材质长度(2)) 严重故障; 对于mat'range(1)循环中的i——第一维 对于mat'range(2)循环中的j——第二维 mat(i,j):=输入(inptr); inptr:=inptr+1;——inptr范围允许最后一次增量 端环; 端环; 返回垫; 末端功能; 返回标准逻辑向量的函数(mat:mat类型) 变量返回: 标准逻辑向量(0到材料长度(1)*材料长度(2)-1); 可变输出:自然范围0到返回长度; 开始 对于mat'range(1)循环中的i——第一维 对于mat'range(2)循环中的j——第二维 retval(outptr):=mat(i,j); outptr:=outptr+1;--输出范围允许最后一次增量 端环; 端环; 返回返回; 末端功能; 开始 初始化矩阵: mat1首先,我们从您的代码片段构造一个:

library ieee;
use ieee.std_logic_1164.all;

entity abir is
end entity;

architecture foo of abir is

    type mat_type is array (1 to 5, 1 to 8) of std_logic;
    signal mat1: mat_type;
    signal datain : std_logic_vector(39 downto 0) := 
                "1111011101100110011001010110011001100110";
    signal dataout: std_logic_vector (39 downto 0);  -- MISSING

    -- this function is predefined in VHDL -2008:
    function to_string (inp: std_logic_vector) return string is
        variable image_str: string (1 to inp'length);
        alias input_str:  std_logic_vector (1 to inp'length) is inp;
    begin
        for i in input_str'range loop
            image_str(i) := character'VALUE(std_ulogic'IMAGE(input_str(i)));
        end loop;
        return image_str;
    end function;
begin

INITIALIZE_MATRIX:
    process  -- (datain)
    begin
        for i1 in 1 to 5 loop 
            for j1 in 1 to 8 loop
                for j2 in datain'range loop
                    mat1(i1,j1)<=datain(j2);
                end loop;
            end loop; 
        end loop;
        wait;   -- Do only once, depends on the initial value of datain
    end process; -- the wait statement can be removed if you add sensitivity

   ------- display the matrix
MATRIX_T0_DATAOUT:
    process (mat1)
    begin
        for i2 in 1 to 5 loop
            for i3 in 1 to 8 loop
                for i4 in dataout'range loop
                    dataout(i4) <= mat1(i2,i3);
                end loop;
            end loop;
        end loop;
    end process;

DISPLAY_DATAOUT:
    process -- (dataout)
    begin               -- wait statements so only disply valid datout
        wait for 0 ns;  -- first delta cycle all 'U's (dataout uninitialized)
        wait for 0 ns;  -- second delta cycle all 'U's (mat1 uninitialized)
        report LF &
               HT & "datain  = " & to_string(datain) & LF & 
               HT & "dataout = " & to_string(dataout);
        wait on dataout;
    end process;
end architecture;
因此,嵌套循环有问题(您也可以使用波形查看器验证这一点,以确定mat1实际上都是“0”)

这是因为内部的循环。使用datain,将矩阵mat1(i,j)的每个元素赋值N次,其中N是datain的长度(范围为j2)。使用dataout,可以为dataout(i4)的每个索引元素分配mat(i2,i3)的每个矩阵元素

那么有可能让三个循环执行这些赋值吗

嗯,没有

在初始化矩阵过程中,mat1的每个(i,j)位置都被datain的所有索引值覆盖。只有最后一个生效了。这使矩阵中充满了所有“0”

在矩阵_到_数据输出过程中,所有数据输出索引都被“安排”为每个i3循环迭代的最后一个mat1(i2,i3)值,以i2和i3的最后一个循环迭代值为“0”为基础

我们可以修改这两组循环,将j2或i4作为变量直接递减(datain和dataout的范围按降序排列):

在这里我们可以找到dataout和datain匹配。(一件好事。)

所以问题是每个进程中的三个嵌套循环都不正确。我们希望分别管理指向输入和输出数组的指针

我们还使用if语句管理变量j2或i4的赋值,以防止边界冲突
abir.vhdl:68:9:@0ms:(report note):
    datain  = 1111011101100110011001010110011001100110
    dataout = 1111011101100110011001010110011001100110
architecture fum of abir is

    type mat_type is array (1 to 5, 1 to 8) of std_logic;
    signal mat1: mat_type;
    signal datain : std_logic_vector(39 downto 0) := 
                "1111011101100110011001010110011001100110";
    signal dataout: std_logic_vector (39 downto 0);  -- MISSING

    -- this function is predefined in VHDL -2008:
    function to_string (inp: std_logic_vector) return string is
        variable image_str: string (1 to inp'length);
        alias input_str:  std_logic_vector (1 to inp'length) is inp;
    begin
        for i in input_str'range loop
            image_str(i) := character'VALUE(std_ulogic'IMAGE(input_str(i)));
        end loop;
        return image_str;
    end function;

    function to_matrix (inp: std_logic_vector) return  mat_type is
        alias input: std_logic_vector(0 to inp'length - 1) is inp; -- ascending
        variable mat: mat_type;
        variable inptr: natural range 0 to inp'length;
    begin
        assert input'length = mat'length(1) * mat'length(2)
        report LF & 
            "to_matrix call, input length (" &
            integer'image(inp'length) & ") " &
            "/= " & integer'image( mat'length(1) * mat'length(2))
        severity FAILURE;
        for i in mat'range(1) loop      -- first dimension
            for j in mat'range(2) loop  -- second dimension
                mat(i,j) := input(inptr);
                inptr := inptr + 1;  -- inptr range allows last increment
            end loop;
        end loop;
        return mat;
    end function;

    function to_std_logic_vector (mat: mat_type) return std_logic_vector is
        variable retval: 
            std_logic_vector(0 to mat'length(1) * mat'length(2) - 1);
        variable outptr: natural range 0 to retval'length;
    begin
        for i in mat'range(1) loop      -- first dimension
            for j in mat'range(2) loop  -- second dimension
                retval(outptr) := mat(i,j);
                outptr := outptr + 1; -- outptr range allows last increment
            end loop;
        end loop;
        return retval;
    end function;
begin

INITIALIZE_MATRIX:
    mat1 <= to_matrix(datain);

MATRIX_T0_DATAOUT:
    dataout <= to_std_logic_vector(mat1);

DISPLAY_DATAOUT:
    process -- (dataout)
    begin               -- wait statements so only disply valid datout
        wait for 0 ns;  -- first delta cycle all 'U's (dataout uninitialized)
        wait for 0 ns;  -- second delta cycle all 'U's (mat1 uninitialized)
        report LF &
               HT & "datain  = " & to_string(datain) & LF & 
               HT & "dataout = " & to_string(dataout);
        wait for 1 ns;
        wait on dataout;
    end process;
end architecture;