VHDL:在常量中使用十六进制值
VHDL: Using hex values in constants
我是一个 VHDL 新手,试图创建一些常量并为它们分配十六进制数字,但是我总是出错。
我希望常量 FOO_CONST
等于 0x38
像这样...
constant FOO_CONST : integer := x"38";
错误:
Type integer does not match with a string literal
我尝试了几个变体都没有成功。
如果有任何帮助,我将不胜感激。谢谢!
-迈克
您可以使用格式 base#value#
:
指定整数的基数
constant FOO_CONST : integer := 16#38#;
一般来说,您可以在表达式中使用文字,如下所示:
数字文字可以用从 2
到 16
的任何基数表示。为清楚起见,它们也可以使用下划线分隔。
FOO_CONST_HEX <= 16#FF#;
FOO_CONST_BIN <= 2#1010_1010#;
FOO_CONST_BROKEN := 1_000_000.0; -- breaking the number using _
要清楚地回答问题,您可以按照Erasmus Cedernaes的建议进行操作:
constant FOO_CONST: integer:= 16#38#;
或
constant FOO_CONST : std_logic_vector := X"38"; -- if you will convert it to a std_logic_vector later
字符数组的文字,例如 string
、bit_vector
和 std_logic_vector
放在双引号中:
constant FLAG :bit_vector(0 to 7) := "11111111";
constant MSG : string := "Hello";
带小数点的数字文字是实数,那些没有的是整数;
constant FREEZE : integer := 32;
constant TEMP : real := 32.0;
实数可以用指数形式表示:
FACTOR := 2.2E-6;
时间类型(和其他物理类型)的文字必须有单位。单位前面应该有 space,虽然有些工具可能不需要这样:
constant DEL1 :time := 10 ns;
constant DEL2 :time := 2.27 us;
枚举类型的文字可以是字符(如 bit
和 std_logic
)或标识符:
type MY_LOGIC is ('X','0','1','Z');
type T_STATE is (IDLE, READ, END_CYC);
signal CLK : MY_LOGIC := '0';
signal STATE : T_STATE := IDLE;
位向量文字可以用二进制(默认)、八进制或十六进制表示。为了清楚起见,它们还可能包含嵌入的下划线。这些形式不能用作 std_logic_vector
文字:
BIT_8_BUS <= B"1111_1111";
BIT_9_BUS <= O"353";
BIT_16_BUS <= X"AA55";
注意:
Literals are supported for synthesis, providing they are of a type
acceptable to the logic synthesis tool. They are either synthesized as
connections to logic '1' or '0' or are used to help minimize the
number of gates required.
我是一个 VHDL 新手,试图创建一些常量并为它们分配十六进制数字,但是我总是出错。
我希望常量 FOO_CONST
等于 0x38
像这样...
constant FOO_CONST : integer := x"38";
错误:
Type integer does not match with a string literal
我尝试了几个变体都没有成功。
如果有任何帮助,我将不胜感激。谢谢!
-迈克
您可以使用格式 base#value#
:
constant FOO_CONST : integer := 16#38#;
一般来说,您可以在表达式中使用文字,如下所示:
数字文字可以用从 2
到 16
的任何基数表示。为清楚起见,它们也可以使用下划线分隔。
FOO_CONST_HEX <= 16#FF#;
FOO_CONST_BIN <= 2#1010_1010#;
FOO_CONST_BROKEN := 1_000_000.0; -- breaking the number using _
要清楚地回答问题,您可以按照Erasmus Cedernaes的建议进行操作:
constant FOO_CONST: integer:= 16#38#;
或
constant FOO_CONST : std_logic_vector := X"38"; -- if you will convert it to a std_logic_vector later
字符数组的文字,例如 string
、bit_vector
和 std_logic_vector
放在双引号中:
constant FLAG :bit_vector(0 to 7) := "11111111";
constant MSG : string := "Hello";
带小数点的数字文字是实数,那些没有的是整数;
constant FREEZE : integer := 32;
constant TEMP : real := 32.0;
实数可以用指数形式表示:
FACTOR := 2.2E-6;
时间类型(和其他物理类型)的文字必须有单位。单位前面应该有 space,虽然有些工具可能不需要这样:
constant DEL1 :time := 10 ns;
constant DEL2 :time := 2.27 us;
枚举类型的文字可以是字符(如 bit
和 std_logic
)或标识符:
type MY_LOGIC is ('X','0','1','Z');
type T_STATE is (IDLE, READ, END_CYC);
signal CLK : MY_LOGIC := '0';
signal STATE : T_STATE := IDLE;
位向量文字可以用二进制(默认)、八进制或十六进制表示。为了清楚起见,它们还可能包含嵌入的下划线。这些形式不能用作 std_logic_vector
文字:
BIT_8_BUS <= B"1111_1111";
BIT_9_BUS <= O"353";
BIT_16_BUS <= X"AA55";
注意:
Literals are supported for synthesis, providing they are of a type acceptable to the logic synthesis tool. They are either synthesized as connections to logic '1' or '0' or are used to help minimize the number of gates required.