From cb7f45fd1d1566cb4fe4c535db8779b743e7ac1b Mon Sep 17 00:00:00 2001
From: Eric Kooistra <kooistra@astron.nl>
Date: Thu, 23 Feb 2023 20:31:21 +0100
Subject: [PATCH] Use different wg_ampl for sp_0 and sp_2 to distinguish them.

---
 .../tb_disturb2_unb2b_sdp_station_full_wg.vhd | 61 +++++++++++++------
 1 file changed, 42 insertions(+), 19 deletions(-)

diff --git a/applications/lofar2/designs/lofar2_unb2b_sdp_station/revisions/disturb2_unb2b_sdp_station_full_wg/tb_disturb2_unb2b_sdp_station_full_wg.vhd b/applications/lofar2/designs/lofar2_unb2b_sdp_station/revisions/disturb2_unb2b_sdp_station_full_wg/tb_disturb2_unb2b_sdp_station_full_wg.vhd
index 5a3f16b8e4..af09b265d0 100644
--- a/applications/lofar2/designs/lofar2_unb2b_sdp_station/revisions/disturb2_unb2b_sdp_station_full_wg/tb_disturb2_unb2b_sdp_station_full_wg.vhd
+++ b/applications/lofar2/designs/lofar2_unb2b_sdp_station/revisions/disturb2_unb2b_sdp_station_full_wg/tb_disturb2_unb2b_sdp_station_full_wg.vhd
@@ -102,7 +102,8 @@ ARCHITECTURE tb OF tb_disturb2_unb2b_sdp_station_full_wg IS
   CONSTANT c_bsn_start_wg         : NATURAL := 2;  -- start WG at this BSN to instead of some BSN, to avoid mismatches in exact expected data values
   -- . ampl
   CONSTANT c_beamlet_scale        : REAL := 1.0 / 2.0**8;
-  CONSTANT c_wg_ampl              : NATURAL := NATURAL(7.0 / c_beamlet_scale);  -- choose < 8.0 to have no beamlet output overflow with unit weights and unit beamlet scale
+  CONSTANT c_wg_ampl_sp_0         : NATURAL := NATURAL(7.0 / c_beamlet_scale);  -- choose < 8.0 to have no beamlet output overflow with unit weights and unit beamlet scale
+  CONSTANT c_wg_ampl_sp_2         : NATURAL := c_wg_ampl_sp_0 / 2;  -- use different ampl for sp_0 and sp_2 to distinghuis them
   -- . phase
   CONSTANT c_subband_phase        : REAL := 0.0;  -- wanted subband phase in degrees = WG phase at sop
   CONSTANT c_wg_latency           : INTEGER := c_diag_wg_latency - 0;  -- -0 to account for BSN scheduler start trigger latency
@@ -116,19 +117,24 @@ ARCHITECTURE tb OF tb_disturb2_unb2b_sdp_station_full_wg IS
   CONSTANT c_wg_phase_sp_2        : REAL := c_subband_phase + c_wg_phase_offset_sp_2;  -- WG phase in degrees
 
   -- WPFB, use default unit subband weights (= 1.0 + 0j)
-  CONSTANT c_subband_phase_offset : REAL := -90.0;  -- WG with zero phase sinus yields subband with -90 degrees phase (negative Im, zero Re)
-  CONSTANT c_exp_subband_ampl     : REAL := REAL(c_wg_ampl) * c_sdp_wpfb_subband_sp_ampl_ratio;
-  CONSTANT c_exp_subband_phase    : REAL := c_subband_phase + c_subband_phase_offset;
+  CONSTANT c_exp_subband_ampl_sp_0 : REAL := REAL(c_wg_ampl_sp_0) * c_sdp_wpfb_subband_sp_ampl_ratio;
+  CONSTANT c_exp_subband_ampl_sp_2 : REAL := REAL(c_wg_ampl_sp_2) * c_sdp_wpfb_subband_sp_ampl_ratio;
+
+  CONSTANT c_subband_phase_offset  : REAL := -90.0;  -- WG with zero phase sinus yields subband with -90 degrees phase (negative Im, zero Re)
+  CONSTANT c_exp_subband_phase     : REAL := c_subband_phase + c_subband_phase_offset;
 
   -- BF
   -- . use one active WG per subband, so beamlet_sum of one subband
   -- . use default unit BF weights (= 1.0 + 0j), so beamlet_sum = subband
   -- . use beamlet output = beamlet_sum * c_beamlet_scale
