signal tx_data_m, tx_data_s, rx_data_m, rx_data_s : std_logic_vector(7 downto 0);
 signal tx_k_m, tx_k_s, rx_k_m, rx_k_s : std_logic;
 
-signal do_once : std_logic := '0';
+signal do_once : std_logic_vector(1 downto 0) := "00";
 
 begin
 
 
 process (tx_data_m)
 begin
-  if (tx_data_m = x"11" and do_once = '0') then
-    rx_data_s(7 downto 1) <= transport tx_data_m(7 downto 1) after 250 ns;
-    rx_data_s(0) <= transport '0' after 250 ns;
-    do_once <= '1';
+  if (tx_data_m = x"11") then
+    rx_k_s <= transport tx_k_m after 250 ns;
+    rx_data_s <= transport tx_data_m after 250 ns;
+    if do_once = "00" then
+      rx_data_s(7 downto 1) <= transport tx_data_m(7 downto 1) after 250 ns;
+      rx_data_s(0) <= transport '0' after 250 ns;
+
+      --rx_k_s <= transport (not tx_k_m) after 250 ns;
+      do_once <= "01"; --2 errors, one good
+      --do_once <= "10";  --1 error, 2 good
+    elsif do_once = "01" then
+      rx_data_s(7 downto 1) <= transport tx_data_m(7 downto 1) after 250 ns;
+      rx_data_s(0) <= transport '0' after 250 ns;
+      do_once <= "10";
+    elsif do_once = "10" then
+      do_once <= "11";
+      rx_data_s <= transport tx_data_m after 250 ns;
+    else
+      do_once <= "00";
+      rx_data_s <= transport tx_data_m after 250 ns;
+    end if;
   else
+    rx_k_s    <= transport tx_k_m after 250 ns; 
     rx_data_s <= transport tx_data_m after 250 ns;
   end if;
 end process;
 
 rx_data_m <= transport tx_data_s after 250 ns;
-rx_k_s    <= transport tx_k_m after 250 ns;
+
 rx_k_m    <= transport tx_k_s after 250 ns;
 
 clk_100_m <= not clk_100_m after 5 ns;
 clk_200_m <= not clk_200_m after 2.5 ns;
-clk_100_s <= not clk_100_s after 5 ns;
-clk_200_s <= not clk_200_s after 2.5 ns;
-
-
+--clk_100_s <= not clk_100_s after 5 ns;
+--clk_100_s <= not clk_100_s after 5.1 ns;
+clk_100_s <= not clk_100_s after 4.8 ns;
+--clk_200_s <= not clk_200_s after 2.5 ns;
+--clk_200_s <= not clk_200_s after 2.55 ns;
+clk_200_s <= not clk_200_s after 2.4 ns;
 
 
 process begin
   wait for 30 us;
 
   -- generate good packages to test the RAM overflow
-  GEN_GOOD: for i in 0 to 3 loop
+  --GEN_GOOD: for i in 0 to 3 loop
+  GEN_GOOD: for i in 0 to 0 loop
   wait until rising_edge(clk_100_m); wait for 1 ns;
   int2med_m.data <= x"0001";
   int2med_m.packet_num <= "100";
   int2med_m.data <= x"0000";
   end loop;
 
-  --bad package
-  --wait for 1 us;
+  GEN_BAD: for i in 0 to 2 loop
+  --bad packages
+  wait for 500ns;
   wait until rising_edge(clk_100_m); wait for 1 ns;
   int2med_m.data <= x"1122";
+  --int2med_m.data <= x"1111";  --for k flip
   int2med_m.packet_num <= "100";
   int2med_m.dataready <= '1';
   wait until rising_edge(clk_100_m); wait for 1 ns;
   wait until rising_edge(clk_100_m); wait for 1 ns;
   int2med_m.dataready <= '0';
   wait until rising_edge(clk_100_m); wait for 1 ns;
-  wait until rising_edge(clk_100_m); wait for 1 ns;
-  wait until rising_edge(clk_100_m); wait for 1 ns;
-  wait until rising_edge(clk_100_m); wait for 1 ns;
-  wait until rising_edge(clk_100_m); wait for 1 ns;
-  wait until rising_edge(clk_100_m); wait for 1 ns;
+  end loop;
+--  wait until rising_edge(clk_100_m); wait for 1 ns;
+--  wait until rising_edge(clk_100_m); wait for 1 ns;
+--  wait until rising_edge(clk_100_m); wait for 1 ns;
+--  wait until rising_edge(clk_100_m); wait for 1 ns;
+--  wait until rising_edge(clk_100_m); wait for 1 ns;
 
-  --good package which should be thrown away
+  --good package
   wait until rising_edge(clk_100_m); wait for 1 ns;
   int2med_m.data <= x"ff01";
   int2med_m.packet_num <= "100";