---系统时钟clk为20MHZ,FPGA为EP4CE15E22C8,环境为quartus10.1。
--问题现象:要将sv_reg_01到sv_reg_06的数据保存到外部存储器中,
---但是sv_reg_01,sv_reg_012,sv_reg_03,sv_reg_04的数据有时出现错误,而sv_reg_05和
---sv_reg_06不出现错误。
---我将sv_reg_05和sv_reg_06写成立即数主要是为了对比一下。
--发现错误是依据从存储器读出的数据来判断的,对存储器的读写我已经验证过,没有错误。
---比如sv_cj_times_sum上一次的数据为100,下一次写的应当为101,但是这时偶然会变为别的数据如1923。
---对存储器写的时间少于cj_times_sum_标志寄存器的脉冲周期。
----部分程序如下
signal cj_times_sum_clr:std_logic;
signal cj_times_sum_标志寄存器:std_logic;
signal cj_times_sum:std_logic_vector(31 downto 0);
signal sv_cj_times_sum:std_logic_vector(31 downto 0);
signal cj_clk_标志寄存器_1:std_logic;
signal cj_clk_标志寄存器_2:std_logic;
signal cj_clk_标志寄存器:std_logic;
signal sv_reg_01:std_logic_vector(7 downto 0);
signal sv_reg_02:std_logic_vector(7 downto 0);
signal sv_reg_03:std_logic_vector(7 downto 0);
signal sv_reg_04:std_logic_vector(7 downto 0);
signal sv_reg_05:std_logic_vector(7 downto 0);
signal sv_reg_06:std_logic_vector(7 downto 0);
------------------------------------------------
-----------计数器进程-----------------------------
----cj_times_sum_标志寄存器高电平维持1个clk
process(clk)
begin
if(clk'event and clk='1') then
if(cj_times_sum_clr='1')
cj_times_sum <= (others=>'0');
elsif(cj_times_sum_标志寄存器='1')then
cj_times_sum <= cj_times_sum + 1;
end if;
end if;
end if;
end process;
--------------------------------------
--------------------------------
process(clk)
begin
if(clk'event and clk='1') then
cj_clk_标志寄存器_1 <= cj_times_sum_标志寄存器;
cj_clk_标志寄存器_2 <= cj_clk_标志寄存器_1;
cj_clk_标志寄存器 <= cj_clk_标志寄存器_2;
sv_data_标志寄存器 <= cj_clk_标志寄存器;
end if;
end process;
--------------------------------------
-------数据采集进程-------------------
-------其中cj_clk_标志寄存器宽度维持1个clk--------
process(clk)
begin
if(clk'event and clk='1') then
if((cj_clk_标志寄存器='1')
cj_load_data_标志寄存器 <= '1';
sv_cj_times_sum <= cj_times_sum;
elsif(cj_load_data_标志寄存器_clr='1') then
cj_load_data_标志寄存器 <= '0';
else
cj_load_data_标志寄存器 <= cj_load_data_标志寄存器;
end if;
end if;
end process;
---------------------------------------------
-----------------------------------------------
---保存数据的进程--------------
---其中sv_data_标志寄存器高电平维持1个clk
process(clk)
begin
if(clk'event and clk='1')then
if(sv_data_标志寄存器='1')then
sv_reg_01 <= sv_cj_times_sum(31 downto 24);
sv_reg_02 <= sv_cj_times_sum(23 downto 16);
sv_reg_03 <= sv_cj_times_sum(15 downto 8);
sv_reg_04 <= sv_cj_times_sum(7 downto 0);
sv_reg_05 <= "01010101"; --55H
sv_reg_06 <= "10101010"; --AAH
end if;
end if;
end process; |