我的代码vhdl代码中有这个小的不匹配项。我正在使用时钟计数器进行信号扩展。 基本上,我将外部信号与2 ff同步器同步并将其作为fsm使用此“ syncrhro-start”后,便会收到一个外部信号“ start”。它读取寄存器中的值,并让“门”打开我设置为reg的计数数。我的时钟周期为25 ns(40MHz时钟)。 因此,当我在寄存器上设置值“ 0”时,我没有任何信号(如预期的那样)。如果我设置为“ 1”,则我的信号为50 ns而不是25 ns。 如果我设置为“ 2”,则我有一个75ns的信号输出。从概念上讲,它是有效的(二进制中的2是01,所以它从0开始计数,所以0-1-2是3时钟运行/ 75ns)。
但是我需要使用“ 1”表示25ns的信号,使用2表示50ns,依此类推。
这是我的代码:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.ALL;
entity gate is
Port (
start : in STD_LOGIC := '0'; --segnale di start
clk : in STD_LOGIC; --clock di ingresso
reset : in STD_LOGIC; --ff reset
gate: out STD_LOGIC; --gate in uscita
lenght: in std_logic_vector (7 downto 0)
);
end gate;
architecture behavioral of gate is
--type state_type is (idle, gate_up, final);
type state_type is (idle, stretching);
signal state : state_type;
begin
process (reset, clk, start)
variable index : integer :=0;
variable gate_v: std_logic;
variable gatelen : integer;
begin
gatelen := to_integer(unsigned(lenght));
if reset = '1' then
gate_v := '0';
index := 0;
else
if rising_edge(clk) then
case state is
when idle =>
index := 0;
gate_v :='0';
if(start = '1') then
state <= stretching;
else
state <= idle;
end if;
when stretching =>
if index = gatelen then
state <=idle;
else
gate_v := '1';
index := index + 1;
state <= stretching;
end if;
when others => null;
end case;
end if;
end if;
gate <= gate_v;
end process;
end Behavioral;
我可以使用此模块部分修复问题
gatelen:= to_integer(unsigned(lenght))-1;
但是在这种情况下,如果我在注册表上输入“ 1”,则不会有任何信号,如果我输入“ 2”,则输出信号为50ns。 25ns输出信号仍然丢失。
任何帮助将不胜感激!
编辑:
感谢您的回复,我还将添加测试平台的代码。
library ieee;
use ieee.std_logic_1164.all;
entity gate_tb is
end gate_tb;
architecture behavioral of gate_tb is
signal master_clk : std_logic := '0';
signal global_rst : std_logic := '0';
signal gate_on : std_logic := '0';
signal gate_out : std_logic := '0';
constant clk_period : time := 25 ns; --40ns
signal lenght_tb : std_logic_vector (7 downto 0);
component gate is
port(
clk : in std_logic;
reset : in std_logic;
start : in std_logic;
gate: out std_logic;
lenght: in std_logic_vector ( 7 downto 0)
);
end component gate;
begin
uut : gate port map (
clk => master_clk,
reset => global_rst,
start => gate_on,
gate => gate_out,
lenght => lenght_tb
);
gate_process : process
begin
master_clk <= '0';
wait for clk_period/2; --for 10 ns signal is '0'.
master_clk <= '1';
wait for clk_period/2; --for next 10 ns signal is '1'.
end process;
--stimulus
stim : process
begin
lenght_tb <= "00000001";
wait for 50 ns;
global_rst <= '1';
wait for 30 ns;
global_rst <= '0';
wait for 50 ns;
gate_on <= '1';
wait for 35 ns;
gate_on <= '0';
wait for 150 ns;
gate_on <= '1';
wait for 35 ns;
gate_on <= '0';
wait for 150 ns;
gate_on <= '1';
wait for 35 ns;
gate_on <= '0';
wait for 150 ns;
gate_on <= '1';
wait for 35 ns;
gate_on <= '0';
wait for 150 ns;
end process;
end behavioral;
所以如果我在这个结核病中 lenght_tb <=“ 00000000”;出0 我设置好了吗 lenght_tb <=“ 00000001”; out是50 ns而不是25 ns的信号。
答案 0 :(得分:1)
问题处于拉伸状态,例如查找reg = 1:
在检查index = gatelen时必须设置gate = 0:
when stretching =>
if index = gatelen then
gate_v := '0';
state <=idle;
else
gate_v := '1';
index := index + 1;
state <= stretching;
end if;