Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/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
Loops 循环的VHDL总是给我相同的值_Loops_For Loop_Vhdl_Clock_Rom - Fatal编程技术网

Loops 循环的VHDL总是给我相同的值

Loops 循环的VHDL总是给我相同的值,loops,for-loop,vhdl,clock,rom,Loops,For Loop,Vhdl,Clock,Rom,我想做的是添加元素0+11,然后添加1+10,然后添加2+9,然后添加所有其他元素,但当我进行模拟时,只需要第一个元素(0,11)。我还认为在一个时钟事件中取值是个好主意,但我不确定 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.std_logic_unsigned.all; entity Sumador is Port ( clk : in STD_LOGIC; en : in STD_LOGIC; --actCont : in

我想做的是添加元素
0+11
,然后添加
1+10
,然后添加
2+9
,然后添加所有其他元素,但当我进行模拟时,只需要第一个元素(0,11)。我还认为在一个时钟事件中取值是个好主意,但我不确定

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;

entity Sumador is
Port ( clk : in  STD_LOGIC;
en : in  STD_LOGIC;
--actCont : in  STD_LOGIC;
data : out  STD_LOGIC_VECTOR (6 downto 0);
A,B: inout STD_LOGIC_VECTOR (6 downto 0);
C: inout STD_LOGIC_VECTOR (6 downto 0)
);
end Sumador;

architecture Behavioral of Sumador is
signal addr: STD_LOGIC_VECTOR(3 downto 0);
--signal A,B,C: STD_LOGIC_VECTOR(6 downto 0);
type arrayRom is array (0 to 11) of std_logic_vector(6 downto 0);

constant memRom: arrayRom:=(
"1111111",--0
"1001111",--1
"0010010",--2
"0000110",--3
"1001100",--4
"0100000",--5
"0001111",--6
"0000000",--7
"0001100",--8
"0000001",--9
"0001000",--10
"0100001"
);

begin                   
process(clk)
begin  
if(RISING_EDGE(clk))then
if(en='1')then
for i in 0 to 11 loop
A<=memRom(i); --here i get the value from the i position of the constant     memory
B<=memRom(11-i);
C<=A+B;
end loop;
data<=C;
else
--A<="0000000";
--B<="0000000";
--C<=A+B;
--data<=C;
data<="0000000";
end if; 
end if; 
end process;
end Behavioral;`enter code here`
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用ieee.std_logic_unsigned.all;
苏马多是一个实体
端口(时钟:在标准逻辑中;
en:标准逻辑;
--actCont:标准逻辑中;
数据:输出标准逻辑向量(6到0);
A、 B:输入标准逻辑向量(6到0);
C:inout标准逻辑向量(6到0)
);
苏马多终点;
苏门答腊岛的建筑是
信号地址:标准逻辑向量(3到0);
--信号A、B、C:STD_逻辑_向量(6到0);
arrayRom类型是标准逻辑向量(6到0)的数组(0到11);
常数memRom:arrayRom:=(
"1111111",--0
"1001111",--1
"0010010",--2
"0000110",--3
"1001100",--4
"0100000",--5
"0001111",--6
"0000000",--7
"0001100",--8
"0000001",--9
"0001000",--10
"0100001"
);
开始
过程(clk)
开始
如果(上升沿(clk)),则
如果(en='1'),则
对于0到11循环中的i

A您的设计意图并不完全清楚,但我想说您这里有两个问题。一个是VHDL问题;一个是一般的编程问题

i) VHDL问题:此代码永远不会按照(我认为)您的意愿执行:

for i in 0 to 11 loop
A<=memRom(i); --here i get the value from the i position of the constant     memory
B<=memRom(11-i);
C<=A+B;
end loop;
data<=C;
应使用VHDL
信号
在进程之间进行通信

VHDL
变量
应用作进程内的工作内存

然而


ii)编程问题:正如我所说,我不知道您的设计意图,但此代码总是只添加元素0和11,而不添加任何其他内容,因为
C
在每个循环中都会被覆盖。

我还借此机会缩进您的代码并删除不必要的括号。我认为这个问题没有那么糟糕。它展示了一个我经常在不理解信号分配语义的年轻工程师身上看到的编码错误。马修·泰勒(Matthew Taylor)给出了一个很好的答案,在一个循环中解释了作业,覆盖了先前的答案。
for i in 0 to 11 loop
A<=memRom(i); --here i get the value from the i position of the constant     memory
B<=memRom(11-i);
C<=A+B;
end loop;
data<=C;
process(clk)
  variable A,B,C : STD_LOGIC_VECTOR (6 downto 0);
begin  
  if RISING_EDGE(clk) then
    if en='1' then
      for i in 0 to 11 loop
        A := memRom(i); --here i get the value from the i position of the constant     memory
        B := memRom(11-i);
        C := A+B;
      end loop;
      data<=C;