【发布时间】:2011-06-07 07:12:31
【问题描述】:
主要编辑:
在阅读了 Will Dean 的评论后,问题得到了解决。原来的问题在修改后的代码下面:
-- REVISED CODE (NOW WORKS)
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
entity CLOCK_DIVIDER is
port(
reset : in std_logic;
clk : in std_logic;
half_clk : out std_logic
);
end CLOCK_DIVIDER;
architecture CLOCK_DIVIDER of CLOCK_DIVIDER is
signal tick : std_logic;
begin
process(clk, reset)
begin
if reset = '1' then
tick <= '0';
elsif clk = '1' and clk'EVENT then
if tick = '0' then
tick <= '1';
elsif tick = '1' then
tick <= '0';
end if;
end if;
end process;
process(tick)
begin
half_clk <= tick;
end process
end CLOCK_DIVIDER;
修改后的代码的综合逻辑块是一个异步复位DFF,它以half_clk为输出,反相half_clk为输入,这意味着half_clk的值在clk的每个上升沿发生变化。
谢谢,威尔迪恩 :)
==== ==== ==== ==== ====
原始问题如下:
==== ==== ==== ==== ====
我需要一个简单的时钟分频器(只需除以二),我想我会尝试自己编写一个以继续训练,而不是使用模板。
不幸的是,合成的逻辑块似乎不起作用 - 我按顺序呈现逻辑块和代码(我真的认为应该起作用)。
logic block http://img808.imageshack.us/img808/3333/unledly.png
我真正想知道的是,“tick”DFF 到底是怎么回事——它显然是从 mux-selector 获取输入的……是的。
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
entity CLOCK_DIVIDER is
port(
reset : in std_logic;
clk : in std_logic;
half_clk : out std_logic
);
end CLOCK_DIVIDER;
architecture CLOCK_DIVIDER of CLOCK_DIVIDER is
signal tick : std_logic;
begin
process(clk, reset)
begin
if reset = '1' then
half_clk <= '0';
tick <= '0';
elsif clk = '1' and clk'EVENT then
if tick = '0' then
half_clk <= '0';
tick <= '1';
elsif tick = '1' then
half_clk <= '1';
tick <= '0';
end if;
end if;
end process;
end CLOCK_DIVIDER;
我确信代码中的错误很明显,但我一直在盯着自己瞎找。
【问题讨论】:
-
我是 Verilog 人而不是 VHDL,但我不明白为什么需要两个寄存器来除以二。除了 'tick' 的(延迟)反转之外,'half_clock' 是什么?
-
我不需要两个寄存器,也不知道为什么会推断出两个寄存器。 half_clck 是逻辑块的输出,而 tick 是内部信号 - 如果我让 tick 输出,它无法读取它,如果我让 half_clk 成为内部信号,我无法输出它。但是:它现在可以工作了——记住你所说的,我从 if 语句中删除了 half_clk 并创建了一个单独的进程,它始终将 tick 的值分配给 half_clk ,现在它可以工作了。
标签: vhdl intel-fpga