2014-04-10 61 views
0

我正在尝试使用VHDL设计一个交通灯控制器,我正在用Altera EPM240T100C5编程,并使用自定义扩展板来显示交通信号灯。最慢的时钟电路板上设置仍然较快,比我想,我需要写一个我一样这么一个时钟分频器:VHDL时钟分频器在板上工作但仿真失败

LIBRARY ieee; 
USE ieee.std_logic_1164.all; 

entity clockdivider is 
    port 
    (
     clkin : in std_logic; 
     dividedclk : out std_logic 
    ); 
end clockdivider; 

architecture divider of clockdivider is 

signal J : std_logic; 
signal K : std_logic; 


begin 
J <= '1'; 
K <= '1'; 


process(clkin) 
variable tempdividedclk : std_logic; 
begin 
if (rising_edge(clkin)) then 
    tempdividedclk := (NOT(tempdividedclk) AND J) OR (tempdividedclk AND (NOT(K))); 
end if; 
    dividedclk <= '0'; 
    dividedclk <= tempdividedclk; 
end process; 

END divider; 

这将运行在板上,但在模拟器(精细的ModelSim )“dividedclk”输出无法初始化任何东西。我想知道是否有人知道为什么?

回答

5

在模拟开始时,“tempdividedclk”被初始化为“单元化”。 当时钟边缘出现时,tempdividedclk将被分配给(not(U)and 1)或(U and 0),这是“未定义”。要正确模拟,tempdividedclk必须通过重置或仅在仿真级别进行初始化。它可以在硅片上找到,因为“U”状态可以是1或0.

+3

在此过程中,可以为tempdivideclk的变量声明提供默认值'0'或'1'。 'variable tempdividedclk:std_logic:='0';' – user1155120

相关问题