-  CONSTANT c_exp_beamlet_scale    : NATURAL := NATURAL(c_beamlet_scale * REAL(c_sdp_unit_beamlet_scale));  -- c_sdp_unit_beamlet_scale = 2**15;
-  CONSTANT c_exp_beamlet_ampl     : REAL := c_exp_subband_ampl * c_beamlet_scale;
-  CONSTANT c_exp_beamlet_phase    : REAL := c_exp_subband_phase;
-  CONSTANT c_exp_beamlet_re       : INTEGER := INTEGER(COMPLEX_RE(c_exp_beamlet_ampl, c_exp_beamlet_phase));
-  CONSTANT c_exp_beamlet_im       : INTEGER := INTEGER(COMPLEX_IM(c_exp_beamlet_ampl, c_exp_beamlet_phase));
+  CONSTANT c_exp_beamlet_scale     : NATURAL := NATURAL(c_beamlet_scale * REAL(c_sdp_unit_beamlet_scale));  -- c_sdp_unit_beamlet_scale = 2**15;
+  CONSTANT c_exp_beamlet_ampl_sp_0 : REAL := c_exp_subband_ampl_sp_0 * c_beamlet_scale;
+  CONSTANT c_exp_beamlet_ampl_sp_2 : REAL := c_exp_subband_ampl_sp_2 * c_beamlet_scale;
+  CONSTANT c_exp_beamlet_phase     : REAL := c_exp_subband_phase;
+  CONSTANT c_exp_beamlet_re_sp_0   : INTEGER := INTEGER(COMPLEX_RE(c_exp_beamlet_ampl_sp_0, c_exp_beamlet_phase));
+  CONSTANT c_exp_beamlet_re_sp_2   : INTEGER := INTEGER(COMPLEX_RE(c_exp_beamlet_ampl_sp_2, c_exp_beamlet_phase));
+  CONSTANT c_exp_beamlet_im_sp_0   : INTEGER := INTEGER(COMPLEX_IM(c_exp_beamlet_ampl_sp_0, c_exp_beamlet_phase));
+  CONSTANT c_exp_beamlet_im_sp_2   : INTEGER := INTEGER(COMPLEX_IM(c_exp_beamlet_ampl_sp_2, c_exp_beamlet_phase));
 
   CONSTANT c_exp_beamlet_index    : NATURAL := NATURAL(c_subband_sp_0) * c_sdp_N_pol;
   CONSTANT c_exp_beamlet_index_os : NATURAL := c_sdp_N_pol_bf * c_sdp_cep_nof_beamlets_per_block + NATURAL(ROUND(c_subband_sp_2)) * c_sdp_N_pol;
@@ -369,13 +375,13 @@ BEGIN
     mmf_mm_bus_wr(c_mm_file_reg_diag_wg, v_offset + 0, 1024*2**16 + 1, tb_clk);  -- nof_samples, mode calc
     mmf_mm_bus_wr(c_mm_file_reg_diag_wg, v_offset + 1, INTEGER(c_wg_phase_sp_0 * c_diag_wg_phase_unit), tb_clk);  -- phase offset in degrees
     mmf_mm_bus_wr(c_mm_file_reg_diag_wg, v_offset + 2, INTEGER(c_subband_sp_0 * c_sdp_wg_subband_freq_unit), tb_clk);  -- freq
