2016-09-08 15 views
0

私は現在、私の簡単なカウンタについて少し混乱しています。 これは次のように実装されています。シンプルなVHDLクロックカウンタシミュレーションの混乱

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_ARITH.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 

entity simple_counter is 
    port( 
     DOUT : out std_logic_vector(3 downto 0); 
     CE : in std_logic; 
     CLK : in std_logic; 
     RSTN : in std_logic 
    ); 
end simple_counter; 

architecture behavioral of simple_counter is 
    signal temp : unsigned(3 downto 0); 

begin 

    process(CLK) 
    begin 
     if RSTN = '0' then 
      temp <= (others => '0'); 
     elsif(rising_edge(CLK)) then 
      if CE = '1' then 
       if std_logic_vector(temp) = (temp'range => '1') then 
        temp <= (others => '0'); 
       else 
        temp <= temp + 1; 
       end if; 
      end if; 
     end if; 
    end process; 

    DOUT <= std_logic_vector(temp); 

end behavioral; 

私はシミュレーションのために、次のテストベンチを使用します。

library ieee; 
use ieee.std_logic_1164.all; 
use ieee.numeric_std.all; 
library std; 
use std.textio.all; 

use work.tools_pkg.all; 

library work; 

--! @class tools_tb 
--! @brief Test bench for the tools_tb design 
entity counter_tb is 
    generic (
    VOID : integer := 0); 
    port (
    void_i : in std_logic); 
end entity counter_tb; 

--! @brief 
--! @details 
architecture sim of counter_tb is 

    -- Clock period definitions 
    -- Clock, reset and baud rate definitions 
    constant CLK_FREQ : integer := 100_000_000; 
    constant clk_period : time  := (1.0/real(CLK_FREQ)) * (1 sec); 
    signal end_sim   : boolean := false; 

    signal rstn    : std_logic; 
    signal clk    : std_logic; 
    signal s_en    : std_logic := '0'; 

    ------------------------------------------------------------------------------ 
    -- DUT signals 
    ------------------------------------------------------------------------------ 

    signal s_dout  : std_logic_vector(3 downto 0) := (others => '0'); 
    signal s_ce   : std_logic := '0'; 

begin -- architecture 


    fifo : entity work.simple_counter 
    port map (
     DOUT => s_dout, 
     CE => s_ce, 
     RSTN => rstn, 
     CLK => clk 
    ); 


    -- Clock process definitions (clock with 50% duty cycle is generated here). 
    clk_process : process 
    begin 
     if end_sim = false then 
      clk <= '1'; 
      wait for clk_period/2; 
      clk <= '0'; 
      wait for clk_period/2; 
     else 
      wait; 
     end if; 
    end process; 

    -- Stimulus process 
    stim_proc: process 
    begin 
     -- startup and wait for some time 
     rstn <= '0'; 
     wait for clk_period; 
     rstn <= '1'; 
     wait for clk_period; 
     wait for clk_period; 
     wait for clk_period; 

     s_ce <= '1'; 

     wait; 
    end process; 

end architecture sim; 

カウンタが増加して瞬時に私はCE <= '1 は、(添付のシミュレーションを見る)設定すると、なぜ私は混乱しています。 enter image description here カウンタは同期プロセスで実装されているため、 '0'から '1'に増加するまで単一クロックサイクルを使用しないでください。

ありがとうございます!

答えて

0

s_ceclkの競合状態が考えられます。 clkの立ち上がりエッジでs_ceを生成する場合、そのカウンタが正しく動作するはずです。

私はこのシミュレータを知らないが、カウンタが> 1 0-

+0

おかげで多くのことを変更した場合、あなたがデルタを拡張することができますレースをチェックします!テスベンチで 'waiting for clk_period;'を 'rising_edge(CLK)まで待つ 'に変更すると、カウンタは期待通りに動作します! – Apoptose

+0

あなたは彼の答えを使用しなかった場合、彼を受け入れるのではなくあなた自身の答えを提供することができました。 – user1155120