提问人:dannyph 提问时间:10/16/2023 更新时间:10/16/2023 访问量:84
VHDL 8 位无符号计数器溢出检测
VHDL 8-bit unsigned counter overflow detection
问:
我正在尝试创建一个 8 位无符号计数器,该计数器的计数步长取决于 3 位控制输入。问题是 RST、控制、加法、减法和下溢可以正常工作,但溢出根本不起作用。在测试台上,当我得到溢出时,溢出值本身似乎并没有像它应该的那样从“0”变为“1”,但它只是从头开始计数。
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity Counter is
Port ( Clk : in STD_LOGIC;
RST : in STD_LOGIC;
Control : in STD_LOGIC_VECTOR (2 downto 0);
Count : out STD_LOGIC_VECTOR (7 downto 0);
Overflow : out STD_LOGIC;
Underflow : out STD_LOGIC;
Valid : out STD_LOGIC);
end Counter;
architecture Behavioral of Counter is
signal tmpCount : UNSIGNED(7 downto 0) := (others => '0');
signal tmpOverflow : STD_LOGIC := '0';
signal tmpUnderflow : STD_LOGIC := '0';
signal tmpValid : STD_LOGIC := '1';
begin
process
begin
wait until Clk'EVENT and Clk = '1';
if tmpOverflow='1' or tmpUnderflow='1' or RST='1' then
if RST='1' then
tmpCount<=(others=>'0');
tmpOverflow<='0';
tmpUnderflow<='0';
tmpValid<='1';
end if;
else
if Control="000" then
tmpCount<= tmpCount - 5;
elsif Control="001" then
tmpCount<=tmpCount - 2;
elsif Control="011" then
tmpCount<=tmpCount + 1;
elsif Control="100" then
tmpCount<=tmpCount + 2;
elsif Control="101" then
tmpCount<=tmpCount + 5;
elsif Control="110" then
tmpCount<=tmpCount + 6;
elsif Control="111" then
tmpCount<=tmpCount + 29;
end if;
if tmpCount > 255 then
tmpOverflow <= '1';
elsif tmpCount < 0 then
tmpUnderflow <= '1';
end if;
end if;
if tmpUnderflow='1' or tmpOverflow='1' then
tmpValid<='0';
tmpCount<= (others =>'U');
end if;
end process;
Count<=std_logic_vector(tmpCount);
Overflow<=tmpOverflow;
Underflow<=tmpUnderflow;
Valid<=tmpValid;
end Behavioral;
答: 暂无答案
上一个:隐式类型升级规则
下一个:无符号 int 文本外部边界
评论
else
if
tmpCount
unsigned
elsif tmpCount < 0 then
if tmpCount > 255 then