-    mmf_mm_bus_wr(c_mm_file_reg_diag_wg, v_offset + 3, INTEGER(REAL(c_wg_ampl) * c_sdp_wg_ampl_lsb), tb_clk);  -- ampl
+    mmf_mm_bus_wr(c_mm_file_reg_diag_wg, v_offset + 3, INTEGER(REAL(c_wg_ampl_sp_0) * c_sdp_wg_ampl_lsb), tb_clk);  -- ampl
     -- WG at signal input 2
     v_offset := 2 * c_mm_span_reg_diag_wg;
     mmf_mm_bus_wr(c_mm_file_reg_diag_wg, v_offset + 0, 1024*2**16 + 1, tb_clk);  -- nof_samples, mode calc
     mmf_mm_bus_wr(c_mm_file_reg_diag_wg, v_offset + 1, INTEGER(c_wg_phase_sp_2 * c_diag_wg_phase_unit), tb_clk);  -- phase offset in degrees
     mmf_mm_bus_wr(c_mm_file_reg_diag_wg, v_offset + 2, INTEGER(c_subband_sp_2 * c_sdp_wg_subband_freq_unit), tb_clk);  -- freq
-    mmf_mm_bus_wr(c_mm_file_reg_diag_wg, v_offset + 3, INTEGER(REAL(c_wg_ampl) * c_sdp_wg_ampl_lsb), tb_clk);  -- ampl
+    mmf_mm_bus_wr(c_mm_file_reg_diag_wg, v_offset + 3, INTEGER(REAL(c_wg_ampl_sp_2) * c_sdp_wg_ampl_lsb), tb_clk);  -- ampl
 
     -- Read current BSN
     mmf_mm_bus_rd(c_mm_file_reg_bsn_scheduler_wg, 0, current_bsn_wg(31 DOWNTO  0), tb_clk);
@@ -462,24 +468,41 @@ BEGIN
     -- Verify 10GbE UDP offload
     --------------------------------------------------------------------------- 
     print_str("");
-    print_str("Beamlet output:");
+    print_str("WG:");
+    print_str(". sp_0 at mid subband,");
+    print_str(". sp_2 at subband edge, so at mid of os subband.");
+    print_str(". c_wg_ampl_sp_0            = " & int_to_str(c_wg_ampl_sp_0));
+    print_str(". c_wg_ampl_sp_2            = " & int_to_str(c_wg_ampl_sp_2));
+    print_str(". c_subband_sp_0            = " & real_to_str(c_subband_sp_0, 20, 6));
+    print_str(". c_subband_sp_2            = " & real_to_str(c_subband_sp_2, 20, 6));
+    print_str("WPFB:");
+    print_str(". c_exp_subband_ampl_sp_0   = " & real_to_str(c_exp_subband_ampl_sp_0, 20, 6));
+    print_str(". c_exp_subband_ampl_sp_2   = " & real_to_str(c_exp_subband_ampl_sp_2, 20, 6));
+    print_str("BF:");
+    print_str(". c_exp_beamlet_ampl_sp_0   = " & real_to_str(c_exp_beamlet_ampl_sp_0, 20, 6));
+    print_str(". c_exp_beamlet_ampl_sp_2   = " & real_to_str(c_exp_beamlet_ampl_sp_2, 20, 6));
+    print_str("");
+    print_str("Beamlet output: (sp_0 at mid subband, sp_2 at subband edge, so at mid of os subband):");
     print_str(". c_exp_beamlet_index       = " & int_to_str(c_exp_beamlet_index));
     print_str(". c_exp_beamlet_index_os    = " & int_to_str(c_exp_beamlet_index_os));
