0

我是 VHDL 编程的新手,这是我的第一个项目 - 构建一个具有常规/反向计数顺序功能的二进制计数器。我的计划很简单:

  1. 编写一个分频器过程以获取所需的时钟频率并将这个新时钟作为位信号输出flag
  2. 将“标志”放入另一个进程的敏感度列表中,根据常规/反向状态对其进行计数 - 存储curr_s在我的代码中。
  3. 第三个进程接收输入ctl信号作为敏感信号,然后切换curr_s并重置count- 的值,该值设置为存储我最后一个进程的计数。

然而,现在的问题是,Quartus II 向我返回了错误消息:

错误 (10028):无法在 bi_counter.vhd(35) 处解析网络“count[31]”的多个常量驱动程序

错误 (10029):bi_counter.vhd(46) 处的常量驱动程序

错误 (10028):无法在 bi_counter.vhd(35) 处解析网络“count[30]”的多个常量驱动程序

...

错误 (10028):无法在 bi_counter.vhd(35) 处解析网络“count[14]”的多个常量驱动程序

我用谷歌搜索了一下,有一些规则,比如不允许signal在多个进程中更改 a 的值,但问题是我将 my 声明count为共享变量而不是信号 - 这不应该遇到这样的错误。我打算这样做是因为我想count用作在进程之间交换信息的变量 - 这是否有意义,如果没有,是否有任何解决方法?

这是我的代码:

--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.numeric_std.all;
--
entity bi_counter is
    port(
        master_clk, ctl, rst: in std_logic;
                           q: out std_logic_vector(7 downto 0)
        );
end bi_counter;
--
architecture behv of bi_counter is
    shared variable curr_s: std_logic := '0'; -- 0 for incremental, 1 for reverse counting
    shared variable count: integer := -1;
    shared variable master_count: natural := 0;
    signal flag: std_logic;
begin
    p_freq_div: process(master_clk, rst)
    begin
        if rst = '0' then
            master_count := 0;
        elsif master_clk'event and master_clk='1' then
            master_count := master_count + 1;
            if master_count = 24000000 then
                flag <= not flag;
                master_count := 0;
            end if;
        end if;
    end process p_freq_div;
    
    p_count: process(flag)
    begin
        if curr_s = '1' then
            count := count + 1;
            q <= conv_std_logic_vector(count, 8);
        else
            count := count - 1;
            q <= conv_std_logic_vector(count, 8);
        end if;
    end process p_count;
    
    p_switch: process(ctl)
    begin
        if ctl'event and ctl='1' then
            curr_s := not curr_s;
            if curr_s = '0' then
                count := 0;
            else
                count := 1000;
            end if;
        end if;
    end process p_switch;
end behv;
4

1 回答 1

3

你写了:

我用谷歌搜索了一下,有一些规则,比如不允许在多个进程中更改信号的值,但问题是我将我的计数声明为共享变量而不是信号 - 这不应该遇到这样的错误。

这个“规则”不仅仅是为了让你的生活更加困难。

想想你想做什么。您正在尝试合成一些东西以放置在您的设备上,该值将保留一个值,您试图从两个独立的进程中分配该值(即使它们可能相关并且知道它们应该如何工作,它们仍然是独立的)。无论你使用什么语言元素——信号、变量等等——一旦你接触到只有物理电路的设备,它就变得无关紧要了。也就是说,你可能没有违反任何语言规则,但你违反了物理规则。

您的输出可以用以下形式表示:如果某些条件,则输出某些内容,否则,如果某些其他条件,则输出其他内容等。这可以放入单个进程中,这就是我建议您做的事情。

此外,正如 Russell 所建议的那样,您可能不应该使用共享变量,尤其是像您那样绕过语言规则。

于 2014-12-08T18:52:42.443 回答