Presentation is loading. Please wait.

Presentation is loading. Please wait.

VHDL數位電路實習與專題設計 文魁資訊-UE301

Similar presentations


Presentation on theme: "VHDL數位電路實習與專題設計 文魁資訊-UE301"— Presentation transcript:

1 VHDL數位電路實習與專題設計 文魁資訊-UE301
亂數產生器設計 VHDL數位電路實習與專題設計 文魁資訊-UE301

2 單元7-1 號碼0 ~ 9之亂數產生器實習 實驗目的 了解利用振盪頻率產生亂數變化的原理 按下彈跳按鍵產生不同數字並在七段顯示器顯示
單元7-1 號碼0 ~ 9之亂數產生器實習 實驗目的 了解利用振盪頻率產生亂數變化的原理 按下彈跳按鍵產生不同數字並在七段顯示器顯示 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

3 相關知識 號碼0 ~ 9亂數產生器示意圖 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

4 實驗功能 以彈跳按鍵來控制亂數產生器的計數器之開始計數與停止計數 將亂數產生器的輸出顯示在七段顯示器上
按一次彈跳按鍵則開始計數,再按一次則停止計數 RANDOM_MODE9系統規格表 信號名稱 輸入/出 信號 功能 CLK INPUT 計數頻率 RST Low 重置 SEL 控制信號 Q[3:0] OUTPUT 0 ~ 9亂數輸出信號 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

5 系統方塊圖 0 ~ 9的亂數產生器實習系統規格表 信號名稱 輸入/出 信號 功能 CLK INPUT 計數頻率 RST Low 重置 SEL
控制信號 SEG_TEN_EN OUTPUT 十位數七段顯示器致能信號 SEG_ONE_EN 個位數七段顯示器致能信號 SEG[6:0] 七段顯示器顯示信號 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

6 實驗電路圖 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

7 除頻器程式碼 2 --實驗名稱:亂數產生器實習 3 --檔案名稱:clk_div.vhd 4 --功 能:除頻功能 5 --日 期: 7 library ieee; 8 use ieee.std_logic_1164.all; 9 use ieee.std_logic_unsigned.all; 10 use ieee.std_logic_arith.all; 11 12 entity clk_div is 13 generic(divisor:integer:=9); 14 port( clk_in : in std_logic; clk_out: out std_logic ); 18 end clk_div; 19 20 architecture arch of clk_div is 21 signal cnt2 : std_logic; 22 begin clk divider 24 process(clk_in) variable cnt1 : integer range 0 to divisor:=1; variable divisor2 : integer range 0 to divisor; 27 begin divisor2:=divisor/2; up counter ----- if (clk_in'event and clk_in='1') then if cnt1 = divisor then cnt1 := 1; else cnt1 := cnt1 + 1; end if; end if; clk_out register clk generator if (clk_in'event and clk_in='1') then if (( cnt1 = divisor2) or (cnt1 = divisor))then cnt2 <= not cnt2 ; end if; end if; clk_out <= cnt2 ; 44 end process; 45 end arch; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

8 號碼0 ~ 9亂數產生器程式碼 2 --實驗名稱:亂數產生器實習 3 --檔案名稱:random_mode9.vhd 4 --功 能:亂數產生號碼0~9 5 --日 期: 7 library ieee; 8 use ieee.std_logic_1164.all; 9 10 entity random_mode9 is 11 port( 12 clk :in std_logic; 13 rst :in std_logic; 14 sel :in std_logic; 15 q:out std_logic_vector(3 downto 0) ); 17 end random_mode9; 18 19 architecture a of random_mode9 is 20 type state_type is (S0,S1,S2,S3,S4,S5,S6,S7,S8,S9); 21 signal state: state_type; 22 signal qt: std_logic_vector(3 downto 0); 23 signal d, d0, d1: std_logic; 24 signal run : std_logic := '0'; 25 begin 26 process(clk) 27 begin if rst = '0' then state <= S0; elsif clk'event and clk = '1' then d1<=d0; d0<=sel; case state is when S0 => if (run = '0') then state <= S1; end if; when S1 => if (run = '0') then state <= S2; end if; when S2 => if (run = '0') then state <= S3; end if; when S3 => if (run = '0') then state <= S4; end if; when S4 => if (run = '0') then state <= S5; end if; when S5 => if (run = '0') then state <= S6; end if; when S6 => if (run = '0') then state <= S7; end if; when S7 => if (run = '0') then state <= S8; end if; when S8 => if (run = '0') then state <= S9; end if; when S9 => if (run = '0') then state <= S0; end if; when others => null; end case; end if; 46 end process; 47 d <= d1 and not d0; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

