如何在 moduleEN 中设置一个值 - VHDL
How to set a value at moduleEN - VHDL
我有这个代码:
library IEEE;
use IEEE.std_logic_1164.all;
entity Controller is
port (
CLK : in std_logic;
OutENABLE : out std_logic_vector (2 downto 0);
ModuleRESET : in std_logic;
ModuleENABLE : in std_logic
);
end Controller;
architecture Controller_archi of Controller is
signal Counter : integer range 0 to 4200 := 0;
begin
process (CLK, ModuleRESET)
begin
if ModuleRESET = '0' then
OutENABLE <= (others => '0');
Counter <= 0;
elsif rising_edge(CLK) then
if ModuleENABLE = '1' then
Counter <= Counter + 1;
case Counter is
when 0 =>
OutENABLE <= "001";
when 450 =>
OutENABLE <= "010";
when 900 =>
OutENABLE <= "100";
when 1350 =>
OutENABLE <= "001";
Counter <= 0;
when others =>
end case;
else
OutENABLE <= "000";
end if;
end if;
end process;
end Controller_archi;
但它并没有像我需要的那样工作。
我需要的:
- 当
ModuleENABLE
立即变为“1”时 OutENABLE
变为“001”,而不是一开始 rising_edge(CLK)
(现在,在这段代码中,如果 ModuleENABLE 变为 ' 1' OutENABLE 不会从“000”变为“001”,它在第一个 rising_edge(CLK)) 后变为“001”
- 计数器在
rising_edge(CLK)
和 OutENABLE
时增加,它会在每个 CLK
事件中更新。 (现在,在这段代码中,计数器在 rising_edge(CLK) 时上升,但 OutENABLE 它在 rising_edge(CLK) 时更新,而不是在 CLK 上升和下降时更新)
所以我修改了代码来做到这一点:
library IEEE;
use IEEE.std_logic_1164.all;
entity Controller is
port (
CLK : in std_logic;
OutENABLE : out std_logic_vector (2 downto 0);
ModuleRESET : in std_logic;
ModuleENABLE : in std_logic
);
end Controller;
architecture Controller_archi of Controller is
signal Counter : integer range 0 to 4200 := 0;
begin
process (CLK, ModuleENABLE, ModuleRESET)
begin
if ModuleRESET = '0' then
OutENABLE <= (others => '0');
Counter <= 0;
elsif ModuleENABLE = '1' then
if rising_edge(CLK) then
Counter <= Counter + 1;
end if;
case Counter is
when 0 =>
OutENABLE <= "001";
when 450 =>
OutENABLE <= "010";
when 900 =>
OutENABLE <= "100";
when 1350 =>
OutENABLE <= "001";
Counter <= 0;
when others =>
end case;
else
Counter <= 0;
OutENABLE <= "000";
end if;
end process;
end Controller_archi;
现在代码可以像我在 ModelSim 中需要的那样工作,但是当我综合它或编译它并再次模拟时它不起作用。
我的问题是:
第二个代码有什么问题,我该如何解决?
如果我无法修复第二个代码,我该如何修改第一个代码以按我的需要工作?
What it's wrong with second code and how I can fix it?
您的综合工具对时钟线和复位线的连接方式很挑剔。您必须使用如下结构:
if ModuleRESET = '0' then
...
elsif rising_edge(CLK) then
或者综合工具无法识别时钟线和复位线。
If I can't fix second code how I can modify first code to work like I need?
您需要将 "OutENABLE" 移出第一个进程,并移动到它自己的进程中。从你所说的来看,OutENABLE 不应该是一个寄存器——它应该是 Counter、ModuleRESET 和 ModuleENABLE 的组合函数。试试这个。
process (CLK, ModuleRESET)
begin
if ModuleRESET = '0' then
Counter <= 0;
elsif rising_edge(CLK) then
if ModuleENABLE = '1' then
Counter <= Counter + 1;
case Counter is
when 1350 =>
Counter <= 0;
when others =>
null;
end case;
end if;
end if;
end process;
process (Counter, ModuleRESET, ModuleEnable)
begin
OutENABLE <= "000";
if ModuleRESET = '1' and ModuleENABLE = '1' then
case Counter is
when 0 .. 449 =>
OutENABLE <= "001";
when 450 .. 899 =>
OutENABLE <= "010";
when 900 .. 1349 =>
OutENABLE <= "100";
when others =>
OutENABLE <= "001";
end case;
end if;
end process;
我有这个代码:
library IEEE;
use IEEE.std_logic_1164.all;
entity Controller is
port (
CLK : in std_logic;
OutENABLE : out std_logic_vector (2 downto 0);
ModuleRESET : in std_logic;
ModuleENABLE : in std_logic
);
end Controller;
architecture Controller_archi of Controller is
signal Counter : integer range 0 to 4200 := 0;
begin
process (CLK, ModuleRESET)
begin
if ModuleRESET = '0' then
OutENABLE <= (others => '0');
Counter <= 0;
elsif rising_edge(CLK) then
if ModuleENABLE = '1' then
Counter <= Counter + 1;
case Counter is
when 0 =>
OutENABLE <= "001";
when 450 =>
OutENABLE <= "010";
when 900 =>
OutENABLE <= "100";
when 1350 =>
OutENABLE <= "001";
Counter <= 0;
when others =>
end case;
else
OutENABLE <= "000";
end if;
end if;
end process;
end Controller_archi;
但它并没有像我需要的那样工作。
我需要的:
- 当
ModuleENABLE
立即变为“1”时OutENABLE
变为“001”,而不是一开始rising_edge(CLK)
(现在,在这段代码中,如果 ModuleENABLE 变为 ' 1' OutENABLE 不会从“000”变为“001”,它在第一个 rising_edge(CLK)) 后变为“001”
- 计数器在
rising_edge(CLK)
和OutENABLE
时增加,它会在每个CLK
事件中更新。 (现在,在这段代码中,计数器在 rising_edge(CLK) 时上升,但 OutENABLE 它在 rising_edge(CLK) 时更新,而不是在 CLK 上升和下降时更新)
所以我修改了代码来做到这一点:
library IEEE;
use IEEE.std_logic_1164.all;
entity Controller is
port (
CLK : in std_logic;
OutENABLE : out std_logic_vector (2 downto 0);
ModuleRESET : in std_logic;
ModuleENABLE : in std_logic
);
end Controller;
architecture Controller_archi of Controller is
signal Counter : integer range 0 to 4200 := 0;
begin
process (CLK, ModuleENABLE, ModuleRESET)
begin
if ModuleRESET = '0' then
OutENABLE <= (others => '0');
Counter <= 0;
elsif ModuleENABLE = '1' then
if rising_edge(CLK) then
Counter <= Counter + 1;
end if;
case Counter is
when 0 =>
OutENABLE <= "001";
when 450 =>
OutENABLE <= "010";
when 900 =>
OutENABLE <= "100";
when 1350 =>
OutENABLE <= "001";
Counter <= 0;
when others =>
end case;
else
Counter <= 0;
OutENABLE <= "000";
end if;
end process;
end Controller_archi;
现在代码可以像我在 ModelSim 中需要的那样工作,但是当我综合它或编译它并再次模拟时它不起作用。
我的问题是:
第二个代码有什么问题,我该如何解决?
如果我无法修复第二个代码,我该如何修改第一个代码以按我的需要工作?
What it's wrong with second code and how I can fix it?
您的综合工具对时钟线和复位线的连接方式很挑剔。您必须使用如下结构:
if ModuleRESET = '0' then
...
elsif rising_edge(CLK) then
或者综合工具无法识别时钟线和复位线。
If I can't fix second code how I can modify first code to work like I need?
您需要将 "OutENABLE" 移出第一个进程,并移动到它自己的进程中。从你所说的来看,OutENABLE 不应该是一个寄存器——它应该是 Counter、ModuleRESET 和 ModuleENABLE 的组合函数。试试这个。
process (CLK, ModuleRESET)
begin
if ModuleRESET = '0' then
Counter <= 0;
elsif rising_edge(CLK) then
if ModuleENABLE = '1' then
Counter <= Counter + 1;
case Counter is
when 1350 =>
Counter <= 0;
when others =>
null;
end case;
end if;
end if;
end process;
process (Counter, ModuleRESET, ModuleEnable)
begin
OutENABLE <= "000";
if ModuleRESET = '1' and ModuleENABLE = '1' then
case Counter is
when 0 .. 449 =>
OutENABLE <= "001";
when 450 .. 899 =>
OutENABLE <= "010";
when 900 .. 1349 =>
OutENABLE <= "100";
when others =>
OutENABLE <= "001";
end case;
end if;
end process;