Syntax 用于D触发器VHDL的1Hz时钟
我正在尝试用VHDL为D触发器实现1hz时钟 下面是我的代码:Syntax 用于D触发器VHDL的1Hz时钟,syntax,compiler-errors,vhdl,Syntax,Compiler Errors,Vhdl,我正在尝试用VHDL为D触发器实现1hz时钟 下面是我的代码: entity d_flip_flop is Port ( clk : in STD_LOGIC; D : in STD_LOGIC; Q : out STD_LOGIC); end d_flip_flop; architecture Behavioral of d_flip_flop is signal clk_div: std_logic; --divided clock
entity d_flip_flop is
Port ( clk : in STD_LOGIC;
D : in STD_LOGIC;
Q : out STD_LOGIC);
end d_flip_flop;
architecture Behavioral of d_flip_flop is
signal clk_div: std_logic; --divided clock
begin
--process to divide clock
clk_divider: process(clk) --clk is the clock port
variable clk_count: std_logic_vector(25 downto 0) := (others => '0');
begin
if clk'event and clk = '1' then
clk_count <= clk_count+1;
clk_div <= clk_count(25);
end if;
end process;
--main process
main:process(clk_div)
begin
if clk'event and clk = '1' then
Q <= D;
end if;
end process;
end Behavioral;
实体d_触发器是
端口(时钟:在标准逻辑中;
D:在标准逻辑中;
Q:输出标准(U逻辑);
结束d_触发器;
d_触发器的结构是
信号时钟分区:标准逻辑--分频钟
开始
--时钟除法
clk_分配器:进程(clk)——clk是时钟端口
变量时钟计数:标准逻辑向量(25到0):=(其他=>'0');
开始
如果clk'事件和clk='1',则
clk_计数过程中clk_分割器修改以下行:
clk_count <= clk_count +1;
这是因为clk\U count被定义为“标准逻辑向量”类型的变量 clk_计数被用来表示一个数字,而不是一包比特
因此,请使用类型系统,而不是与之对抗,并将其声明为数字或至少某些数字类型
出于这个目的,最好的工具是numeric_std.unsigned,因为您需要从中提取一个位
因此添加使用ieee.numeric\u std.all代码>在库ieee之后代码>子句,将其声明为
variable clk_count: unsigned(25 downto 0) := (others => '0');
你已经完成了。不管怎样,布莱恩有最好的答案,就是二的幂。可以说,对于其他环绕值,您还应该为时钟计数使用整数
,并将其环绕:
signal clk_div : std_logic := '0';
clk_divider: process(clk) --clk is the clock port
subtype t_clk_count: integer range 0 to 12345678; -- for example
variable clk_count: t_clk_count := 0;
begin
if clk'event and clk = '1' then
if clk_count+1 >= t_clk_count'high then
clk_div <= not clk_div;
clk_count <= 0;
else
clk_count <= clk_count+1;
end if;
end if;
end process;
信号时钟div:std_逻辑:='0';
clk_分配器:进程(clk)——clk是时钟端口
子类型t_clk_count:整数范围0到12345678;--例如
变量clk_计数:t_clk_计数:=0;
开始
如果clk'事件和clk='1',则
如果时钟计数+1>=时钟计数高,则
clk#U div这可能是谷歌搜索准确错误消息的第四次成功(#1和#3指标准逻辑)。他还需要在“库ieee”之后添加“使用ieee.numeric#U标准全部”;这是一个快速破解(或Verilog用户)的补丁,我的首选也是整数(所以我说“声明为数字或…”),即使你必须显式地编码换行行为。但是对于这个需要2次幂溢出的应用程序,我选择了更简单的答案+1.多走一英里。
signal clk_div : std_logic := '0';
clk_divider: process(clk) --clk is the clock port
subtype t_clk_count: integer range 0 to 12345678; -- for example
variable clk_count: t_clk_count := 0;
begin
if clk'event and clk = '1' then
if clk_count+1 >= t_clk_count'high then
clk_div <= not clk_div;
clk_count <= 0;
else
clk_count <= clk_count+1;
end if;
end if;
end process;