entity PulseDurationDetector is
Generic
(
g_CLK_FREQ_MHZ : integer := 100;
g_OUT1_THR_LOW_US : integer := 9;
g_OUT1_THR_HIGH_US : integer := 11;
g_OUT2_THR_LOW_US : integer := 19;
g_OUT2_THR_HIGH_US : integer := 21;
g_OUT_DURATION_US : integer := 2
);
Port
(
i_CLK : in std_logic;
i_Pulse : in std_logic;
o_Out1 : out std_logic := '0';
o_Out2 : out std_logic := '0'
);
end PulseDurationDetector;
architecture Behavioral of PulseDurationDetector is
constant c_OUT1_THR_LOW_CLK : integer := g_OUT1_THR_LOW_US*g_CLK_FREQ_MHZ;
constant c_OUT1_THR_HIGH_CLK : integer := g_OUT1_THR_HIGH_US*g_CLK_FREQ_MHZ;
constant c_OUT2_THR_LOW_CLK : integer := g_OUT2_THR_LOW_US*g_CLK_FREQ_MHZ;
constant c_OUT2_THR_HIGH_CLK : integer := g_OUT2_THR_HIGH_US*g_CLK_FREQ_MHZ;
constant c_OUT_DURATION_CLK : integer := g_OUT_DURATION_US*g_CLK_FREQ_MHZ;
constant c_PDD_State_Idle : integer := 0;
constant c_PDD_State_1 : integer := 1;
constant c_PDD_State_2 : integer := 2;
constant c_PDD_State_3 : integer := 3;
constant c_PDD_State_4 : integer := 4;
signal s_Pulse : std_logic := '0';
signal s_Pulse_old : std_logic := '0';
signal s_PDD_cnt : integer range 0 to c_OUT1_THR_HIGH_CLK+c_OUT2_THR_HIGH_CLK := 0;
signal s_PDD_out_cnt : integer range 0 to c_OUT_DURATION_CLK+1 := 0;
signal st_PDD_State : integer range 0 to 5 := c_PDD_State_Idle;
begin
process(i_clk)
begin
if rising_edge(i_clk) then
s_Pulse <= i_Pulse;
s_Pulse_old <= s_Pulse;
case st_PDD_State is
when c_PDD_State_Idle =>
s_PDD_cnt <= 0;
if(s_Pulse_old = '0' and s_Pulse = '1') then
st_PDD_State <= c_PDD_State_1;
end if;
when c_PDD_State_1 =>
s_PDD_cnt <= s_PDD_cnt + 1;
if(s_Pulse_old = '1' and s_Pulse = '0') then
st_PDD_State <= c_PDD_State_2;
end if;
when c_PDD_State_2 =>
if(s_PDD_cnt >= c_OUT1_THR_LOW_CLK and s_PDD_cnt <= c_OUT1_THR_HIGH_CLK) then
st_PDD_State <= c_PDD_State_3;
s_PDD_cnt <= 0;
s_PDD_out_cnt <= 0;
elsif(s_PDD_cnt >= c_OUT2_THR_LOW_CLK and s_PDD_cnt <= c_OUT2_THR_HIGH_CLK) then
st_PDD_State <= c_PDD_State_4;
s_PDD_cnt <= 0;
s_PDD_out_cnt <= 0;
else
st_PDD_State <= c_PDD_State_Idle;
s_PDD_cnt <= 0;
end if;
when c_PDD_State_3 =>
if(s_PDD_out_cnt <= 200) then
s_PDD_out_cnt <= s_PDD_out_cnt + 1;
o_Out1 <= '1';
else
st_PDD_State <= c_PDD_State_Idle;
s_PDD_out_cnt <= 0;
o_Out1 <= '0';
end if;
when c_PDD_State_4 =>
if(s_PDD_out_cnt <= 200) then
s_PDD_out_cnt <= s_PDD_out_cnt + 1;
o_Out2 <= '1';
else
st_PDD_State <= c_PDD_State_Idle;
s_PDD_out_cnt <= 0;
o_Out2 <= '0';
end if;
when others =>
st_PDD_State <= c_PDD_State_Idle;
s_PDD_cnt <= 0;
end case;
end if;
end process;
end Behavioral;