【发布时间】:2018-09-03 16:07:15
【问题描述】:
我的代码 vhdl 代码中有这个小不匹配。我正在使用时钟计数器做信号展宽器。 基本上,在我与 2 ff 同步器同步并为我的 fsm 使用这个“syncrhro-start”之后,我收到一个外部信号作为“开始”。它读取寄存器中的值并让“门”打开我设置为寄存器的计数。我的时钟周期为 25 ns(40MHz 时钟)。 因此,当我在寄存器上设置值“0”时,我没有任何信号(如预期的那样)。如果我设置“1”,我的信号为 50 ns 而不是 25ns。 如果我设置“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;
所以如果我在这个 TB 中设置 长度_tb
【问题讨论】:
-
您不提供minimal reproducible example 允许在不编写测试平台的情况下复制问题。我的评论提供的更正答案是有效的,但如果没有 MCVe,未来的读者如何从您的问题中寻找解决方案的问题以及他们无法解释或复制的解决方案?
-
您的测试台与您的问题描述不符。 lenght_tb 没有变化。您还可以注意到,gate_on(开始)信号不是时钟同步反映 ...在我将其与 2 ff 同步器同步并将此“syncrhro-start”用于我的 fsm 之后。你的测试台只产生一个长度的门输出。
-
我使用 2 个触发器制作的特定块同步了真实的模拟信号。在这个我可以定义信号的阶段,我觉得这没什么用,我用我需要模拟的值更改了 lenght_tb。因此,如果我需要 75ns 或 3 个时钟周期的输出信号的“最终长度”,我设置 lenght_tb