参考: VHDLによるFPGA設計 & デバッグ by 松村謙 & 坂巻 佳壽美
実装
CLKの立ち上がりを検出して、FLIPという信号(Qに接続)をH/L反転する
code
if (CLK'event and CLK = '1') then
で立ち上がりを検知。
http://qiita.com/nYaaJee/items/7404a387f9e404757869
で別の方法も合わせて詳しい。
design.vhd
library IEEE;
use IEEE.std_logic_1164.all;
entity CLOCK is
port ( CLK: in std_logic;
Q : out std_logic);
end CLOCK;
architecture RTL of CLOCK is
signal FLIP : std_logic := '0';
begin
Q <= FLIP;
process(CLK)
begin
if (CLK'event and CLK = '1') then
if (FLIP = '0') then
FLIP <= '1';
else
FLIP <= '0';
end if;
end if;
end process;
end;
testbench.vhd
library IEEE;
use IEEE.std_logic_1164.all;
entity testbench is
end testbench;
architecture SIM of testbench is
signal I_CLK : std_logic := '1';
signal I_Q : std_logic := '0';
component CLOCK
port ( CLK: in std_logic;
Q : out std_logic);
end component;
begin
process begin
I_CLK <= '1';
wait for 10 ns;
I_CLK <= '0';
wait for 10 ns;
end process;
process begin
wait for 100 ns;
-- to end the testbench
assert false
report "end." severity FAILURE;
end process;
U1: CLOCK port map(CLK => I_CLK, Q => I_Q);
end SIM;
結果
CLKの立ち上がり時にFLIP(=Q)が反転した。