library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity RAM_controler is
port(
clk_50 : in std_logic;
clk_baud : in std_logic;
main_reset : in std_logic;
enable: in std_logic; --active high write enable
in_data : in std_logic_vector(7 downto 0);
W_order : out std_logic;
R_order : out std_logic;
Data_OUT : out std_logic_vector(7 downto 0);
Write_Address_OUT: out std_logic_vector(7 downto 0);
Read_Address_OUT: out std_logic_vector(7 downto 0)
);
end entity RAM_controler;
architecture Behavioral of RAM_controler is
type state is (reset,operation);
signal state_reg,next_state_reg : state;
signal write_address : std_logic_vector(W-1 downto 0):="00000000";
signal next_write_address : std_logic_vector(W-1 downto 0):="00000000";
begin
state_change : process(clk_50, main_reset)
begin
if (main_reset = '1') then
state_reg <= reset;
elsif (rising_edge(clk_50)) then
state_reg <= operation;
read_counter <= next_read_counter;
write_address<= next_write_address;
read_address <= next_read_address;
end if;
end process;
writecounter : process(clk_baud, main_reset,enable)
begin
if (main_reset='1') then
next_write_address <= "00000000";
Data_OUT <= "ZZZZZZZZ";
W_order <='0';
Write_Address_OUT <="ZZZZZZZZ";
elsif (rising_edge(clk_baud) and enable='1' ) then
W_order <='1';
Data_OUT <= in_data;
Write_Address_OUT <= write_address;
if (write_address = "11111111") then
next_write_address <= "00000000";
else
next_write_address <= write_address+1;
end if;
else
W_order <='0';
Write_Address_OUT <= "ZZZZZZZZ";
next_write_address <= write_address+1;
end if;
end process;
end Behavioral;
上面的代码描述了RAM控制器。
制作问题的部分是&#34; elsif(rising_edge(clk_baud)和enable =&#39; 1&#39;)然后&#34;。
错误:无法注册&#34; Write_Address_OUT&#34;在RAM_controler.vhd,因为它没有在时钟边缘之外保持其值
我不知道为什么这一点是错误的。
有人向我建议吗?
谢谢!
答案 0 :(得分:2)
如果您正在编写顺序逻辑,那么坚持使用模板是明智之举。下面是一个这样的顺序逻辑模板,带有异步复位,所有综合工具都应该理解:
process(clock, async_reset) -- nothing else should go in the sensitivity list
begin
-- never put anything here
if async_reset ='1' then -- or '0' for an active low reset
-- set/reset the flip-flops here
-- ie drive the signals to their initial values
elsif rising_edge(clock) then -- or falling_edge(clock)
-- put the synchronous stuff here
-- ie the stuff that happens on the rising or falling edge of the clock
end if;
-- never put anything here
end process;
所以 enable 不应该在敏感列表中,并且不应该在与异步复位相同的if语句中进行测试,并且测试时钟。
您收到此错误的原因:
错误:无法在“Write_Address_OUT”处注册 RAM_controler.vhd因为它没有超出时钟的值 边缘
是因为代码中的最后三个分配:
W_order <='0';
Write_Address_OUT <= "ZZZZZZZZ";
next_write_address <= write_address+1;
可以在时钟的下降沿发生,或者(因为你的灵敏度列表中也有启用),完全独立于任何时钟。逻辑合成器无法合成行为类似的逻辑。如果你坚持使用模板,你就不会遇到这种问题(这会让你更仔细地思考你期望合成器合成的逻辑)。
所以,我会将你的 writecounter 进程编码为:
writecounter : process(clk_baud, main_reset)
begin
if (main_reset='1') then
next_write_address <= "00000000";
Data_OUT <= "ZZZZZZZZ";
W_order <='0';
Write_Address_OUT <="ZZZZZZZZ";
elsif rising_edge(clk_baud) then
if enable='1' then
W_order <='1';
Data_OUT <= in_data;
Write_Address_OUT <= write_address;
if (write_address = "11111111") then
next_write_address <= "00000000";
else
next_write_address <= write_address+1;
end if;
else
W_order <='0';
Write_Address_OUT <= "ZZZZZZZZ";
next_write_address <= write_address+1;
end if;
end if;
end process;
尽管如此,我应该强调我的代码与你的代码不完全相同。我不知道你的设计意图,所以我只能猜出你的意图。如果您打算采取其他行为,那么您将不得不实施该行为。无论您的设计意图如何,关于坚持使用模板的建议都很重要。
答案 1 :(得分:0)
代码中的最终else
实际上应该是:
elsif (rising_edge(clk_baud) and enable='0' ) then