9 號碼0 ~ 9亂數產生器程式碼 48 with state select 49 qt <= "0000" when S0,
59 process(d, clk) 60 begin if clk'event and clk='1' then q<=qt; 63 if (d='1') then run <= not run; end if; end if; 67 end process; 68 end a; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

10 二進制轉七段顯示器編碼程式碼 2 --實驗名稱:亂數產生器實習 3 --檔案名稱:bin2dec.vhd 4 --功 能:二進制轉七段顯示器編碼 5 --日 期: 7 -- a <= seg(0); 8 -- b <= seg(1); 9 -- c <= seg(2); d <= seg(3); e <= seg(4); f <= seg(5); g <= seg(6); 14 library ieee; 15 use ieee.std_logic_1164.all; 16 entity bin2dec is 17 port ( dip : in std_logic_vector(3 downto 0); seg : out std_logic_vector(6 downto 0); seg_en : out std_logic ); 22 end bin2dec; 23 24 architecture arch of bin2dec is 25 begin PROGRAM BODY ----- 27 seg_en<='1'; binary to seven segment decoder ----- 29 process (dip) 30 begin case dip is when "0000" => seg <= " "; -- 0 when "0001" => seg <= " "; -- 1 when "0010" => seg <= " "; -- 2 when "0011" => seg <= " "; -- 3 when "0100" => seg <= " "; -- 4 when "0101" => seg <= " "; -- 5 when "0110" => seg <= " "; -- 6 when "0111" => seg <= " "; -- 7 when "1000" => seg <= " "; -- 8 when "1001" => seg <= " "; -- 9 when "1010" => seg <= " "; -- A when "1011" => seg <= " "; -- b when "1100" => seg <= " "; -- C when "1101" => seg <= " "; -- d when "1110" => seg <= " "; -- E when "1111" => seg <= " "; -- F when others => seg <= " "; end case; 50 end process; 51 end arch; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

11 亂數產生器主程式 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計 33 ----- bin2dec -----
2 --實驗名稱:亂數產生器實習 3 --檔案名稱:random9_top.vhd 4 --功 能:以彈跳按鍵產生亂數0~9且在七段顯示器顯示 5 --日 期: 7 library ieee; 8 use ieee.std_logic_1164.all; 9 use ieee.std_logic_unsigned.all; 10 use ieee.std_logic_arith.all; 11 12 entity random9_top is 13 port( clk: in std_logic; rst: in std_logic; sel: in std_logic; seg_out: out std_logic_vector(6 downto 0); seg_one_en: out std_logic; seg_ten_en: out std_logic; bz : out std_logic ); 22 end random9_top; 23 24 architecture arch of random9_top is clk_div ----- 26 component clk_div 27 generic(divisor:integer:=8); 28 port( clk_in : in std_logic; clk_out: out std_logic ); 32 end component; bin2dec ----- 34 component bin2dec 35 port( dip : in std_logic_vector(3 downto 0); seg : out std_logic_vector(6 downto 0); seg_en : out std_logic ); 40 end component; random_mode 42 component random_mode9 43 port( clk : in std_logic; rst : in std_logic; sel : in std_logic; q : out std_logic_vector(3 downto 0) ); 49 end component; 50 signal clk1: std_logic; 51 signal dip : std_logic_vector(3 downto 0); 52 begin 53 seg_ten_en <= '0'; 54 bz <= '0'; 55 U1: clk_div generic map(184320) port map(clk,clk1); 58 U2: random_mode9 port map(clk1,rst,sel,dip); 59 U3: bin2dec port map(dip,seg_out,seg_one_en); 60 end arch; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

