1
2

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 > Clock Divider > VHDL実装 / Run Simulation

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

http://zynqhowto.blogspot.jp/2014/03/zynq-how-to.html
のLab1.pdfを参考にClock DividerのVHDLファイルとテストベンチを試している。

UniClkDiv.vhd

VHDL実装の記述(UniClkDiv.vhd)はBehavioralのend;が抜けているため、そのままの実装だとエラーとなる。以下のように最後の行(end;)を追加した。

UniClkDiv.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity clk_gen is
port(   Clk : in std_logic;
        Clk_mod : out std_logic
        );
end clk_gen;

architecture Behavioral of clk_gen is
    signal counter : integer := 0;
    constant divide : integer := 100;
begin
    process(Clk)
    begin
        if( rising_edge(Clk) ) then
            if(counter < divide/2 - 1) then
                counter <= counter + 1;
                Clk_mod <= '1';
            elsif(counter < divide - 1) then
                counter <= counter + 1;
                Clk_mod <= '0';
            else
                Clk_mod <= '1';
                counter <= 0;
            end if;
        end if;
    end process;   
end;

テストベンチ

テストベンチ側は画像のソースそのままでも問題なかった。

testbench.tb
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity testbench IS
end testbench;

architecture behavior of testbench IS
    signal clk, clk_mod : std_logic;
    constant clk_period : time := 10 ns;
begin
-- Component Instantiation
uut: entity work.clk_gen PORT MAP (
    clk => clk,
    clk_mod => clk_mod);
clk_process : process -- generate a 100 MHz Clock.
begin
    clk <= '0';
    wait for clk_period/2; -- for 5 ns signal is '0'.
    clk <= '1';
    wait for clk_period/2; -- for next 5 ns signal is '1'.
end process;
end;

実行

Run Simulationを実行したところ、以下のようになった。

qiita.png

5nsごとにH/L切替えのclkに対してclk_modは100分周して500nsのところでH/L切替えしているので、Clock Dividerとして動作しているようだ。

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?