这是一个按顺序1-2-3-4-6-7计算的VHDL代码,但似乎计入1-7 代码似乎在某处有逻辑错误。请帮忙
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity newtest is
port(C, CLR : in std_logic;
Q : out std_logic_vector(2 downto 0));
end newtest;
architecture archi of newtest is
signal tmp: std_logic_vector(2 downto 0);
begin
process (C, CLR)
begin
if (CLR='1') then
tmp <= "000";
elsif (C'event and C='1') then
if (tmp="100") then
tmp <= tmp + 1;
end if;
tmp <= tmp + 1;
end if;
end process;
Q <= tmp;
end archi;
答案 0 :(得分:1)
在对tmp没有时间间隔的两个连续信号分配的过程中,将发生后面的分配。信号具有当前值和未来值。直到当前模拟周期之后才更新信号分配。您已经更新了未来值,然后在下一个模拟周期中使用时钟C&#39;事件和C =&#39; 1&#39;将其分配给当前值。
以下使用numeric_std包而不是Synopsys std_logic_unsigned包而不更改tmp的类型,因此转换为unsigned的类型转换。我根本不想转移我的ieee库以包含非标准兼容的东西。您可以使用std_logic_unsigned并删除类型转换。
您同样可以将信号tmp声明为无符号(2 downto 0)并在分配给Q时键入转换它(Q&lt; = std_logic_vector(tmp);)或者如果可能的话使Q和tmp都无符号。
library ieee;
use ieee.std_logic_1164.all;
--use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity newtest is
port(C, CLR : in std_logic;
Q : out std_logic_vector(2 downto 0));
end newtest;
architecture archi of newtest is
signal tmp: std_logic_vector(2 downto 0);
begin
process (C, CLR)
begin
if (CLR='1') then
tmp <= "000";
elsif (C'event and C='1') then
if (tmp="100") then
tmp <= std_logic_vector (unsigned (tmp) + 2);
else
tmp <= std_logic_vector (unsigned (tmp) + 1);
end if;
end if;
end process;
Q <= tmp;
end archi;
现在只有一个tmp的赋值,它应该来自&#34; 100&#34;到&#34; 110&#34;。有人必须指出tmp可以是无符号而不是std_logic_vector,或者tmp可以是整数而不是其中任何一个。
就合成硬件增加2而言,需要为tmp输入的最右边两位增加一个术语输入