12 主程式電路連線(random9_top_grahp.gdf)
註:在主程式中加入蜂鳴器控制信號,是為了不讓蜂鳴器因為信號干擾而發出聲響, 因此我們將蜂鳴器控制信號bz設定為低電位。 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

13 功能模擬 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

14 腳位配置 號碼0 ~ 9之亂數產生器實習腳位配置表 輸入 腳位 輸出 CLK 43 SEG_TEN_EN 26 RST 37(SW1)
SEG_ONE_EN 27 SEL 39(SW2) SEG[0] 16(SEG_a) SEG[1] 17(SEG_b) SEG[2] 18(SEG_c) SEG[3] 19(SEG_d) SEG[4] 20(SEG_e) SEG[5] 21(SEG_f) SEG[6] 24(SEG_g) BZ 28(BZ) 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

15 編譯錯誤解決方法 編繹錯誤訊息圖 編繹錯誤訊息圖 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

16 編譯錯誤解決方法 將Clear的設定取消圖 設定Global Project Logic Synthesis圖
陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

17 編譯錯誤解決方法 重新Compiler 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

18 FPT-3實驗板元件規劃 RST SEL 7 Segment 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

19 用於LP-2900實驗板上的除頻器程式碼 2 --實驗名稱:亂數產生器實習 3 --檔案名稱:clk_div_lp2900.vhd 4 --功 能:除頻功能, clk_out = clk_in / divisor 5 --日 期: 7 library ieee; 8 use ieee.std_logic_1164.all; 9 use ieee.std_logic_unsigned.all; 10 use ieee.std_logic_arith.all; 11 12 entity clk_div_lp2900 is 13 generic(divisor:integer:= ); 14 port( clk_in : in std_logic; clk_out: out std_logic ); 18 end clk_div_lp2900; 19 20 architecture arch of clk_div_lp2900 is 21 signal cnt2 : std_logic; 22 begin clk divider 24 process(clk_in) variable cnt1 : integer range 0 to divisor:=1; variable divisor2 : integer range 0 to divisor; 27 begin divisor2:=divisor/2; up counter ----- if (clk_in'event and clk_in='1') then if cnt1 = divisor then cnt1 := 1; else cnt1 := cnt1 + 1; end if; end if; clk_out register clk generator ----- if (clk_in'event and clk_in='1') then if (( cnt1 = divisor2) or (cnt1 = divisor))then cnt2 <= not cnt2 ; end if; end if; clk_out <= cnt2 ; 44 end process; 45 end arch; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

20 用於LP-2900實驗板上的二進制轉七段顯示器編碼程式碼
2 --實驗名稱:亂數產生器實習 3 --檔案名稱:bin2dec_LP2900.vhd 4 --功 能:二進制轉七段顯示器編碼 5 --日 期: 7 -- a <= seg(0); 8 -- b <= seg(1); 9 -- c <= seg(2); d <= seg(3); e <= seg(4); f <= seg(5); g <= seg(6); 14 15 library ieee; 16 use ieee.std_logic_1164.all; 17 entity bin2dec_LP2900 is 18 port ( dip : in std_logic_vector(3 downto 0); seg : out std_logic_vector(6 downto 0); DE : out std_logic_vector(2 downto 0) ); 23 end bin2dec_LP2900; 24 25 architecture arch of bin2dec_LP2900 is 26 begin PROGRAM BODY ----- 28 DE<="000"; binary to seven segment decoder ----- 30 process (dip) 31 begin case dip is when "0000" => seg <= " "; -- 0 when "0001" => seg <= " "; -- 1 when "0010" => seg <= " "; -- 2 when "0011" => seg <= " "; -- 3 when "0100" => seg <= " "; -- 4 when "0101" => seg <= " "; -- 5 when "0110" => seg <= " "; -- 6 when "0111" => seg <= " "; -- 7 when "1000" => seg <= " "; -- 8 when "1001" => seg <= " "; -- 9 when "1010" => seg <= " "; -- A when "1011" => seg <= " "; -- b when "1100" => seg <= " "; -- C when "1101" => seg <= " "; -- d when "1110" => seg <= " "; -- E when "1111" => seg <= " "; -- F when others => seg <= " "; end case; 51 end process; 52 end arch; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

