動作環境
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がカウントアップしていくようになった。
これを発展させてパルスカウントしたものをUART出力する予定。