記事一覧

ルーレットをつくる ~ クロックの分周

2013年06月16日(日)20時05分

ルーレット用の分周をつくります。

大雑把に1Hzをクロックするを利用しました。

クロックがあまり早いと、目押しが難しいので、(私は全然ダメ)、16Hz=62.5ms位にしておきます。リーチとビンゴ用に、2Hz 8Hzも用意しました。

divider.vhd

-- Divider for Roullet
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity  DIVIDER is
    port(
        CLK          : in  std_logic;
        DIV_CLK_2HZ  : out std_logic;
        DIV_CLK_8HZ  : out std_logic;
        DIV_CLK_16HZ : out std_logic
    );
end DIVIDER;

architecture RTL of DIVIDER is
    constant OSC_BIT   : integer := 25;    --Osc 33MHz: 25bit
    signal DIV_COUNTER : std_logic_vector(OSC_BIT-1 downto 0);

begin

    process(CLK)
    begin
        if (CLK'event and CLK = '0') then
            DIV_COUNTER <= DIV_COUNTER + 1;
        end if;
    end process;
    
    DIV_CLK_2HZ  <= not DIV_COUNTER(OSC_BIT-2);
    DIV_CLK_8HZ  <= not DIV_COUNTER(OSC_BIT-4);
    DIV_CLK_16HZ <= not DIV_COUNTER(OSC_BIT-5);
    
end RTL;

ルーレットをつくる ~ ルーレットを止める

2013年06月16日(日)15時00分

ルーレットを止めます。
一旦止まるとリセットが入るまで、動きません。(動いたらルーレットじゃないですね)

oneshot.vhd

-- oneshot
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity ONESHOT is
    port(
        RESET   : in  std_logic;
        SW      : in  std_logic;
        STOP_OUT: out std_logic    -- ストップしているかどうか
    );
end ONESHOT;

architecture RTL of ONESHOT is
    
begin

    process(RESET,SW)
    begin
        if (RESET = '0') then
            STOP_OUT <= '0';
        elsif (SW'event and SW = '0') then
            STOP_OUT <= '1';
        end if;
    end process;

end RTL;

SW'event and SW = '0' で一度STOP_OUT <= '1'になると、
リセットがかかるまで、STOP_OUT <= '0'になりません。
つまり、ルーレットは止まったままになります。

oneshot.vhd とroullet.vhd を組み合わせて、
slot.vhd にします。

slot.vhd

-- slot
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity SLOT is
    port(
        DIV_CLK : in  std_logic;
        RESET   : in  std_logic;
        SW      : in  std_logic;
        STOP_OUT: out std_logic;
        HIT     : out std_logic_vector(3 downto 0)
    );
end SLOT;

architecture RTL of SLOT is

component ONESHOT
    port(
        RESET   : in  std_logic;
        SW      : in  std_logic;
        STOP_OUT: out std_logic
    );
end component;

component ROULLET
    port(
        DIV_CLK : in  std_logic;
        RESET   : in  std_logic;
        STOP_IN : in  std_logic;
        STOP_OUT: out std_logic;
        HIT     : out std_logic_vector(3 downto 0)
    );
end component;

signal STOP_TMP : std_logic;

begin

    U1 :ONESHOT    port map(RESET,SW,STOP_TMP);
    U2 :ROULLET    port map (DIV_CLK,RESET,STOP_TMP,STOP_OUT,HIT);

end RTL;

slot.vhd の回路図です。
ファイル 90-1.jpg