21 主程式電路架構圖(random9_lp2900.gdf)
陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

22 腳位配置表(LP-2900實驗板) 輸入 腳位 輸出 CLK 55 DE(0) 33(DE1) RST 54(PS1) DE(1)
SEL 56(PS2) DE(2) 37(DE3) SEG(0) 23(A) SEG(1) 26(B) SEG(2) 27(C) SEG(3) 28(D) SEG(4) 29(E) SEG(5) 30(F) SEG(6) 31(G) 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

23 LP-2900實驗板元件規劃 7 segment RST SEL 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

24 練習 試著設計出一個以彈跳按鍵控制的1 ~ 8亂數產生器,並將結果在LED上顯示。
試著設計出一個以彈跳按鍵控制的亂數產生器,並可先以指撥開關設定一數字並顯示在十位數七段顯示器上,若所產生的亂數與指撥開關所設定的數字相同時,啟動蜂鳴器。 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

25 單元7-2樂透彩亂數產生器實習 實驗目的 利用亂數產生器產生1 ~ 42 的樂透彩號碼。 按下彈跳按鍵產生樂透彩號碼並在七段顯示器顯示。
陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

26 相關知識 樂透彩亂數產生器示意圖 當十位數是0的情況下,個位數計數器需要從1開始計數到9。
當十位數是4的情況下,個位數計數器需要從0開始計數到2。 當十位數是4的情況下,且個位數計數器為2,則必須由01開始重新計數。 樂透彩亂數產生器示意圖 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

27 實驗功能 以彈跳按鍵作為產生號碼的控制訊號,將1 ~ 42號的亂數產生器所產生出來的十位數與個位數分別以SCAN的方式在七段顯示器上顯示出來。 RANDOM_LOTTO系統規格表 信號名稱 輸入/出 信號 功能 CLK INPUT 計數頻率 RST Low 重置 SEL 控制信號 Q_TEN[3:0] OUTPUT 十位數輸出信號 Q_ONE[3:0] 個位數輸出信號 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

28 樂透彩亂數產生器實習 樂透彩亂數產生器示意圖 樂透彩亂數產生器系統規格表 信號名稱 輸入/出 信號 功能 CLK INPUT 計數頻率
RST Low 重置 SEL 控制信號 SEG_EN HIGH 七段顯示器掃描電路致能信號 SEG_TEN_EN OUTPUT 十位數七段顯示器致能信號 SEG_ONE_EN 個位數七段顯示器致能信號 SEG_OUT[6:0] 七段顯示器顯示信號 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

29 實驗電路圖 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

30 頻率產生器程式碼 2 --實驗名稱:亂數產生器實習 3 --檔案名稱:clk_gen.vhd 4 --功 能:頻率產生器 5 --日 期: 7 library ieee; 8 use ieee.std_logic_1164.all; 9 use ieee.std_logic_unsigned.all; 10 entity clk_gen is 11 port( clk_in : in std_logic; clk_out1: out std_logic; clk_out2: out std_logic ); 16 end clk_gen; 17 architecture a of clk_gen is 18 signal cnt : std_logic_vector(19 downto 0); 19 signal reset: std_logic; 20 begin 21 process (clk_in) 22 begin if reset='1' then cnt<=" "; elsif clk_in'event and clk_in='1' then cnt<=cnt+1; end if; 28 end process; 29 30 reset<='1' when cnt= else '0'; 31 clk_out1<=cnt(14); --32hz 32 clk_out2<=cnt(13); --64hz 33 end a; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

