00001 --! @file
00002 --! @brief FreqDiv
00003 -- Frequncy Divider for Dynamic Lighting
00004 -- 1KHz clock
00005 -- マスタークロックを1KHzのlighting_enaに分周します。
00006 -- クロック周波数をclk_frequencyにKHz単位で設定してください。defaultで50MHzです。
00007
00008 --! Use standard library
00009 LIBRARY IEEE;
00010 --! std_logic_1164を使用
00011 USE IEEE.std_logic_1164.all;
00012 --! STD_LOGIC_ARITHを使用
00013 use IEEE.STD_LOGIC_ARITH.ALL;
00014 --! STD_LOGIC_UNSIGNEDを使用
00015 use IEEE.STD_LOGIC_UNSIGNED.ALL;
00016 --! log2を使用するのでmath_realをインクルード
00017 use ieee.math_real.all;
00018
00019 --! FreqDivのentity
00020 entity FreqDiv is
00021 generic(
00022 clk_frequency : := 50000 --! クロック周波数 (KHz)
00023 );
00024 port(
00025 clk : in ; --! クロック
00026 reset : in ; --! リセット
00027 lighting_ena : out --! LED表示イネーブル
00028 );
00029 end FreqDiv;
00030
00031 --! @brief FreqDivのアーキテクチャの定義
00032 --! @details FreqDiv
00033 architecture RTL of FreqDiv is
00034 --! lcnt (1ms間隔)
00035 signal lcnt : ((log2((clk_frequency))) downto 0);
00036 begin
00037 --! @details 1KHzに分周する
00038 FREQ_DIVIDE : process(reset, clk) begin -- Lighting frequency is 1KHz
00039 if reset='1' then
00040 lcnt <= (others => '0');
00041 elsif clk'event and clk='1' then
00042 if lcnt = conv_std_logic_vector(clk_frequency, (log2((clk_frequency)))+1) then
00043 lcnt <= (others => '0');
00044 else
00045 lcnt <= lcnt + 1;
00046 end if;
00047 end if;
00048 end process FREQ_DIVIDE;
00049
00050 lighting_ena <= '1' when lcnt = conv_std_logic_vector(clk_frequency, (log2((clk_frequency)))+1) else '0';
00051 -- lighting_ena <= '1';
00052 end RTL;
00053
00054