職業訓練34日目 習得度確認テスト(PLDを用いたデジタル回路設計作業)
仕様
どういうこと?
使用しているCPLDにはLEDが8個付いてるので、
そのLEDを「ナイト2000」のようにチカチカさせる、
って、それだけなんですけどね、それだけ。
出来上がったら結構盛り上がるかな、と思ってたのに、
そもそもナイトライダー自体を知らない人が多かった…、悲しいことです。
VHDL
できれば、RTLレベルで記述したかったけど、
減算とかどうやってやればいいのかも分からないし、
それを調べる時間も手段も無かったので(言い訳)、
思いっきりビヘイビアレベルで書いちゃいました。
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGHNED.ALL; entity knightRider is Port ( SW1 : in std_logic; CLK : in std_logic; LED : OUT std_logic_vector(7 downto 0) ); end knightRider; architecture Behavioral of knightRider is constant SEG_0 : std_logic_vector(7 downto 0) := "00000000"; constant SEG_1 : std_logic_vector(7 downto 0) := "00000001"; constant SEG_2 : std_logic_vector(7 downto 0) := "00000011"; constant SEG_3 : std_logic_vector(7 downto 0) := "00000111"; constant SEG_4 : std_logic_vector(7 downto 0) := "00001110"; constant SEG_5 : std_logic_vector(7 downto 0) := "00011100"; constant SEG_6 : std_logic_vector(7 downto 0) := "00111000"; constant SEG_7 : std_logic_vector(7 downto 0) := "01110000"; constant SEG_8 : std_logic_vector(7 downto 0) := "11100000"; constant SEG_9 : std_logic_vector(7 downto 0) := "11000000"; constant SEG_9 : std_logic_vector(7 downto 0) := "10000000"; signal COUNT : std_logic_vector(3 downto 0); signal LED_OUT : std_logic_vector(7 downto 0); signal WAY : std_logic; -- LEDの進む方向を保持するフラグ begin process(CLK) begin if (CLK'event and CLK = '1') then -- ボタンが押されている間だけ、点灯させる。 -- ボタンを離したら、また右端から点灯させる。 if (not SW1 = '1') then ------ -- WAYが0のとき、LEDは左向きに進む(←) -- WAYが1のとき、LEDは右向きに進む(→) ------ if (WAY = '0') then if (COUNT = "1011") then -- 向きを反転、右向きにする。 VEC <= '1'; else COUNT <= COUNT + '1'; end if; elsif ( WAY = '1') then if (COUNT = "0000") then -- 向きを反転、左向きにする。 VEC <= '0'; else COUNT <= COUNT - '1'; end if; end if; else COUNT <= "0000"; end if; end if; end process; LED_OUT <= SEG_1 when COUNT = "0001" else SEG_2 when COUNT = "0010" else SEG_3 when COUNT = "0011" else SEG_4 when COUNT = "0100" else SEG_5 when COUNT = "0101" else SEG_6 when COUNT = "0110" else SEG_7 when COUNT = "0111" else SEG_8 when COUNT = "1000" else SEG_9 when COUNT = "1001" else SEG_10 when COUNT = "1010" else SEG_0; LED <= not LED_OUT; end Behavioral;
単に、LEDが行って帰ってチカチカするだけなんだけど、
出来たときはものすごく感動しました!
ナイトライダーの曲が頭の中流れたし。
デジカメ持って行って、動画撮っとけば良かったなぁ。