我是 VHDL 编程的新手,这是我的第一个项目 - 构建一个具有常规/反向计数顺序功能的二进制计数器。我的计划很简单:
- 编写一个分频器过程以获取所需的时钟频率并将这个新时钟作为位信号输出
flag。 - 将“标志”放入另一个进程的敏感度列表中,根据常规/反向状态对其进行计数 - 存储
curr_s在我的代码中。 - 第三个进程接收输入
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;