31 樂透彩亂數產生器程式碼 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計
2 --實驗名稱:亂數產生器實習 3 --檔案名稱:random_lotto.vhd 4 --功 能:亂數產生號碼1~42 5 --日 期: 7 library ieee; 8 use ieee.std_logic_1164.all; 9 use ieee.std_logic_arith.all; 10 use ieee.std_logic_unsigned.all; 11 12 entity random_lotto is 13 port( clk : in std_logic; rst : in std_logic; sel : in std_logic; q_one: out std_logic_vector(3 downto 0); q_ten: out std_logic_vector(3 downto 0) ); 20 end random_lotto; 21 22 architecture a of random_lotto is 23 signal cnt_one,cnt_ten : std_logic_vector(3 downto 0); 24 signal s,s0,s1 : std_logic; 25 begin 26 process (clk,rst) 27 begin if rst='0' then cnt_one <= "0001"; cnt_ten <= "0000"; s0 <= '1'; s1 <= '1'; elsif clk'event and clk='1' then s1<=s0; s0<=sel; if cnt_ten = "0100" then if cnt_one = "0010" then cnt_one <= "0001"; cnt_ten <= "0000"; else cnt_one <= cnt_one + 1; end if; elsif cnt_one = "1001" then cnt_one <= "0000"; cnt_ten <= cnt_ten + 1; else cnt_one <= cnt_one + 1; end if; 47 end if; 48 end process; 49 s <= s1 and not s0; 50 process(clk,rst) 51 begin if clk'event and clk='1' then if rst='0' then q_one <= "0000"; q_ten <= "0000"; elsif s = '1' then q_one <= cnt_one; q_ten <= cnt_ten; end if; end if; 61 end process; 62 end a; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

32 具掃描功能之二進制轉七段顯示器編碼程式碼
2 --實驗名稱:亂數產生器實習 3 --檔案名稱:bin2seg0_scan.vhd 4 --功 能:具掃描功能之二進制轉七段顯示器編碼 6 --a <= seg(0); b <= seg(1); c <= seg(2); d <= seg(3); 7 --e <= seg(4); f <= seg(5); g <= seg(6); 8 library ieee; 9 use ieee.std_logic_1164.all; 10 use ieee.std_logic_unsigned.all; 11 use ieee.std_logic_arith.all; 12 13 entity bin2seg0_scan is 14 port ( clk: in std_logic; seg_en: in std_logic; q_one: in std_logic_vector(3 downto 0); q_ten : in std_logic_vector(3 downto 0); seg_out : out std_logic_vector(6 downto 0); seg_one_en: out std_logic; seg_ten_en: out std_logic ); 23 end bin2seg0_scan; 24 25 architecture arch of bin2seg0_scan is 26 signal bin: std_logic_vector(3 downto 0); 27 signal seg: std_logic_vector(6 downto 0); 28 signal sel: integer range 0 to 1; 29 begin scan and signal assign ----- 31 process (clk, seg_en) 32 begin if clk'event and clk='1' then if (seg_en='0') then seg_one_en<='0'; seg_ten_en<='0'; sel<=0; else sel<=sel+1; case sel is when 0 => bin<=q_one; seg_one_en<='1'; seg_ten_en<='0'; when 1 => bin<=q_ten; seg_one_en<='0'; seg_ten_en<='1'; when others => null; end case; end if; end if; 54 end process; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

33 具掃描功能之二進制轉七段顯示器編碼程式碼
binary to seven segment decoder ----- 56 process (bin) 57 begin case bin is when "0000" => seg_out <= " "; -- 0 when "0001" => seg_out <= " "; -- 1 when "0010" => seg_out <= " "; -- 2 when "0011" => seg_out <= " "; -- 3 when "0100" => seg_out <= " "; -- 4 when "0101" => seg_out <= " "; -- 5 when "0110" => seg_out <= " "; -- 6 when "0111" => seg_out <= " "; -- 7 when "1000" => seg_out <= " "; -- 8 when "1001" => seg_out <= " "; -- 9 when others => seg_out <= " "; end case; 71 end process; 72 end arch; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

