VHDL时钟分频器每时钟周期在0和X之间翻转
在做了一点Verilog之后,我开始尝试学习VHDL 这是我创建时钟分频器的尝试: (主要取自)VHDL时钟分频器每时钟周期在0和X之间翻转,vhdl,clock,digital-design,Vhdl,Clock,Digital Design,在做了一点Verilog之后,我开始尝试学习VHDL 这是我创建时钟分频器的尝试: (主要取自) IEEE库; 使用IEEE.STD_LOGIC_1164.ALL; 使用IEEE.numeric_std.ALL; 实体时钟_192为 端口(时钟:在标准逻辑中; clr:标准逻辑中; 时钟输出:输出标准逻辑); 结束时钟μ192; 时钟_192的结构是 信号q:std_逻辑_向量(23向下至0); 开始 clk_out clk, clr=>clr, 时钟输出=>时钟输出 ); --时钟进程定义 c
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.numeric_std.ALL;
实体时钟_192为
端口(时钟:在标准逻辑中;
clr:标准逻辑中;
时钟输出:输出标准逻辑);
结束时钟μ192;
时钟_192的结构是
信号q:std_逻辑_向量(23向下至0);
开始
clk_out clk,
clr=>clr,
时钟输出=>时钟输出
);
--时钟进程定义
clk_流程:流程
开始
clk测试台驱动来自uut
实例和clk\U out
过程的clk\U out
信号,这使得std\U逻辑的解析功能生效
当两个源都驱动'0'
时,生成的clk_out
值将是'0'
,但如果一个源驱动'0'
而另一个源驱动'1'
,则解析函数将返回'X'
,如您所见
您可以查找“VHDL解析函数”的一些描述,或者尝试使用谷歌搜索。非常感谢。这解决了问题。这也是我第一次听说VHDL解析函数,我很欣赏这个链接;可以推荐“VHDL设计指南”。有几种方法可以简化时钟分频器过程:(1)使用上升沿(clk)
函数,而不是clk'event和clk='1'
(2)使用类型,而不是与它们对抗:使q
无符号,然后时钟线简化为q
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.ALL;
entity clock_192 is
Port ( clk : in STD_LOGIC;
clr : in STD_LOGIC;
clk_out : out STD_LOGIC);
end clock_192;
architecture Behavioral of clock_192 is
signal q : std_logic_vector (23 downto 0);
begin
clk_out <= q(23);
process(clk,clr)
begin
if clr = '1' then
q <= "000000000000000000000000";
elsif clk'event and clk = '1' then
q <= std_logic_vector(unsigned(q)+1);
end if;
end process;
end Behavioral;
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY test_clock_192 IS
END test_clock_192;
ARCHITECTURE behavior OF test_clock_192 IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT clock_192
PORT(
clk : IN std_logic;
clr : IN std_logic;
clk_out : OUT std_logic
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal clr : std_logic := '0';
--Outputs
signal clk_out : std_logic;
-- Clock period definitions
constant clk_period : time := 10 ns;
constant clk_out_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: clock_192 PORT MAP (
clk => clk,
clr => clr,
clk_out => clk_out
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
clk_out_process :process
begin
clk_out <= '0';
wait for clk_out_period/2;
clk_out <= '1';
wait for clk_out_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
clr <= '1';
wait for 97 ns;
clr <= '0';
wait for clk_period*10;
-- insert stimulus here
wait;
end process;
END;
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY test_clock_192 IS
END test_clock_192;
ARCHITECTURE behavior OF test_clock_192 IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT clock_192
PORT(
clk : IN std_logic;
clr : IN std_logic;
clk_out : OUT std_logic
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal clr : std_logic := '0';
--Outputs
signal clk_out : std_logic;
-- Clock period definitions
constant clk_period : time := 10 ns;
constant clk_out_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: clock_192 PORT MAP (
clk => clk,
clr => clr,
clk_out => clk_out
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
clr <= '1';
wait for 97 ns;
clr <= '0';
wait for clk_period*10;
-- insert stimulus here
wait;
end process;
END;