LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all; --必须声明这个包集才能使用Signed和Unsigned
USE ieee.std_logic_signed.all;
USE ieee.std_logic_unsigned.all;
ENTITY OC_ERR IS
PORT(
Reset : IN STD_LOGIC; --全局复位
Clk : IN STD_LOGIC; --全局时钟
CPUCS : IN STD_LOGIC; --CPU片选
CpuWr : IN STD_LOGIC; --CPU写信号
CpuData : IN STD_LOGIC_VECTOR(15 downto 0); --CPU数据线
AD1Data : IN STD_LOGIC_VECTOR(15 downto 0); --AD采样数据
AD2Data : IN STD_LOGIC_VECTOR(15 downto 0); --AD采样数据
AD3Data : IN STD_LOGIC_VECTOR(15 downto 0); --AD采样数据
A_Fault_Flag : OUT STD_LOGIC ; --故障标志
B_Fault_Flag : OUT STD_LOGIC ;
C_Fault_Flag : OUT STD_LOGIC
);
END OC_ERR;
ARCHITECTURE behave OF OC_ERR IS
SIGNAL A_Err_Cnt : STD_LOGIC_VECTOR(12 DOWNTO 0);
SIGNAL B_Err_Cnt : STD_LOGIC_VECTOR(12 DOWNTO 0);
SIGNAL C_Err_Cnt : STD_LOGIC_VECTOR(12 DOWNTO 0);
SIGNAL ProtectPara : SIGNED(15 DOWNTO 0);
SIGNAL ProtectPara_BackUp : SIGNED(15 DOWNTO 0);
SIGNAL ProtectParaUpper : SIGNED(15 DOWNTO 0);
SIGNAL ProtectParaLow : SIGNED(15 DOWNTO 0);
SIGNAL ADDataBuff1 : SIGNED(15 DOWNTO 0);
SIGNAL ADDataBuff2 : SIGNED(15 DOWNTO 0);
SIGNAL ADDataBuff3 : SIGNED(15 DOWNTO 0);
SIGNAL A_Err_Flag_Buff : STD_LOGIC;
SIGNAL B_Err_Flag_Buff : STD_LOGIC;
SIGNAL C_Err_Flag_Buff : STD_LOGIC;
SIGNAL cpuwr_r1 : STD_LOGIC;
SIGNAL cpuwr_r2 : STD_LOGIC;
BEGIN
----------------------------------------------------------------------
-- 从CPU获取保护值
-- -------------------------------------------------------------------
Delay_Proc:process(Reset,Clk)
begin
if (Reset='0') then
cpuwr_r1 <= '0';
cpuwr_r2 <= '0';
ProtectPara <= x"7530"; --默认30000;
ProtectPara_BackUp<= x"7530"; --默认30000;
ProtectParaUpper <= (others=>'0');
ProtectParaLow <= (others=>'0');
ADDataBuff1<=(others=>'0');
ADDataBuff2<=(others=>'0');
ADDataBuff3<=(others=>'0');
ELSIF RISING_EDGE(Clk) THEN
--------------------------CPU写信号两次同步----------------
cpuwr_r1 <= CpuWr;
cpuwr_r2 <= cpuwr_r1;
ProtectPara_BackUp<= x"7530"; --默认30000;
--------------------------数据处理-----------------------
if ((CPUCS='1') and (cpuwr_r2='1') and (cpuwr_r1='0')) then
ProtectPara <= SIGNED(CpuData); --获取保护值
end if;