記事一覧

野球ゲームをつくる ~ 9.得点表示の点滅

2015年06月03日(水)20時35分

得点が入った時に得点表示を点滅させてみます。
ただ、ずっと点滅し続けるとうっとうしいので、
5回点滅させることにします。*1

また、点滅させるかどうかの入力信号が必要なので、
ENABLEを入れています。

blink.vhd

-- Blink
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity BLINK is
    port(
        CLK     : in  std_logic;
        ENABLE  : in  std_logic;
        BLINK       : out  std_logic
    );
end BLINK;

architecture RTL of BLINK is

signal BLINK_CNT    : std_logic_vector(2 downto 0);
signal BLINK_TMP    : std_logic;

begin

    process(CLK,ENABLE)
    begin
        if (ENABLE = '1') then
            if (CLK'event and CLK = '0') then   
                if (BLINK_CNT = "101") then
                    BLINK_TMP <= '1';
                else
                    BLINK_CNT <= BLINK_CNT + 1;
                    BLINK_TMP <= not BLINK_TMP;
                end if;
            end if;
        else
            BLINK_TMP <= '1';
            BLINK_CNT <= (others => '0');
        end if;
    end process;
    
    BLINK <= BLINK_TMP;
    
end RTL;

*1:クロックが早いとあっという間かもしれません。