我可以重用在不同进程中分配值的信号吗?

时间:2015-10-28 12:07:14

标签: vhdl hardware

我创建了一个为信号分配值的过程,目的是在不同的过程中重用信号:

Signaling : process(button0, button1)
begin

  if (button1= '0') AND (button0 = '0') then  -- if both buttons are pressed
    BothButtons <= "00";
  elsif (button1 = '0') AND (button0 = '1') then  -- if button1 is pressed
    BothButtons <= "01";
  elsif (button1 = '1') AND (button0 = '0') then  -- if button0 is pressed
    BothButtons <= "10";
  elsif (button1 = '1') AND (button0 = '1') then -- if no button are pressed
    BothButtons <= "11";
  else
    --BothButtons <= "11";
    BothButtons <= button0 & button1;
  end if;

end process;

我正在重复使用此信号的另一个过程是:

Counting : process(button0, BothButtons) 

  variable count0 : integer range 0 to 9; -- to hold the counter value

begin 

  if falling_edge(Button0) then -- I am using button0 as a clock because the onboard clock is too fast  

    if BothButtons = "00" then
      count0 := 0;
    elsif BothButtons = "01" then
      count0 := count0 + 1;
    elsif BothButtons = "10" then
      count0 := count0 + 1;
    else
      count0 := count0 + 1; -- when i have included this i have discovered that the signal value is not visible within this process
  end if;

end process;

请忽略此if语句的内容我知道它没有意义,但我只是测试信号值是否在此过程中是可见的!

输出不符合预期,似乎第二个进程没有响应信号内的变化!

2 个答案:

答案 0 :(得分:2)

简短回答:是的。根据经验,只在一个过程中写入您的信号(这是信号&#39;驱动程序&#39;),并在任何其他过程中读取它。

它比这复杂一点,但你可以忽略开始时的复杂情况。你实际上是在一个有效的过程中写信给信号。 (例如,可以是并发分配,而不是进程),如果要处理分辨率函数,可以有多个驱动程序。

但是你的代码搞砸了。首先,你有重大的种族问题。这两个过程对相同的信号都很敏感,你不知道它们将执行什么命令。其次,你的第一个进程可以完全被一个简单的并发赋值(你的else分支中的那个)替换掉。你的第二个过程也太复杂了。

答案 1 :(得分:1)

您可以在一个进程中写入信号并在一个或多个其他进程中读取它。但是,您永远不会被允许从多个进程写入相同的信号,这不是这里的情况。