以下的code為範例
1.正確版的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | architecture read_mod of RAM is type ram_array is array (0 to 2**AddressLineSize-1) of std_logic_vector(DataLineSize-1 downto 0); signal mem: ram_array; begin p0 : process( clock) begin if rising_edge(clock) then if Write_en='1' then mem(to_integer(unsigned(Write_Adr)))<=Write_Data; elsif Write_en='0' then Read_Data <= mem(to_integer(unsigned(Read_Adr))); end if ; end if; end process ; end read_mod ; -- read_mod |
2.錯誤版的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | architecture read_mod of RAM is type ram_array is array (0 to 2**AddressLineSize-1) of std_logic_vector(DataLineSize-1 downto 0); signal mem: ram_array; begin p0 : process( clock) begin if rising_edge(clock) and Write_en='1' then mem(to_integer(unsigned(Write_Adr)))<=Write_Data; elsif rising_edge(clock)and Write_en='0' then Read_Data <= mem(to_integer(unsigned(Read_Adr))); end if ; end process ; end read_mod ; -- read_mod |
相當於取了兩次clock'EVENT,貌似因為在取clock'EVENT,這個值會
被unset,造成第二次取值產生非預期的結果,不知道是不是我理解錯誤,
可以希望知道真正原因的大大可以跟我補充解釋 謝謝
0 意見:
張貼留言