1 / 112

コンピュータシステム実験 VHDLによる回路設計

コンピュータシステム実験 VHDLによる回路設計. 守 川 和 夫 ( 情報電子工学科 ). MUX と DEMUX. 4 to 1 MUX の設計. 4 to 1 マルチプレクサ(セレクタ)を VHDL で記述する. RT レベルの記述 ゲートレベルの記述. library IEEE; use IEEE.std_logic_1164.all; entity MUX4to1 is port ( A,B,C,D : in std_logic; SEL : in std_logic_vector(1 downto 0);

mareo
Télécharger la présentation

コンピュータシステム実験 VHDLによる回路設計

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. コンピュータシステム実験VHDLによる回路設計コンピュータシステム実験VHDLによる回路設計 守 川 和 夫 (情報電子工学科)

  2. MUXとDEMUX

  3. 4 to 1 MUXの設計 • 4 to 1 マルチプレクサ(セレクタ)をVHDLで記述する. • RTレベルの記述 • ゲートレベルの記述

  4. library IEEE; use IEEE.std_logic_1164.all; entity MUX4to1 is port ( A,B,C,D : in std_logic; SEL : in std_logic_vector(1 downto 0); Q : out std_logic ); end MUX4to1; 4 to 1 MUX

  5. architecture RTL of MUX4to1 is begin process(A,B,C,D,SEL) begin case SEL is when “00” => Q <= A; when “01” => Q <= B; when “10” => Q <= C; when others => Q <= D; end case; end process; end RTL;

  6. architecture RTL of MUX4to1 is begin process(A,B,C,D,SEL) begin if (SEL = “00”) then Q <= A; elsif (SEL = “01”) then Q <= B; elsif (SEL = “10”) then Q <= C; else Q <= D; end if; end process; end RTL;

  7. A B Q C D SEL(1) SEL(0) 4 to 1 MUXの回路は...

  8. architecture GATE of MUX4to1 is begin Q <= ( not SEL(1) and not SEL(0) and A ) or ( not SEL(1) and SEL(0) and B ) or ( SEL(1) and not SEL(0) and C ) or ( SEL(1) and SEL(0) and D ); end GATE; ゲートレベルのアーキテクチャ

  9. FPGAの実装と動作確認 • A,B,C,Dをデータスイッチ7,6,5,4に,SELをデータスイッチ1,0に,QをアドレスLED 0に接続する. • 回路を評価ボード(TeC5)上のFPGAにダウンロードし,動作を確認する. • SELの値を変え,4 to 1のマルチプレクサとなっているか?

  10. 3 to 8 デコーダの設計 • 3 to 8 デコーダをRTレベルのVHDLで記述する.

  11. library IEEE; use IEEE.std_logic_1164.all; entity DECODER3to8 is port ( A,B,C : in std_logic; Y : out std_logic_vector(7 downto 0)); end DECODER3to8; 3 to 8 デコーダ

  12. architecture RTL of DECODER3to8 is signal IN_DATA : std_logic_vector(2 downto 0); begin IN_DATA <= A & B & C; process(IN_DATA) begin case IN_DATA is when “000” => Y <= “00000001”; when “001” => Y <= “00000010”; when “010” => Y <= “00000100”; when “011” => Y <= “00001000”; when “100” => Y <= “00010000”; when “101” => Y <= “00100000”; when “110” => Y <= “01000000”; when “111” => Y <= “10000000”; when others => Y <= “XXXXXXXX”; end case; end process; end RTL;

  13. FPGAの実装と動作確認 • A,B,Cをデータスイッチ2,1,0に,出力YをアドレスLED 7~0に接続する. • 回路を評価ボード上のFPGAにダウンロードし,動作を確認する. • A,B,Cの値によって,3 to 8デコーダとなっているか?

  14. 8 to 3 エンコーダの設計 • 8 to 3 エンコーダをRTレベルのVHDLで記述する.

  15. library IEEE; use IEEE.std_logic_1164.all; entity ENCODER8to3 is port ( INPUT : in std_logic_vector(7 downto 0); Y : out std_logic_vector(2 downto 0)); end ENCODER8to3; 8 to 3 エンコーダ

  16. architecture RTL of ENCODER8to3 is begin process(INPUT) begin case INPUT is when “00000001” => Y <= “000”; when “00000010” => Y <= “001”; when “00000100” => Y <= “010”; when “00001000” => Y <= “011”; when “00010000” => Y <= “100”; when “00100000” => Y <= “101”; when “01000000” => Y <= “110”; when “10000000” => Y <= “111”; when others => Y <= “XXX”; -- don’t care end case; end process; end RTL;

  17. don’t careの出力 • 入力スイッチが2個以上‘1’になっているかすべてのスイッチが‘0’になっているとき,case文のwhen othersで不定の‘X’を代入することで回路規模を小さくする(don’t care出力)ことができる.

  18. FPGAの実装と動作確認 • INPUTをデータスイッチ7~0に,出力YをアドレスLED 2~0に接続する. • 回路を評価ボード上のFPGAにダウンロードし,動作を確認する. • INPUTのどれかが‘1’になっているとき,8 to 3エンコーダになっているか? • INPUTが2個以上‘1’になっているかすべて‘0’になっているときは?

  19. 課題 • 1 to 4 デマルチプレクサをゲートレベルのVHDLで記述する. • 10進-BCDエンコーダをRTレベルのVHDLで記述する.

  20. library IEEE; use IEEE.std_logic_1164.all; entity DEMUX1to4 is port ( IN : in std_logic; SEL : in std_logic_vector(1 downto 0); Q : out std_logic_vector(3 downto 0)); end DEMUX1to4; 1 to 4 DEMUX

  21. architecture GATE of DEMUX1to4 is begin Q(3) <= IN and SEL(1) and SEL(0); Q(2) <= IN and SEL(1) and not SEL(0); Q(1) <= IN and not SEL(1) and SEL(0); Q(0) <= IN and not SEL(1) and not SEL(0); end GATE;

  22. library IEEE; use IEEE.std_logic_1164.all; entity BCD_ENCODER is port ( IN10 : in std_logic_vector(9 downto 0); BCD : out std_logic_vector(3 downto 0)); end BCD_ENCODER; 10進ーBCDエンコーダ

  23. architecture RTL of BCD_ENCODER is begin process(IN10) begin case IN10 is when “0000000001” => Y <= “0000”; when “0000000010” => Y <= “0001”; when “0000000100” => Y <= “0010”; when “0000001000” => Y <= “0011”; when “0000010000” => Y <= “0100”; when “0000100000” => Y <= “0101”; when “0001000000” => Y <= “0110”; when “0010000000” => Y <= “0111”; when “0100000000” => Y <= “1000”; when “1000000000” => Y <= “1001”; when others => Y <= “XXXX”; end case; end process; end RTL;

  24. カウンタの設計 • バイナリカウンタ • リングカウンタ

  25. ボード上のシステムクロック(2.4576MHz)を分周して1秒のクロックを作り出す回路をVHDLで記述する.ボード上のシステムクロック(2.4576MHz)を分周して1秒のクロックを作り出す回路をVHDLで記述する. 1秒クロックの生成 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity CLOCK is port ( CLK_2M : in std_logic; CLK_1 : out std_logic); end CLOCK;

  26. architecture RTL of CLOCK is signal Q2M : std_logic_vector(20 downto 0); signal QCLK : std_logic; begin CLK_1 <= QCLK; -- 1秒クロック process( CLK_2M ) begin if CLK_2M='1' and CLK_2M'event then if Q2M=1228799 then -- CLK_2M/2-1 Q2M <= “000000000000000000000”; -- Q2M <=(others => '0') QCLK <= not QCLK; else Q2M <= Q2M + '1'; end if; end if; end process; end RTL;

  27. 1秒クロックの動作確認 • CLK_2Mを2.4576MHz CLK(P91)に,1秒クロックCLK_1をアドレスLED 0に接続する. • 回路を評価ボード上のFPGAにダウンロードし,動作を確認する. • アドレスLED 0が1秒周期で点滅しているか?

  28. 4ビットバイナリカウンタの設計 • 4ビットバイナリカウンタをVHDLで記述する.

  29. 4ビットバイナリカウンタ library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity COUNT4 is port ( CLK,RESET : in std_logic; COUNT : out std_logic_vector (3 downto 0)); end COUNT4;

  30. architecture RTL of COUNT4 is signal CNT_IN : std_logic_vector(3 downto 0); begin COUNT <= CNT_IN; process(CLK,RESET) begin if (RESET = ‘0’) then -- RESETスイッチオン=‘0’ CNT_IN <= “0000”; elsif (CLK’event and CLK = ‘1’) then CNT_IN <= CNT_IN + ‘1’; end if; end process; end RTL;

  31. 1秒ずつで動く4ビットバイナリカウンタCOUNT4_1の構成1秒ずつで動く4ビットバイナリカウンタCOUNT4_1の構成 RESET 1秒クロック 生成 4ビット バイナリカウンタ CLK_1 CLK_2M COUNT CLOCK COUNT4 COUNT4_1

  32. 4ビットバイナリカウンタの設計 • 1秒クロック生成回路CLOCKと4ビットバイナリカウンタCOUNT4を同じアーキテクチャに2つのprocessとして記述する.

  33. 4ビットバイナリカウンタ library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity COUNT4_1 is port (CLK_2M,RESET : in std_logic; COUNT : out std_logic_vector (3 downto 0)); end COUNT4_1;

  34. architecture RTL of COUNT4_1 is signal CLK_1 : std_logic; signal Q2M : std_logic_vector(20 downto 0); signal CNT_IN : std_logic_vector(3 downto 0); begin process( CLK_2M ) begin if CLK_2M='1' and CLK_2M'event then if Q2M=1228799 then Q2M <= ( others => '0'); CLK_1 <= not CLK_1; else Q2M <= Q2M + '1'; end if; end if; end process;

  35. COUNT <= CNT_IN; process(CLK_1,RESET) begin if (RESET = ‘0’) then CNT_IN <= “0000”; elsif (CLK_1’event and CLK_1 = ‘1’) then CNT_IN <= CNT_IN + ‘1’; end if; end process; end RTL;

  36. 4ビットバイナリカウンタの動作確認 • CLK_2Mを2.4576MHz CLK(P91),RESETをRESETスイッチ(P97)に,COUNTをアドレスLED 3~0に接続する. • 回路を評価ボード上のFPGAにダウンロードし,動作を確認する. • アドレスLED 3~0がバイナリカウンタになっているか?

  37. リングカウンタ 4ビットリングカウンタの動作表

  38. 8ビットリングカウンタの設計 • 4ビットバイナリカウンタの設計と同様に,1秒クロック生成回路CLOCKと8ビットリングカウンタRING8を同じアーキテクチャに記述する.

  39. 8ビットリングカウンタ library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity RING8_1 is port (CLK_2M,RESET : in std_logic; COUNT : out std_logic_vector (7 downto 0)); end RING8_1;

  40. architecture RTL of RING8_1 is signal CLK_1 : std_logic; signal Q2M : std_logic_vector(20 downto 0); signal CNT_IN : std_logic_vector(7 downto 0); begin process( CLK_2M ) begin if CLK_2M='1' and CLK_2M'event then if Q2M=1228799 then Q2M <= ( others => '0'); CLK_1 <= not CLK_1; else Q2M <= Q2M + '1'; end if; end if; end process;

  41. COUNT <= CNT_IN; process(CLK_1,RESET) begin if (RESET = ‘0’) then CNT_IN <= “00000001”; elsif (CLK_1’event and CLK_1 = ‘1’) then CNT_IN(7 downto 1) <= CNT_IN(6 downto 0); CNT_IN(0) <= CNT_IN(7); end if; end process; end RTL;

  42. 8ビットリングカウンタの動作確認 • CLK_2Mを2.4576MHz CLK(P91),RESETをRESETスイッチ(P97)に,COUNTをアドレスLED 7~0に接続する. • 回路を評価ボード上のFPGAにダウンロードし,動作を確認する. • アドレスLED 7~0がリングカウンタになっているか? • リングカウンタをもっと速く動かせるには?

  43. 課題 • 次のカウンタの動作表を示し,VHDLで記述する. • 10進(BCD)カウンタ • 8ビットジョンソンカウンタ • それぞれのカウンタはどんなところに応用されるか?

  44. library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity COUNTBCD is port ( CLK,RESET : in std_logic; COUNT : out std_logic_vector (3 downto 0)); end COUNTBCD; 10進(BCD)カウンタ

  45. architecture RTL of COUNTBCD is signal CNT_IN : std_logic_vector(3 downto 0); begin COUNT <= CNT_IN; process(CLK,RESET) begin if (RESET = ‘1’) then CNT_IN <= “0000”; elsif (CLK’event and CLK = ‘1’) then if (CNT_IN = 9) then -- CNT_IN =“1001” CNT_IN <= “0000”; else CNT_IN <= CNT_IN + ‘1’; end if; end if; end process; end RTL;

  46. 4ビットジョンソンカウンタの動作表

  47. library IEEE; use IEEE.std_logic_1164.all; entity JOHNSON8 is port ( CLK,RESET : in std_logic; COUNT : out std_logic_vector (7 downto 0)); end JOHNSON8; 8ビットジョンソンカウンタ

  48. architecture RTL of JOHNSON8 is signal CNT_IN : std_logic_vector(7 downto 0); begin COUNT <= CNT_IN; process(CLK,RESET) begin if (RESET = ‘1’) then CNT_IN <= “00000000”; elsif (CLK’event and CLK = ‘1’) then CNT_IN(7) <= CNT_IN(6); CNT_IN(6) <= CNT_IN(5); CNT_IN(5) <= CNT_IN(4); CNT_IN(4) <= CNT_IN(3); CNT_IN(3) <= CNT_IN(2); CNT_IN(2) <= CNT_IN(1); CNT_IN(1) <= CNT_IN(0); CNT_IN(0) <= not CNT_IN(7); end if; end process; end RTL;

  49. architecture RTL of JOHNSON8 is signal CNT_IN : std_logic_vector(7 downto 0); begin COUNT <= CNT_IN; process(CLK,RESET) begin if (RESET = ‘1’) then CNT_IN <= “00000000”; elsif (CLK’event and CLK = ‘1’) then CNT_IN(7 downto 1) <= CNT_IN(6 downto 0); -- ベクタのスライスで簡単に記述 CNT_IN(0) <= not CNT_IN(7); end if; end process; end RTL;

  50. レジスタの設計 • レジスタ • シフトレジスタ

More Related