VHDL中unsigned的初值
Initial value of unsigned in VHDL
我正在使用 Altera Max plus II,用 VHDL 编写。
在架构中我得到了这个命令:
signal count_value : unsigned (3 downto 0);
我注意到count_value的初始值是0000。
我该如何改变它?
编辑:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all ;
entity decade_counter is
port ( clk : in std_logic;
q : out unsigned(3 downto 0) );
end entity decade_counter;
architecture rtl of decade_counter is
signal count_value : unsigned(3 downto 0);
begin
count : process (clk) is
begin
if rising_edge(clk) then
if count_value = 9 then
count_value <= "0000";
else
count_value <= count_value + 1;
end if;
end if;
end process count;
q <= count_value;
end architecture rtl;
我有这个代码,它是一个从 1 到 9 的 BCD 计数器。我想修改它,使它从 7 到 12。这就是我想要 count_value 在 0111 初始化的原因。
提前致谢
如果你想在构建时为它提供一些价值time.I建议你试试这个方法
signal count_value : unsigned (3 downto 0) := "xxxx";
此 "xxxx" 可以是您想要的任何 std_logic_Vector 值
希望对您有所帮助!
首先 - 不要使用 std_logic_arith
。它不是标准的一部分,并且经常会产生问题。请改用 numeric_std
。
其次 - 初始化。您可以通过两种方式进行:
信号声明时的初始值。这是可能的,但您必须检查您的设备是否支持它。如果您希望您的代码可移植,请使用第二种方法。
重置。最好是同步的,因为它通常是逻辑的一部分。
示例(尚未检查,但应该有效):
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all ;
entity decade_counter is
port (
clk : in std_logic;
reset_n: in std_logic;
q : out std_logic_vector(3 downto 0)
);
end entity decade_counter;
architecture rtl of decade_counter is
signal count_value : unsigned(3 downto 0);
-- Possibly:
-- signal count_value : unsigned(3 downto 0) := "0111";
begin
count : process (clk) is
begin
if rising_edge(clk) then
if resetn = '0' then
count_value <= "0111";
else
if count_value >= 12 then
count_value <= "0111";
else
count_value <= count_value + 1;
end if;
end if;
end if;
end process count;
q <= std_logic_vector(count_value);
end architecture rtl;
我正在使用 Altera Max plus II,用 VHDL 编写。
在架构中我得到了这个命令:
signal count_value : unsigned (3 downto 0);
我注意到count_value的初始值是0000。 我该如何改变它?
编辑:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all ;
entity decade_counter is
port ( clk : in std_logic;
q : out unsigned(3 downto 0) );
end entity decade_counter;
architecture rtl of decade_counter is
signal count_value : unsigned(3 downto 0);
begin
count : process (clk) is
begin
if rising_edge(clk) then
if count_value = 9 then
count_value <= "0000";
else
count_value <= count_value + 1;
end if;
end if;
end process count;
q <= count_value;
end architecture rtl;
我有这个代码,它是一个从 1 到 9 的 BCD 计数器。我想修改它,使它从 7 到 12。这就是我想要 count_value 在 0111 初始化的原因。
提前致谢
如果你想在构建时为它提供一些价值time.I建议你试试这个方法
signal count_value : unsigned (3 downto 0) := "xxxx";
此 "xxxx" 可以是您想要的任何 std_logic_Vector 值
希望对您有所帮助!
首先 - 不要使用 std_logic_arith
。它不是标准的一部分,并且经常会产生问题。请改用 numeric_std
。
其次 - 初始化。您可以通过两种方式进行:
信号声明时的初始值。这是可能的,但您必须检查您的设备是否支持它。如果您希望您的代码可移植,请使用第二种方法。
重置。最好是同步的,因为它通常是逻辑的一部分。
示例(尚未检查,但应该有效):
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all ;
entity decade_counter is
port (
clk : in std_logic;
reset_n: in std_logic;
q : out std_logic_vector(3 downto 0)
);
end entity decade_counter;
architecture rtl of decade_counter is
signal count_value : unsigned(3 downto 0);
-- Possibly:
-- signal count_value : unsigned(3 downto 0) := "0111";
begin
count : process (clk) is
begin
if rising_edge(clk) then
if resetn = '0' then
count_value <= "0111";
else
if count_value >= 12 then
count_value <= "0111";
else
count_value <= count_value + 1;
end if;
end if;
end if;
end process count;
q <= std_logic_vector(count_value);
end architecture rtl;