Commit 289c8e93 authored by Evangelia Gousiou's avatar Evangelia Gousiou

correction on glitch filter test; added two more tests of glitch filter with TTL bar

parent 198e95b5
......@@ -81,14 +81,18 @@ architecture behav of testbench is
signal sscl, ssda : std_logic_vector(C_NR_SLAVES-1 downto 0);
signal scl, sda : std_logic;
signal rst_copm : std_logic;
signal rst_copm, rst_cnt : std_logic := '0';
type cnt_ch_array is array (C_NR_CHANS-1 downto 0) of integer;
signal fp_rp_same, fp_rp_oppos : cnt_ch_array;
signal in_out_oppos, in_out_same : cnt_ch_array;
signal pulse_cnt_ttl, pulse_cnt_rs485 : cnt_ch_array;
signal inv_err : cnt_ch_array;
signal fp_rp_same_err : cnt_ch_array;
signal fp_rp_oppos_err : cnt_ch_array;
signal in_out_oppos_err : cnt_ch_array;
signal in_out_same_err : cnt_ch_array;
signal pulse_cnt_ttl, pulse_cnt_rs485: cnt_ch_array;
signal inv_err : cnt_ch_array;
signal test_id : string(7 downto 1);
type cnt_inv_ch_array is array (C_NR_INV_CHANS-1 downto 0) of integer;
type cnt_inv_ch_array is array (C_NR_INV_CHANS-1 downto 0) of integer;
--==============================================================================
......@@ -270,32 +274,32 @@ begin
--============================================================================
-- Check if ttl_out matches rs485_out
-- Check if TTL_out, TTL_IN and RS485 match or are opposite
--============================================================================
compare_front_rear_pulses: process (clk_125)
begin
if rising_edge (clk_125) then
if vme_sysreset_n = '0' or rst_copm = '1' then
fp_rp_same <= (others=> (0));
fp_rp_oppos <= (others=> (0));
in_out_same <= (others=> (0));
in_out_oppos <= (others=> (0));
fp_rp_same_err <= (others=> (0));
fp_rp_oppos_err <= (others=> (0));
in_out_same_err <= (others=> (0));
in_out_oppos_err <= (others=> (0));
else
for i in 0 to C_NR_CHANS-1 loop
for i in 0 to C_NR_CHANS-1 loop -- loop: 7 channels
if ttl_out(i) /= rs485_out(i) then
fp_rp_same(i) <= fp_rp_same(i)+1;
fp_rp_same_err(i) <= fp_rp_same_err(i)+1;
end if;
if ttl_out(i) /= not rs485_out(i) then
fp_rp_oppos(i) <= fp_rp_oppos(i)+1;
fp_rp_oppos_err(i) <= fp_rp_oppos_err(i)+1;
end if;
if ttl_out(i) /= not ttl_n_in(i) then
in_out_oppos(i) <= in_out_oppos(i)+1;
in_out_oppos_err(i) <= in_out_oppos_err(i)+1;
end if;
if ttl_out(i) /= ttl_n_in(i) then
in_out_same(i) <= in_out_same(i)+1;
in_out_same_err(i) <= in_out_same_err(i)+1;
end if;
end loop;
......@@ -303,8 +307,9 @@ begin
end if;
end process;
--============================================================================
-- Check INV channels
-- Check INV channels
--============================================================================
compare_inv_i_inv_o: process (clk_125)
begin
......@@ -312,7 +317,7 @@ begin
if vme_sysreset_n = '0' then
inv_err <= (others=> (0));
else
for i in 0 to C_NR_INV_CHANS-1 loop
for i in 0 to C_NR_INV_CHANS-1 loop -- loop: 4 INV channels
if inv_n_in(i) /= inv_out(i) then
inv_err(i) <= inv_err(i)+1;
end if;
......@@ -321,40 +326,40 @@ begin
end if;
end process;
--============================================================================
-- pulse counter
--============================================================================
pulse_counter_ttl: process (ttl_out)
pulse_counter_ttl: process (ttl_out, vme_sysreset_n, rst_cnt)
begin
if vme_sysreset_n = '0' then
if vme_sysreset_n = '0' or rst_cnt = '1' then
pulse_cnt_ttl <= (others=> (0));
end if;
else
--for i in 0 to C_NR_CHANS-1 loop
if rising_edge(ttl_out(0)) then
pulse_cnt_ttl(0) <= pulse_cnt_ttl(0) +1;
end if;
if rising_edge(ttl_out(1)) then
pulse_cnt_ttl(1) <= pulse_cnt_ttl(1) +1;
end if;
if rising_edge(ttl_out(2)) then
pulse_cnt_ttl(2) <= pulse_cnt_ttl(2) +1;
end if;
if rising_edge(ttl_out(3)) then
pulse_cnt_ttl(3) <= pulse_cnt_ttl(3) +1;
end if;
if rising_edge(ttl_out(4)) then
pulse_cnt_ttl(4) <= pulse_cnt_ttl(4) +1;
end if;
if rising_edge(ttl_out(5)) then
pulse_cnt_ttl(5) <= pulse_cnt_ttl(5) +1;
end if;
if rising_edge(ttl_out(0)) then
pulse_cnt_ttl(0) <= pulse_cnt_ttl(0) +1;
end if;
if rising_edge(ttl_out(1)) then
pulse_cnt_ttl(1) <= pulse_cnt_ttl(1) +1;
end if;
if rising_edge(ttl_out(2)) then
pulse_cnt_ttl(2) <= pulse_cnt_ttl(2) +1;
end if;
if rising_edge(ttl_out(3)) then
pulse_cnt_ttl(3) <= pulse_cnt_ttl(3) +1;
end if;
if rising_edge(ttl_out(4)) then
pulse_cnt_ttl(4) <= pulse_cnt_ttl(4) +1;
end if;
if rising_edge(ttl_out(5)) then
pulse_cnt_ttl(5) <= pulse_cnt_ttl(5) +1;
end if;
--end loop;
end if;
end process pulse_counter_ttl;
pulse_counter_rs485: process (rs485_out)
begin
if vme_sysreset_n = '0' then
if vme_sysreset_n = '0' or rst_cnt = '1' then
pulse_cnt_rs485 <= (others=> (0));
end if;
--for i in 0 to C_NR_CHANS-1 loop
......@@ -394,6 +399,7 @@ begin
variable nb_pulses_to_send_bar : integer := 6;
variable glitch_filter_en : std_logic := '0'; -- glitch filter disabled
variable ttl_out_bar_en : std_logic := '0'; -- TTLbar disabled
variable rtm : std_logic_vector(5 downto 0) := C_NO_RTM;
variable err_cnt, err : integer := 0;
variable time_intrvl, rst_timetag : integer := 0;
variable pulse_timetag : integer := 0;
......@@ -408,7 +414,7 @@ begin
-- Board settings
print_now("----------------------------------------------------------------");
print_now("---> Configure board settings");
settings_config (glitch_filter_en, ttl_out_bar_en, sw_gp_n_in, sw_other_in, pcbrev, rtm_in);
settings_config (glitch_filter_en, ttl_out_bar_en, rtm, sw_gp_n_in, sw_other_in, pcbrev, rtm_in);
---------------------------------------------------------------------------
-- VME reset
......@@ -423,6 +429,7 @@ begin
---------------------------------------------------------------------------
-- I2C readings
test_id <= "TEST 1 ";
print_now("----------------------------------------------------------------");
print_now("---> Test 01: I2C reg reading");
print_now("----------------------------------------------------------------");
......@@ -437,6 +444,7 @@ begin
---------------------------------------------------------------------------
-- I2C writing
test_id <= "TEST 2 ";
print_now("----------------------------------------------------------------");
print_now("---> Test 02: I2C reg writing");
print_now("----------------------------------------------------------------");
......@@ -451,6 +459,7 @@ begin
---------------------------------------------------------------------------
-- Pulses to the front TTL input
test_id <= "TEST 3 ";
print_now("----------------------------------------------------------------");
print_now("---> Test 03: Sending TTL pulses and checking the outputs");
print_now("----------------------------------------------------------------");
......@@ -471,7 +480,7 @@ begin
-- Check if TTL_N_IN out and TTL_O out are opposite
print_now("Check that TTL_O(0) is the inverted TTL_N_IN(0)");
if in_out_oppos(0) = 0 then
if in_out_oppos_err(0) = 0 then
print_now("[OK] TTL_O(0) is exactly the inverted TTL_N_IN(0)");
else
print_now("[ERR] TTL_O(0) is not exactly the inverted TTL_N_IN(0)");
......@@ -480,7 +489,7 @@ begin
-- Check if TTL out and RS485 out are the same
print_now("Check that the pulses arrived to the RS485_O(0)");
if fp_rp_same(0) = 0 then
if fp_rp_same_err(0) = 0 then
print_now("[OK] RS485_O(0) matches TTL_O(0)");
else
print_now("[ERR] RS485_O(0) does not match TTL_O(0)");
......@@ -492,6 +501,7 @@ begin
---------------------------------------------------------------------------
-- Counters reading
test_id <= "TEST 4 ";
print_now("----------------------------------------------------------------");
print_now("---> Test 04: Reading of the pulse counters through I2C");
print_now("----------------------------------------------------------------");
......@@ -536,6 +546,7 @@ begin
---------------------------------------------------------------------------
-- Pulses to the rear RS485 input
test_id <= "TEST 5 ";
print_now("----------------------------------------------------------------");
print_now("---> Test 05: Sending pulses to the RS485 and checking the outputs");
print_now("----------------------------------------------------------------");
......@@ -558,7 +569,7 @@ begin
-- Check if TTL out and RS485 out are the same
print_now("Check that the pulses arrived to the TTL_O(0)");
if fp_rp_same(0) = 0 then
if fp_rp_same_err(0) = 0 then
print_now("[OK] RS485_O(0) matches TTL_O(0)");
else
print_now("[ERR] RS485_O(0) does not match TTL_O(0)");
......@@ -570,6 +581,7 @@ begin
---------------------------------------------------------------------------
-- Counters reading
test_id <= "TEST 6 ";
print_now("----------------------------------------------------------------");
print_now("---> Test 06: Reading of the pulse counters through I2C");
print_now("----------------------------------------------------------------");
......@@ -594,6 +606,7 @@ begin
---------------------------------------------------------------------------
-- Timetag reading
test_id <= "TEST 7 ";
print_now("----------------------------------------------------------------");
print_now("---> Test 07: Reading of the timetag register through I2C");
print_now("----------------------------------------------------------------");
......@@ -616,6 +629,7 @@ begin
---------------------------------------------------------------------------
-- INV channels
test_id <= "TEST 8 ";
print_now("----------------------------------------------------------------");
print_now("---> Test 08: INV channel check");
print_now("----------------------------------------------------------------");
......@@ -637,6 +651,7 @@ begin
---------------------------------------------------------------------------
-- Glitch filter test
test_id <= "TEST 9 ";
print_now("----------------------------------------------------------------");
print_now("---> Test 09: Test Glitch filter");
print_now("----------------------------------------------------------------");
......@@ -645,10 +660,10 @@ begin
print_now("---> Configure board settings");
glitch_filter_en := '1';
ttl_out_bar_en := '0';
settings_config (glitch_filter_en, ttl_out_bar_en, sw_gp_n_in, sw_other_in, pcbrev, rtm_in);
settings_config (glitch_filter_en, ttl_out_bar_en, rtm, sw_gp_n_in, sw_other_in, pcbrev, rtm_in);
wait for 2 us; -- ML: does not work without this wait, no idea way?
print_now_s_i("Sending pulses 50ns-long each to TTL_N_I(3): ", nb_pulses_to_send_fp);
generate_pulse (ttl_n_in(3), nb_pulses_to_send_fp, "fp", rs485_fs_n_in(3), 50ns, 20ns);
generate_pulse (ttl_n_in(3), nb_pulses_to_send_fp, "fp", rs485_fs_n_in(3), 50ns, 50ns);
-- Checking if any pulse was passed to the output
print_now("Check that the glitches were filtered and there is no pulse in the TTL_O(3) output");
......@@ -664,6 +679,7 @@ begin
---------------------------------------------------------------------------
-- TTL bar test
test_id <= "TEST 10";
print_now("----------------------------------------------------------------");
print_now("---> Test 10: Test TTL BAR");
print_now("----------------------------------------------------------------");
......@@ -672,16 +688,16 @@ begin
print_now("---> Configure board settings");
glitch_filter_en := '0';
ttl_out_bar_en := '1';
settings_config (glitch_filter_en, ttl_out_bar_en, sw_gp_n_in, sw_other_in, pcbrev, rtm_in);
settings_config (glitch_filter_en, ttl_out_bar_en, rtm, sw_gp_n_in, sw_other_in, pcbrev, rtm_in);
rst_copm <= '1';
wait for 2 us; -- ML: does not work without this wait, no idea way?
rst_copm <= '0';
generate_pulse (ttl_n_in(5), nb_pulses_to_send_bar, "fp", rs485_fs_n_in(5), 200ns, 200ns);
-- Check if TTL_N_IN out and TTL_O out are the same
-- Check if TTL_N_IN is the opposite of TTL_O; Note: TTLbar does not invert the output!
print_now("Check that TTL_O(5) matches TTL_N_IN(5)");
if in_out_same(5) = 0 then
if in_out_oppos_err(5) = 0 then
print_now("[OK] TTL_O(5) matches TTL_N_IN(5)");
else
print_now("[ERR] TTL_O(5) does not match TTL_N_IN(5)");
......@@ -693,6 +709,110 @@ begin
---------------------------------------------------------------------------
-- Glitch filter enabled with TTL bar test
test_id <= "TEST 11";
print_now("----------------------------------------------------------------");
print_now("---> Test 11: Test glitch filter enabled with TTL BAR");
print_now("----------------------------------------------------------------");
---------------------------------------------------------------------------
-- Change board settings
print_now("---> Configure board settings");
glitch_filter_en := '1';
ttl_out_bar_en := '1';
nb_pulses_to_send_bar := 2;
settings_config (glitch_filter_en, ttl_out_bar_en, rtm, sw_gp_n_in, sw_other_in, pcbrev, rtm_in);
rst_copm <= '1';
rst_cnt <= '1';
wait for 2 us; -- ML: does not work without this wait, no idea way?
rst_copm <= '0';
rst_cnt <= '0';
-- create a 50ns glitch during a 450ns pulse: ------|____|-|____|------
generate_pulse (ttl_n_in(5), nb_pulses_to_send_bar, "fp", rs485_fs_n_in(5), 200ns, 50ns);
-- Checking that a single pulse passed to the output
print_now("Check that the 50ns glitch within the 450ns pulse was filtered out and a single 450ns pulse arrived to the output");
if pulse_cnt_ttl(5) = 1 then
print_now("[OK] Glitch filter filtered the glitch");
else
print_now_s_i("[ERR] Number of pulses measured at TTL_O(5): ",pulse_cnt_ttl(5));
err_cnt := err_cnt + 1;
end if;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- Glitch filter disabled with TTL bar testt
test_id <= "TEST 12";
print_now("----------------------------------------------------------------");
print_now("---> Test 12: Test glitch filter disable with TTL BAR");
print_now("----------------------------------------------------------------");
---------------------------------------------------------------------------
-- Change board settings
print_now("---> Configure board settings");
glitch_filter_en := '0';
ttl_out_bar_en := '1';
nb_pulses_to_send_bar := 2;
settings_config (glitch_filter_en, ttl_out_bar_en, rtm, sw_gp_n_in, sw_other_in, pcbrev, rtm_in);
rst_copm <= '1';
rst_cnt <= '1';
wait for 2 us; -- ML: does not work without this wait, no idea way?
rst_copm <= '0';
rst_cnt <= '0';
-- create a 50ns glitch during a 450ns pulse: ------|____|-|____|------
generate_pulse (ttl_n_in(5), nb_pulses_to_send_bar, "fp", rs485_fs_n_in(5), 200ns, 50ns);
-- Checking that the glitch passed to the output
print_now("Check that the 50ns glitch within the 450ns pulse passed to the output");
if pulse_cnt_ttl(5) = 2 then
print_now("[OK] Glitch filter correctly disabled");
else
print_now_s_i("[ERR] Number of pulses measured at TTL_O(5): ",pulse_cnt_ttl(5));
err_cnt := err_cnt + 1;
end if;
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
-- DB9 RTM test
test_id <= "TEST 13";
print_now("----------------------------------------------------------------");
print_now("---> Test 13: Test RS485 outputs with DB9 RTM");
print_now("----------------------------------------------------------------");
---------------------------------------------------------------------------
-- Change board settings
print_now("---> Configure board settings");
glitch_filter_en := '0';
ttl_out_bar_en := '0';
nb_pulses_to_send_fp := 2;
rtm := C_RTM_DB9;
settings_config (glitch_filter_en, ttl_out_bar_en, rtm, sw_gp_n_in, sw_other_in, pcbrev, rtm_in);
rst_copm <= '1';
rst_cnt <= '1';
wait for 2 us; -- ML: does not work without this wait, no idea way?
rst_copm <= '0';
rst_cnt <= '0';
-- generate pulses
generate_pulse (ttl_n_in(1), nb_pulses_to_send_fp, "fp", rs485_fs_n_in(1), 200ns, 200ns);
-- Checking that a single pulse passed to the output
---------------------------------------------------------------------------
print_now_s_i("Errors so far: ", err_cnt);
---------------------------------------------------------------------------
print("*****************************************************************************");
print(" Tests Summary");
print("*****************************************************************************");
......
......@@ -47,7 +47,8 @@ package testbench_pkg is
constant C_NR_MASTERS : positive := 1;
constant C_NR_SLAVES : positive := 1;
constant C_RTM : std_logic_vector(5 downto 0) := "010101";
constant C_NO_RTM : std_logic_vector(5 downto 0) := "000000";
constant C_RTM_DB9 : std_logic_vector(5 downto 0) := "000101";
constant C_INITIAL_TST_VALUE : std_logic_vector(31 downto 0) := x"FFFFFFF0";
constant C_I2C_MASTER_SLV_ADDR: std_logic_vector(6 downto 0) := "1011110";
......@@ -259,6 +260,7 @@ end component conv_ttl_rs485;
procedure settings_config (constant glitch_filter_en : in std_logic;
constant ttl_out_bar_en : in std_logic;
constant rtm_value : in std_logic_vector(5 downto 0);
signal sw_gp_n : out std_logic_vector(7 downto 0);
signal sw_other : out std_logic_vector(31 downto 0);
signal pcbrev : out std_logic_vector(5 downto 0);
......@@ -297,23 +299,30 @@ package body testbench_pkg is
--==================================================================================================
procedure settings_config (constant glitch_filter_en : in std_logic;
constant ttl_out_bar_en : in std_logic;
signal sw_gp_n : out std_logic_vector(7 downto 0);
signal sw_other : out std_logic_vector(31 downto 0);
signal pcbrev : out std_logic_vector(5 downto 0);
signal rtm : out std_logic_vector(5 downto 0)) is
constant rtm_value : in std_logic_vector(5 downto 0);
signal sw_gp_n : out std_logic_vector(7 downto 0);
signal sw_other : out std_logic_vector(31 downto 0);
signal pcbrev : out std_logic_vector(5 downto 0);
signal rtm : out std_logic_vector(5 downto 0)) is
begin
sw_gp_n(0) <= not glitch_filter_en;
if glitch_filter_en = '1' then
print_now("Glitch filter enabled");
print_now("- Glitch filter enabled");
else
print_now("Glitch filter disabled");
print_now("- Glitch filter disabled");
end if;
sw_gp_n(7) <= ttl_out_bar_en;
if ttl_out_bar_en = '1' then
print_now("TTL output BAR enabled");
print_now("- TTL output BAR enabled");
else
print_now("- TTL output BAR disabled");
end if;
if rtm_value = C_RTM_DB9 then
print_now("- DB9 RTM plugged in");
else
print_now("TTL output BAR disabled");
print_now("- No particular RTM");
end if;
--print_now_s_std("RTMP & RTMM set to x", C_RTM);
......@@ -321,7 +330,9 @@ package body testbench_pkg is
sw_gp_n(6 downto 1) <= (others => '0'); -- not used
sw_other <= (others => '0'); -- not used
pcbrev <= "111100"; -- not used
rtm <= C_RTM; -- not used
rtm <= rtm_value;
end procedure;
----------------------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment