0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ZYBO / VHDL > カウンタ実装 / Run Simulation

Last updated at Posted at 2016-07-22
動作環境
Vivado 2015.4 on Windows 8.1 pro (64bit)

VHDLでカウントアップしていくものを作成してみる。

VHDLのコードとテストベンチの作成の手順は以下を参照
http://qiita.com/7of9/items/ec1a0048e69e74adc39a

VHDLコードとテストベンチは以下を参考にした。
http://www.asic-world.com/vhdl/first1.html

code

clockCounter.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity counter is
port(   Clk : in std_logic;
        Reset : in std_logic;
        OUT_D : out std_logic_vector (3 downto 0)
        );
end counter;

architecture Behavior of counter is
signal DFF_8 : std_logic_vector (3 downto 0);

begin

process(Clk, Reset)
begin
    OUT_D <= DFF_8;
    if (Reset = '1') then
        DFF_8 <= (others => '0');
    elsif ( clk'event and clk = '1') then    
        if (DFF_8 = "1111") then
            DFF_8 <= (others => '0');
        end if;
        DFF_8 <= DFF_8 + 1;
    end if;
end process;
end Behavior;

テストベンチ。
clk_processというプロセス以外にリセットの周期を決めるstimulus(名前は任意)プロセスを用意するということらしい。数週間前に読んだ本にもおそらく掲載されていたが、忘れていた。

clockCounter.tv
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity testbench is
end testbench;

architecture behavior of testbench is
signal clk : std_logic;
signal reset : std_logic;
signal out_d : std_logic_vector (3 downto 0);
constant clk_period : time := 10 ns;

begin
uut: entity work.counter PORT MAP (
    clk => clk,
    reset => reset,
    out_d => out_d);
  
stimulus : process
begin
    wait for 5 ns;
    reset <= '1';
    wait for 5 ns;
    reset <= '0';
    wait for 300 ns;
end process;

clk_process : process
begin
    clk <= '0';
    wait for clk_period / 2;
    clk <= '1';
    wait for clk_period / 2;
end process;

end behavior;

結果

Run Simulationの結果

reset, clkの入力に対して、out_dがカウントアップしていくようになった。

qiita.png

これを発展させてパルスカウントしたものをUART出力する予定。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?