为什么在VHDL for-loop不工作? [英] Why in VHDL for-loop is not working?

查看:137
本文介绍了为什么在VHDL for-loop不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在ModelSim中模拟一个for循环,但是它不能正常工作。我知道它不能合成,但我不知道为什么它不能正确模拟。

模拟时,不会显示任何错误。但最终的结果是00000001(即只增加一次),而不是00000011的预期输出。

  library ieee; 
使用ieee.std_logic_1164.all;
使用IEEE.STD_LOGIC_unsigned.ALL;

实体forloop是
端口(enable:在std_logic;
data_out:out std_logic_vector(7 downto 0));
结束forloop;

forloop的架构行为是

signal temp:std_logic_vector(7 downto 0):=00000000;

begin

process(enable)
begin

for i in 0 to 3 loop
temp <= temp +1;
结束循环;
结束进程;
data_out< = temp;
结束行为;


解决方案

模拟输出是正确的。 VHDL中的for循环扩展为并行赋值,而不是C(顺序赋值)中的赋值。这意味着

 我在0到3循环中
temp <= temp +1;
结束循环;

会变成

  temp <= temp +1; 
temp <= temp +1;
temp <= temp +1;
temp <= temp +1;请注意,temp是一个信号,将在下一个周期更新,因此+1被分配所有4行代码的相同临时值。除此之外,您不要在灵敏度列表中使用启用信号。你确定要使用异步进程吗?


I tried simulating a for loop in ModelSim, but it is not working properly. I know it cannot synthesized, but I don't know why it is not simulating properly.

When simulated, it is not showing any error. But final result is "00000001" (ie incremented only once) instead of the expected output of "00000011".

library ieee;
use ieee.std_logic_1164.all;
use IEEE.STD_LOGIC_unsigned.ALL;

entity forloop is 
port(   enable      : in std_logic;         
     data_out       : out std_logic_vector(7 downto 0)); 
end forloop;

architecture behaviour of forloop is

signal temp     : std_logic_vector(7 downto 0) := "00000000";

begin

process(enable)         
begin   

    for i in 0 to 3 loop            
        temp <= temp +1;
    end loop;
end process;        
data_out <= temp;       
end behaviour;

解决方案

The simulation output is correct. The for loop in VHDL expands to parallel assignments and not what you get in C (sequential assignments). This means that

for i in 0 to 3 loop            
    temp <= temp +1;
end loop;

will become

    temp <= temp +1;
    temp <= temp +1;
    temp <= temp +1;
    temp <= temp +1;

Note that temp is a signal and will be updated in the next cycle, hence the +1 is assigned to the same temp value for all 4 lines of code. Besides that, you don't use the enable signal in the sensitivity list. And are you sure you want to use an asynchronous process?

这篇关于为什么在VHDL for-loop不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