我正在尝试将一些 Verilog 代码转换为 UART 模块的较快时钟产生较慢时钟的代码。原始的 verilog 代码基于 fpga4fun.com 上的模块,这是我尝试将其转换为基于 VHDL 的设计。
entity baud_generator is
generic(
f_clk : integer := 50000000; -- default: 50 MHz
baud : integer := 115200; -- default: 115,200 baud
accum_width : integer := 16;
accum_inc : integer := (baud sll accum_width) / f_clk
);
port(
clock : in std_logic;
reset_n : in std_logic;
enable : in std_logic;
baud_clock : out std_logic
);
end entity baud_generator;
但是,我的编译器 Aldec-HDL 不喜欢以下行:
accum_inc : natural := (baud sll accum_width) / f_clk
这是确切的错误消息:
# Error: COMP96_0300: baud_generator.vhd : (20, 52): Cannot reference "f_clk" until the interface list is complete.
# Error: COMP96_0300: baud_generator.vhd : (20, 28): Cannot reference "baud" until the interface list is complete.
# Error: COMP96_0071: baud_generator.vhd : (20, 28): Operator "sll" is not defined for such operands.
# Error: COMP96_0104: baud_generator.vhd : (20, 27): Undefined type of expression.
# Error: COMP96_0077: baud_generator.vhd : (20, 27): Assignment target incompatible with right side. Expected type 'INTEGER'.
在verilog中,我有这样的东西:
module baud_generator(
input clock,
input reset_n,
input enable,
output baud_clock
);
parameter f_clock = 50000000;
parameter baud = 115200;
parameter accum_width = 16;
parameter accum_inc = (baud << accum_width) / f_clock;
//...
endmodule
我需要在该行中修改什么以使编译器满意?是否可以像这样使用链接在一起的泛型?
最佳答案
这基本上表示您不能使用泛型值进行计算来计算其他泛型的(默认值)。
只需使用 accum_inc
作为常量,而不是泛型。
此外,SLL(逻辑左移)运算符用于位模式(unsigned
和 signed
数据类型在 ieee.numeric_std
和 ieee.numeric_bit
包中),不适用于整数。您可以通过乘以 2 的幂来做同样的事情。
关于syntax - 如何使用依赖于实体的其他泛型参数的泛型参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6104933/