記事一覧

ルーレットをつくる ~ リーチの判定、動作

2013年06月21日(金)10時48分

リーチかどうか判定します。

リーチである条件は
1.3個のルーレットの内、止まっている2個が一致
2.3個とも止まっていればリーチではない
で、

リーチの動作は7セグを点滅させます。

1.の判定を reach.vhd で行います。
2.の判定及び点滅を reach_ctl.vhd で行います。

reach.vhd

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity REACH is
    port(
        STOP1       : in  std_logic;    -- ルーレットが 0:動 1:止
        STOP2       : in  std_logic;    -- ルーレットが 0:動 1:止
        HIT1        : in  std_logic_vector(3 downto 0);
        HIT2        : in  std_logic_vector(3 downto 0);
        REACH_STATUS: out std_logic     -- リーチ状態 0:× 1:○
    );
end REACH;

architecture RTL of REACH is
    signal STOP_TMP    : std_logic;
    
begin
    
    STOP_TMP <= STOP1 and STOP2;

    process(STOP_TMP,HIT1,HIT2)
    begin
        if (STOP_TMP = '1') then
            if (HIT1 = HIT2) then
                REACH_STATUS <= '1';
            else
                REACH_STATUS <= '0';
            end if;
        else
            REACH_STATUS <= '0';
        end if;
    end process;
    
end RTL;

reach_ctl.vhd

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity REACH_CTL is
    port(
        REACH_CLK: in  std_logic;    -- リーチ状態の点滅用クロック
        STOP1    : in  std_logic;    -- ルーレットが 0:動 1:止
        STOP2    : in  std_logic;    -- ルーレットが 0:動 1:止
        STOP3    : in  std_logic;    -- ルーレットが 0:動 1:止
        HIT1     : in  std_logic_vector(3 downto 0);
        HIT2     : in  std_logic_vector(3 downto 0);
        HIT3     : in  std_logic_vector(3 downto 0);
        LED_CLK1 : out std_logic;    -- 7SegLEDの点滅クロック
        LED_CLK2 : out std_logic;    -- 7SegLEDの点滅クロック
        LED_CLK3 : out std_logic     -- 7SegLEDの点滅クロック
    );
end REACH_CTL;

architecture RTL of REACH_CTL is

component REACH
    port(
        STOP1       : in  std_logic;    -- ルーレットが 0:動 1:止
        STOP2       : in  std_logic;    -- ルーレットが 0:動 1:止
        HIT1        : in  std_logic_vector(3 downto 0);
        HIT2        : in  std_logic_vector(3 downto 0);
        REACH_STATUS: out std_logic    -- リーチ状態 0:× 1:○
    );
end component;

signal REACH_STOP   : std_logic_vector(2 downto 0);
signal REACH_STATUS : std_logic_vector(2 downto 0);

begin

    REACH_STOP(0) <= REACH_STATUS(0) and not STOP3;
    REACH_STOP(1) <= REACH_STATUS(1) and not STOP1;
    REACH_STOP(2) <= REACH_STATUS(2) and not STOP2;
    

    process(REACH_STOP)
    begin
        if (REACH_STOP(0) = '1') then
            LED_CLK1 <= REACH_CLK;
            LED_CLK2 <= REACH_CLK;
            LED_CLK3 <= '1';
        elsif (REACH_STOP(1) = '1') then
            LED_CLK2 <= REACH_CLK;
            LED_CLK3 <= REACH_CLK;
            LED_CLK1 <= '1';
        elsif (REACH_STOP(2) = '1') then
            LED_CLK3 <= REACH_CLK;
            LED_CLK1 <= REACH_CLK;
            LED_CLK2 <= '1';
        else
            LED_CLK1 <= '1';
            LED_CLK2 <= '1';
            LED_CLK3 <= '1';
        end if;
    end process;
    
    U1 : REACH    port map (STOP1, STOP2, HIT1, HIT2, REACH_STATUS(0)); 
    U2 : REACH    port map (STOP2, STOP3, HIT2, HIT3, REACH_STATUS(1)); 
    U3 : REACH    port map (STOP3, STOP1, HIT3, HIT1, REACH_STATUS(2));     
    
end RTL;