34 樂透彩亂數產生器主程式 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計
2 --實驗名稱:亂數產生器實習 3 --檔案名稱:random_lotto_top.vhd 4 --功 能:樂透彩亂數產生器 5 --日 期: 7 library ieee; 8 use ieee.std_logic_1164.all; 9 use ieee.std_logic_unsigned.all; 10 use ieee.std_logic_arith.all; 11 12 entity random_lotto_top is 13 port( clk : in std_logic; rst : in std_logic; sel : in std_logic; seg_en : in std_logic; seg_out : out std_logic_vector(6 downto 0); seg_one_en: out std_logic; seg_ten_en: out std_logic; bz : out std_logic ); 23 end random_lotto_top; 24 25 architecture arch of random_lotto_top is random_lotto ----- 27 component random_lotto 28 port( clk : in std_logic; rst : in std_logic; sel : in std_logic; q_one: out std_logic_vector(3 downto 0); q_ten: out std_logic_vector(3 downto 0) ); 35 end component; bin2seg0_scan ----- 37 component bin2seg0_scan 38 port ( clk : in std_logic; seg_en : in std_logic; q_one : in std_logic_vector(3 downto 0); q_ten : in std_logic_vector(3 downto 0); seg_out : out std_logic_vector(6 downto 0); seg_one_en: out std_logic; seg_ten_en: out std_logic ); 47 end component; clk_gen ----- 49 component clk_gen 50 port( clk_in : in std_logic; clk_out1: out std_logic; clk_out2: out std_logic ); 55 end component; 56 signal clk_out1,clk_out2 : std_logic; 57 signal q_one,q_ten : std_logic_vector(3 downto 0); 58 signal clk_64 : std_logic; 59 begin 60 bz<=’0’; 61 U1: clk_gen port map(clk,clk_out1,clk_out2); 62 U2: random_lotto port map(clk_out1,rst,sel,q_one,q_ten); 63 U3: bin2seg0_scan port map(clk_out2, seg_en, q_one, q_ten, seg_out, seg_one_en, seg_ten_en); 65 end arch; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

35 功能模擬 樂透彩亂數產生器random_lotto功能模擬圖 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

36 樂透彩亂數產生器實習腳位配置表 訊號名稱 CPLD腳位 CLK 43 SEG_TEN_EN 26 RST 37(SW1)
SEG_ONE_EN 27 SEL 39(SW2) SEG_OUT[0] 16(SEG_a) SEG_EN 29 SEG_OUT [1] 17(SEG_b) SEG_OUT [2] 18(SEG_c) SEG_OUT [3] 19(SEG_d) SEG_OUT [4] 20(SEG_e) SEG_OUT [5] 21(SEG_f) SEG_OUT [6] 24(SEG_g) 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

37 FPT-3實驗板元件規劃 RST SEL 7 Segment SEG_EN 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

38 除頻電路程式碼 (LP-2900) 2 --實驗名稱:樂透彩亂數產生器實習 3 --檔案名稱:clk_div_64_lp2900.vhd 4 --功 能:產生掃描頻率 5 --日 期: 7 Library IEEE; 8 Use IEEE.std_logic_1164.all; 9 Use ieee.std_logic_unsigned.all; 10 Use IEEE.std_logic_arith.all; 11 12 Entity clk_div_64_lp2900 is 13 Port( clk: in std_logic; system clock(10MHz) clk_64hz: out std_logic; --64Hz output clk_32hz: out std_logic --32Hz outpout ); 18 end clk_div_64_lp2900; 19 architecture arch of clk_div_64_lp2900 is 20 signal count : integer range 0 to ; 21 signal clk_64_temp,clk_32_temp : std_logic; 22 begin 23 process (clk) 24 begin 25 if rising_edge(clk) then count<=count+1; if count>=78124 then clk_64_temp <= '1'; else clk_64_temp <= '0'; end if; 32 end if; 33 clk_64hz <= clk_64_temp; 34 end process; 35 36 process(clk_64_temp) 37 begin 38 if rising_edge(clk_64_temp) then clk_32_temp <= not clk_32_temp; 40 end if; 41 clk_32hz <= clk_32_temp; 42 end process; 43 end arch; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

