VHDL如何将输入向量值分配给整数信号
VHDL how to assign a input vector value to an integer signal
我是 VHDL 的新手,我正在尝试制作一个计数器,它从输入接收值并计数到给定值,然后输出 1;
例如输入是4位向量“1011”
我尝试设置一个整数信号a = input = 1011 = 11 in decimal,然后如果b = a = 11输出1,否则输出0和b = b + 1
我知道我可以通过一系列 if 语句来完成,但我想知道是否有更好的方法,比如将值直接从输入向量分配给整数信号?感谢任何可以提供帮助的人!
这是未经测试的,但它是您所追求的一般架构。在 VHDL 中使用 if
语句并不是坏习惯;它们是定义顺序(而非组合)逻辑所必需的;你只需要明智地使用它们。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity Counter is port (
enable: in std_logic; -- Used to increment the counter. (Active high.)
value: in std_logic_vector(0 to 3);
clk: in std_logic; -- Used to clock the counter.
reset: in std_logic; -- Reset the counter. (Active high.)
output: out std_logic -- Generates a logic high once the count has been reached.
);
end Counter;
architecture Behavioral of Counter is
signal count: unsigned(0 to 3);
begin
process(clk,reset)
begin
-- If reset goes high, reset the count.
if reset='1' then
count <= "0000"; -- Reset the counter.
output <= '0'; -- Set the output low.
elsif(clk'event and clk='1') then -- If not reset, and the rising edge of the input clock...
if enable='1' then -- If the counter is enabled...
if count=unsigned(value) then -- If the count reached the input value...
output <= '1'; -- Set the output high.
else
count <= count + 1; -- Increment the counter.
end if;
end if;
end if;
end process;
end Behavioral;
我是 VHDL 的新手,我正在尝试制作一个计数器,它从输入接收值并计数到给定值,然后输出 1;
例如输入是4位向量“1011”
我尝试设置一个整数信号a = input = 1011 = 11 in decimal,然后如果b = a = 11输出1,否则输出0和b = b + 1
我知道我可以通过一系列 if 语句来完成,但我想知道是否有更好的方法,比如将值直接从输入向量分配给整数信号?感谢任何可以提供帮助的人!
这是未经测试的,但它是您所追求的一般架构。在 VHDL 中使用 if
语句并不是坏习惯;它们是定义顺序(而非组合)逻辑所必需的;你只需要明智地使用它们。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity Counter is port (
enable: in std_logic; -- Used to increment the counter. (Active high.)
value: in std_logic_vector(0 to 3);
clk: in std_logic; -- Used to clock the counter.
reset: in std_logic; -- Reset the counter. (Active high.)
output: out std_logic -- Generates a logic high once the count has been reached.
);
end Counter;
architecture Behavioral of Counter is
signal count: unsigned(0 to 3);
begin
process(clk,reset)
begin
-- If reset goes high, reset the count.
if reset='1' then
count <= "0000"; -- Reset the counter.
output <= '0'; -- Set the output low.
elsif(clk'event and clk='1') then -- If not reset, and the rising edge of the input clock...
if enable='1' then -- If the counter is enabled...
if count=unsigned(value) then -- If the count reached the input value...
output <= '1'; -- Set the output high.
else
count <= count + 1; -- Increment the counter.
end if;
end if;
end if;
end process;
end Behavioral;