diff --git a/plot.c b/plot.c index a10e2cd..264d4a4 100644 --- a/plot.c +++ b/plot.c @@ -519,6 +519,13 @@ draw_on_strut(int v0, int d, int color) * calculate log10f(abs(gamma)) */ + +float +index_to_value(const int i) +{ + return(value(actual_t[i])); +} + float value(const float v) { @@ -2084,31 +2091,47 @@ static void cell_draw_marker_info(int x0, int y0) if (setting.measurement == M_THD && active >= 1) active = 2; for (int i = 0; i < MARKER_COUNT; i++) { - if (i == 3 && setting.measurement == M_PASS_BAND) { + if (i == 3) { + if (setting.measurement == M_PASS_BAND) { uint32_t f; if (markers[2].frequency>markers[1].frequency) f = markers[2].frequency-markers[1].frequency; else f = markers[1].frequency-markers[2].frequency; plot_printf(buf, sizeof buf, "WIDTH: %8.3qHz", f); + show_computed: j = 3; int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; int ypos = 1 + (j/2)*(16) - y0; cell_drawstring_7x13(buf, xpos, ypos); -// cell_drawstring(buf, xpos, ypos); + // cell_drawstring(buf, xpos, ypos); + } else if (setting.measurement == M_AM){ +#ifdef AM_IN_VOLT + int old_unit = setting.unit; + setting.unit = U_VOLT; + float level = (index_to_value(markers[1].index) + index_to_value(markers[2].index))/2 / index_to_value(markers[0].index); + setting.unit = old_unit; + int depth = (int)( level * 2.0 * 80.0) + 20; +#else + float level = actual_t[markers[0].index] - (actual_t[markers[1].index] + actual_t[markers[2].index])/2.0 ; + int depth = (int)( (15.0 - level) / 9.0 * 50) + 50; +#endif + plot_printf(buf, sizeof buf, "DEPTH: %3d%%", depth); + goto show_computed; break; - } else + } + } if (i >= 2 && setting.measurement == M_THD) { if (i == 2 && (markers[0].index << 5) > sweep_points ) { int old_unit = setting.unit; setting.unit = U_WATT; - float p = value((actual_t[markers[0].index])); + float p = index_to_value(markers[0].index); int j = 2; uint32_t f = markers[0].frequency; float h = 0.0; while (f * j < frequencies[sweep_points-1]) { if (search_maximum(1, f*j, 4*j) ) // use marker 1 for searching harmonics - h += value((actual_t[markers[1].index])); + h += index_to_value(markers[1].index); j++; } float thd = 100.0 * sqrt(h/p); @@ -2125,10 +2148,10 @@ static void cell_draw_marker_info(int x0, int y0) break; } else if (i >= 2 && setting.measurement == M_OIP3 && markers[2].enabled && markers[3].enabled) { - float il = value((actual_t[markers[2].index])); - float ir = value((actual_t[markers[3].index])); - float sl = value((actual_t[markers[0].index])); - float sr = value((actual_t[markers[1].index])); + float il = index_to_value(markers[2].index); + float ir = index_to_value(markers[3].index); + float sl = index_to_value(markers[0].index); + float sr = index_to_value(markers[1].index); float ip = sl+ (sr - il)/2; plot_printf(buf, sizeof buf, "OIP3: %4.1fdB", ip); diff --git a/sa_core.c b/sa_core.c index 1ac7cdf..acf0a9f 100644 --- a/sa_core.c +++ b/sa_core.c @@ -2014,7 +2014,7 @@ sweep_again: // stay in sweep loop when output mo if (setting.subtract_stored) { RSSI = RSSI - stored_t[i] ; } -// #define __DEBUG_AGC__ +//#define __DEBUG_AGC__ #ifdef __DEBUG_AGC__ // For debugging the AGC control stored_t[i] = (SI4432_Read_Byte(0x69) & 0x01f) * 3.0 - 90.0; // Display the AGC value in the stored trace #endif @@ -2374,18 +2374,18 @@ sweep_again: // stay in sweep loop when output mo if (markers[2].index < 0) markers[1].index = setting._sweep_points - 1; markers[2].frequency = frequencies[markers[2].index]; } else if (setting.measurement == M_PASS_BAND && markers[0].index > 10) { // ----------------Pass band measurement - int t = markers[0].index; - float v = actual_t[t]; - while (t > 0 && actual_t[t] > v - 4.0) // Find left -3dB point - t --; - if (t > 0) { + int t = 0; + float v = actual_t[markers[0].index] - 3.0; + while (t < markers[0].index && actual_t[t+1] < v) // Find left -3dB point + t++; + if (t< markers[0].index) { markers[1].index = t; markers[1].frequency = frequencies[t]; } - t = markers[0].index; - while (t < setting._sweep_points - 1 && actual_t[t] > v - 4.0) // find right -3dB point - t ++; - if (t < setting._sweep_points - 1 ) { + t = setting._sweep_points-1;; + while (t > markers[0].index && actual_t[t-1] < v) // find right -3dB point + t--; + if (t > markers[0].index) { markers[2].index = t; markers[2].frequency = frequencies[t]; } @@ -3584,7 +3584,9 @@ void self_test(int test) reset_settings(M_LOW); setting.step_delay_mode = SD_NORMAL; setting.step_delay = 0; - } else if (test == 5) { + } +#ifdef DOESNOTFIT + else if (test == 5) { // reset_settings(M_LOW); // Make sure we are in a defined state in_selftest = true; switch (setting.test_argument) { @@ -3622,6 +3624,7 @@ void self_test(int test) } in_selftest = false; } +#endif show_test_info = FALSE; in_selftest = false; test_wait = false;