39 具掃描功能之二進制轉七段顯示器編碼程式碼(LP-2900)
2 --實驗名稱:樂透彩亂數產生器實習 3 --檔案名稱:bin2seg_scan_lp2900.vhd 4 --功 能:具掃描功能之二進制轉七段顯示器編碼 5 --日 期: (LP-2900) 7 --a <= seg(0); b <= seg(1); c <= seg(2); d <= seg(3); 8 --e <= seg(4); f <= seg(5); g <= seg(6); 9 library ieee; 10 use ieee.std_logic_1164.all; 11 use ieee.std_logic_unsigned.all; 12 use ieee.std_logic_arith.all; 13 14 entity bin2seg_scan_lp2900 is 15 port ( clk : in std_logic; seg_en : in std_logic; q_one : in std_logic_vector(3 downto 0); q_ten : in std_logic_vector(3 downto 0); seg_out : out std_logic_vector(6 downto 0); DE : out std_logic_vector(2 downto 0) ); 23 end bin2seg_scan_lp2900; 24 25 architecture arch of bin2seg_scan_lp2900 is 26 signal bin: std_logic_vector(3 downto 0); 27 signal seg: std_logic_vector(6 downto 0); 28 signal sel: integer range 0 to 1; 29 begin scan and signal assign ----- 31 process (clk, seg_en) 32 begin if clk'event and clk='1' then if (seg_en='0') then sel<=0; else sel<=sel+1; case sel is when 0 => bin<=q_one; DE <= "101"; when 1 => bin<=q_ten; DE <= "100"; when others => null; end case; end if; end if; 50 end process; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

40 具掃描功能之二進制轉七段顯示器編碼程式碼(LP-2900)
binary to seven segment decoder ----- 52 process (bin) 53 begin case bin is when "0000" => seg_out <= " "; -- 0 when "0001" => seg_out <= " "; -- 1 when "0010" => seg_out <= " "; -- 2 when "0011" => seg_out <= " "; -- 3 when "0100" => seg_out <= " "; -- 4 when "0101" => seg_out <= " "; -- 5 when "0110" => seg_out <= " "; -- 6 when "0111" => seg_out <= " "; -- 7 when "1000" => seg_out <= " "; -- 8 when "1001" => seg_out <= " "; -- 9 when others => seg_out <= " "; end case; 67 end process; 68 end arch; 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

41 主程式電路架構圖(random_lotto_top_LP2900.gdf)
陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

42 樂透彩亂數產生器實習腳位規劃表 (LP-2900實驗板)
輸入 腳位 輸出 CLK 55 DE(0) 33(DE1) RST 54(PS1) DE(1) 36(DE2) SEL 56(PS2) DE(2) 37(DE3) SEG(0) 23(A) SEG(1) 26(B) SEG(2) 27(C) SEG(3) 28(D) SEG(4) 29(E) SEG(5) 30(F) SEG(6) 31(G) 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

43 LP-2900實驗板元件規劃 7 segment RST SEL 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

44 練習 試著在LP-2900上設計一個4星彩號碼產生機,也就是隨機產生4個0~9的數字。
陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計

45 勘誤 陳慶逸、林柏辰編著---文魁資訊 VHDL數位電路實習與專題設計


Download ppt "VHDL數位電路實習與專題設計 文魁資訊-UE301"

Similar presentations


Ads by Google