[問題] vhdl程式問題

看板Electronics作者 (丹)時間16年前 (2009/12/27 03:31), 編輯推噓1(103)
留言4則, 1人參與, 最新討論串1/1
這個是0~9的亂數產生器程式,想請教版上的神人們幫我解釋一下到底是那段可以產生 亂數嗎T^T.... 因為我用Q2模擬不知是我不知如何模擬還是怎樣 他的值永遠就是0~9而不是亂跳....拜託版上的大大了 library ieee; use ieee.std_logic_1164.all; entity random_mode9 is port( clk :in std_logic; rst :in std_logic; sel :in std_logic; q:out std_logic_vector(3 downto 0) ); end random_mode9; architecture a of random_mode9 is type state_type is (S0,S1,S2,S3,S4,S5,S6,S7,S8,S9); signal state: state_type; signal qt: std_logic_vector(3 downto 0); signal d, d0, d1: std_logic; signal run : std_logic := '0'; begin process(clk) 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; end process; d <= d1 and not d0; with state select qt <= "0000" when S0, "0001" when S1, "0010" when S2, "0011" when S3, "0100" when S4, "0101" when S5, "0110" when S6, "0111" when S7, "1000" when S8, "1001" when S9; process(d, clk) begin if clk'event and clk='1' then q<=qt; if (d='1') then run <= not run; end if; end if; end process; end a; -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.124.137.45

12/27 14:21, , 1F
看起來是用人工去輸入SEL的不定時間來RANDON的
12/27 14:21, 1F

12/27 14:22, , 2F
硬體本身只是個CNT SEL準位變換第一次跑 第二次停
12/27 14:22, 2F

12/27 14:24, , 3F
所以如果SEL是接到按鍵的話 壓下去CNT跑 放開停
12/27 14:24, 3F

12/27 14:26, , 4F
而這個時間對人去按按鍵而言每次都會不一樣(除非剛好)
12/27 14:26, 4F
文章代碼(AID): #1BDcHrFY (Electronics)