-    print_str(". c_exp_beamlet_ampl        = " & real_to_str(c_exp_beamlet_ampl, 20, 6));
+    print_str(". c_exp_beamlet_ampl_sp_0   = " & real_to_str(c_exp_beamlet_ampl_sp_0, 20, 6));
+    print_str(". c_exp_beamlet_ampl_sp_2   = " & real_to_str(c_exp_beamlet_ampl_sp_2, 20, 6));
     print_str(". c_exp_beamlet_phase       = " & real_to_str(c_exp_beamlet_phase, 20, 6));
     print_str("");
     print_str(". c_beamlet_re at index     = " & int_to_str(TO_SINT(beamlet_arr2_re(c_exp_beamlet_index))));
     print_str(". c_beamlet_re at index_os  = " & int_to_str(TO_SINT(beamlet_arr2_re(c_exp_beamlet_index_os))));
-    print_str(". c_exp_beamlet_re          = " & int_to_str(INTEGER(c_exp_beamlet_re)));
+    print_str(". c_exp_beamlet_re_sp_0     = " & int_to_str(INTEGER(c_exp_beamlet_re_sp_0)));
+    print_str(". c_exp_beamlet_re_sp_2     = " & int_to_str(INTEGER(c_exp_beamlet_re_sp_2)));
     print_str("");
     print_str(". c_beamlet_im at index     = " & int_to_str(TO_SINT(beamlet_arr2_im(c_exp_beamlet_index))));
     print_str(". c_beamlet_im at index_os  = " & int_to_str(TO_SINT(beamlet_arr2_im(c_exp_beamlet_index_os))));
-    print_str(". c_exp_beamlet_im          = " & int_to_str(INTEGER(c_exp_beamlet_im)));
+    print_str(". c_exp_beamlet_im_sp_0     = " & int_to_str(INTEGER(c_exp_beamlet_im_sp_0)));
+    print_str(". c_exp_beamlet_im_sp_2     = " & int_to_str(INTEGER(c_exp_beamlet_im_sp_2)));
 
-    ASSERT SIGNED(beamlet_arr2_re(c_exp_beamlet_index)) = c_exp_beamlet_re REPORT "Wrong 10GbE output (re) on beamset 0" SEVERITY ERROR;
-    ASSERT SIGNED(beamlet_arr2_im(c_exp_beamlet_index)) = c_exp_beamlet_im REPORT "Wrong 10GbE output (im) on beamset 0" SEVERITY ERROR;
-    ASSERT SIGNED(beamlet_arr2_re(c_exp_beamlet_index_os)) = c_exp_beamlet_re REPORT "Wrong 10GbE output (re) on beamset 1 (shifted subbands)" SEVERITY ERROR;
-    ASSERT SIGNED(beamlet_arr2_im(c_exp_beamlet_index_os)) = c_exp_beamlet_im REPORT "Wrong 10GbE output (im) on beamset 1 (shifted subbands)" SEVERITY ERROR;
+    ASSERT SIGNED(beamlet_arr2_re(c_exp_beamlet_index)) = c_exp_beamlet_re_sp_0 REPORT "Wrong 10GbE beamlet output /= c_exp_beamlet_re_sp_0 in beamset 0" SEVERITY ERROR;
+    ASSERT SIGNED(beamlet_arr2_im(c_exp_beamlet_index)) = c_exp_beamlet_im_sp_0 REPORT "Wrong 10GbE beamlet output /= c_exp_beamlet_im_sp_0 in beamset 0" SEVERITY ERROR;
+    ASSERT SIGNED(beamlet_arr2_re(c_exp_beamlet_index_os)) = c_exp_beamlet_re_sp_2 REPORT "Wrong 10GbE beamlet output /= c_exp_beamlet_re_sp_2 in beamset 1 (shifted subbands)" SEVERITY ERROR;
+    ASSERT SIGNED(beamlet_arr2_im(c_exp_beamlet_index_os)) = c_exp_beamlet_im_sp_2 REPORT "Wrong 10GbE beamlet output /= c_exp_beamlet_im_sp_2 in beamset 1 (shifted subbands)" SEVERITY ERROR;
 
     ---------------------------------------------------------------------------
     -- End Simulation 
-- 
GitLab