From 12e912d7f1bbdee045a1a73fe65884d2ea707c3d Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Thu, 1 Apr 2021 08:30:31 +0200 Subject: [PATCH] Shift freq added --- nanovna.h | 3 ++- plot.c | 15 ++++++------- sa_cmd.c | 2 +- sa_core.c | 52 +++++++++++++++++++++++++++++++++++---------- ui.c | 2 +- ui_sa.c | 63 ++++++++++++++++++++++++++++++++++++++++++------------- 6 files changed, 102 insertions(+), 35 deletions(-) diff --git a/nanovna.h b/nanovna.h index e4cf23d..480ebfe 100644 --- a/nanovna.h +++ b/nanovna.h @@ -986,6 +986,7 @@ typedef struct setting freq_t frequency0; freq_t frequency1; freq_t frequency_IF; + long_t frequency_offset; float trace_scale; float trace_refpos; @@ -1007,7 +1008,7 @@ typedef struct setting uint8_t ultra; // enum ?? int R; // KM_R #endif - int test_argument; // used for tests + int64_t test_argument; // used for tests uint32_t checksum; // must be last and at 4 byte boundary }setting_t; diff --git a/plot.c b/plot.c index 549ee8e..d7c5a6d 100644 --- a/plot.c +++ b/plot.c @@ -129,7 +129,7 @@ float2int(float v) void update_grid(void) { freq_t gdigit = 1000000000; - freq_t fstart = get_sweep_frequency(ST_START); + freq_t fstart = get_sweep_frequency(ST_START) + setting.frequency_offset; freq_t fspan = get_sweep_frequency(ST_SPAN); freq_t grid; @@ -209,7 +209,7 @@ const ham_bands_t ham_bands[] = int ham_band(int x) // Search which index in the frequency tabled matches with frequency f using actual_rbw { - freq_t f = frequencies[x]; + freq_t f = frequencies[x] + setting.frequency_offset; int L = 0; int R = (sizeof ham_bands)/sizeof(freq_t) - 1; while (L <= R) { @@ -1347,7 +1347,8 @@ static void trace_print_value_string( // Only used at one place if (ridx > idx) {freq = ref_freq - freq; idx = ridx - idx; *ptr2++ = '-';} else {freq = freq - ref_freq; idx = idx - ridx; *ptr2++ = '+';} v-= value(coeff[ridx]); - } + } else + freq += setting.frequency_offset; // For CW mode output time if (FREQ_IS_CW()) { @@ -1541,16 +1542,16 @@ draw_frequencies(void) return; if (FREQ_IS_CW()) { - plot_printf(buf1, sizeof(buf1), " CW %QHz", get_sweep_frequency(ST_CW)); + plot_printf(buf1, sizeof(buf1), " CW %QHz", get_sweep_frequency(ST_CW) + setting.frequency_offset); // Show user actual select sweep time? uint32_t t = setting.actual_sweep_time_us; plot_printf(buf2, sizeof(buf2), " TIME %.3Fs", (float)t/ONE_SECOND_TIME); } else if (FREQ_IS_STARTSTOP()) { - plot_printf(buf1, sizeof(buf1), " START %.3QHz %5.1QHz/", get_sweep_frequency(ST_START), grid_span); - plot_printf(buf2, sizeof(buf2), " STOP %.3QHz", get_sweep_frequency(ST_STOP)); + plot_printf(buf1, sizeof(buf1), " START %.3QHz %5.1QHz/", get_sweep_frequency(ST_START) + setting.frequency_offset, grid_span); + plot_printf(buf2, sizeof(buf2), " STOP %.3QHz", get_sweep_frequency(ST_STOP) + setting.frequency_offset); } else if (FREQ_IS_CENTERSPAN()) { - plot_printf(buf1, sizeof(buf1), " CENTER %.3QHz %5.1QHz/", get_sweep_frequency(ST_CENTER), grid_span); + plot_printf(buf1, sizeof(buf1), " CENTER %.3QHz %5.1QHz/", get_sweep_frequency(ST_CENTER) + setting.frequency_offset, grid_span); plot_printf(buf2, sizeof(buf2), " SPAN %.3QHz", get_sweep_frequency(ST_SPAN)); } ili9341_set_foreground(LCD_FG_COLOR); diff --git a/sa_cmd.c b/sa_cmd.c index 89f418c..2e49a47 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -485,7 +485,7 @@ VNA_SHELL_FUNCTION(cmd_selftest) if (argc == 1) setting.test_argument = 0; else - setting.test_argument = my_atoi(argv[1]); + setting.test_argument = my_atoui(argv[1]); sweep_mode = SWEEP_SELFTEST; } diff --git a/sa_core.c b/sa_core.c index 2e040e9..f41087b 100644 --- a/sa_core.c +++ b/sa_core.c @@ -230,6 +230,7 @@ void reset_settings(int m) #else setting.frequency_IF = DEFAULT_IF; #endif + setting.frequency_offset = 0; setting.auto_IF = true; set_external_gain(0.0); // This also updates the help text!!!!! //setting.external_gain = 0.0; @@ -1452,6 +1453,19 @@ static const float correction_value[CORRECTION_POINTS] = static int32_t scaled_correction_multi[CORRECTION_POINTS]; static int32_t scaled_correction_value[CORRECTION_POINTS]; +#if 0 // Not implemented +static int8_t scaled_atten_correction[16][16] = +{ + {0, -1, -2, -2, -3, -4, -3, -1, 0, 3, 7, 14, 21, 30, 42, 54 }, // 2.6G dB*8, 16 levels + {0, -2, -4, -6, -7, -9, -8, -8, -11, -9, -9, -8, -7, -4, 2, 8 }, // 3.2G + {0, 0, 0, -1, -8, -10, -10, -12, -22, -24, -28, -30, -37, -34, -24, -13, }, // 3.8G + {0, 0, 0, -1, -8, -10, -10, -12, -22, -24, -28, -30, -37, -34, -24, -13, }, // 4.3G + {0, 0, 0, 1, -4, -2, 0, 0, -3, 0, 1, 6, 5, 10, 16, 22, }, // 4.8G + {0, 0, 1, 2, -9, -7, -6, -5, -18, -18, -17, -17, -23, -24, -25, -27, }, // 5.4G + {0, -1, -3, -3, -21, -20, -20, -20, -31, -29, -24, -18, -4, 4, 19, 30, }, // 5.9G +}; +#endif + static void calculate_correction(void) { scaled_correction_value[0] = setting.correction_value[0] * (1 << (SCALE_FACTOR)); @@ -1471,6 +1485,15 @@ pureRSSI_t get_frequency_correction(freq_t f) // Frequency dependent RSSI c if (setting.mode == M_GENHIGH) return(0.0); #ifdef TINYSA4 +#if 0 // Not implemented + int cf = (((f >> 28)+1)>>1) - 5; // Correction starts at 2,684,354,560Hz round to closest correction frequency + int ca = setting.attenuate_x2 >> 2; // One data point per 2dB step + if (cf >= 0 && cf < 16) + cv -= scaled_atten_correction[cf][ca]<<2; // Shift is +5(pure RSSI) - 3 (scaled correction) = 2 +#endif +#endif + + #if 0 if (setting.extra_lna) { if (f > 2100000000U) { @@ -1483,7 +1506,6 @@ pureRSSI_t get_frequency_correction(freq_t f) // Frequency dependent RSSI c if (f > ULTRA_MAX_FREQ) { cv += float_TO_PURE_RSSI(+4); // 4dB loss in harmonic mode } -#endif #endif int i = 0; while (f > setting.correction_frequency[i] && i < CORRECTION_POINTS) @@ -2706,15 +2728,13 @@ modulation_again: again: // Spur reduction jumps to here for second measurement #endif - local_IF=0; // to get rid of warning + local_IF=0; // For all high modes #ifdef TINYSA4 int LO_shifted = false; int LO_mirrored = false; int LO_harmonic = false; #endif - if (MODE_HIGH(setting.mode)) { - local_IF = 0; - } else if (MODE_LOW(setting.mode)){ // All low mode + if (MODE_LOW(setting.mode)){ // All low mode if (!setting.auto_IF) local_IF = setting.frequency_IF; else @@ -3626,7 +3646,7 @@ sweep_again: // stay in sweep loop when output mo } else if (actual_max_level > target_level && setting.attenuate_x2 < 60) { delta = actual_max_level - target_level; } - if ((chVTGetSystemTimeX() - sweep_elapsed > 10000 && delta != 0) || delta > 5 ) { + if ((chVTGetSystemTimeX() - sweep_elapsed > 10000 && ( delta < -5 || delta > +5)) || delta > 10 ) { setting.attenuate_x2 += delta + delta; if (setting.attenuate_x2 < 0) setting.attenuate_x2= 0; @@ -4151,7 +4171,7 @@ const test_case_t test_case [] = #define TEST_SILENCE 4 TEST_CASE_STRUCT(TC_BELOW, TP_SILENT, 200, 100, -70, 0, 0), // 5 Wide band noise floor low mode TEST_CASE_STRUCT(TC_BELOW, TPH_SILENT, 633, 994, -85, 0, 0), // 6 Wide band noise floor high mode - TEST_CASE_STRUCT(TC_SIGNAL, TP_10MHZEXTRA, 30, 14, -20, 27, -70), // 7 BPF loss and stop band + TEST_CASE_STRUCT(TC_SIGNAL, TP_10MHZEXTRA, 30, 14, -23, 27, -70), // 7 BPF loss and stop band TEST_CASE_STRUCT(TC_FLAT, TP_10MHZEXTRA, 30, 14, -18, 9, -60), // 8 BPF pass band flatness TEST_CASE_STRUCT(TC_BELOW, TP_30MHZ, 900, 1, -90, 0, -90), // 9 LPF cutoff TEST_CASE_STRUCT(TC_SIGNAL, TP_10MHZ_SWITCH,20, 7, -29, 10, -50), // 10 Switch isolation using high attenuation @@ -4772,18 +4792,28 @@ quit: reset_settings(M_LOW); #if 1 float reference_peak_level = 0; - for (int j= 0; j < 64; j++ ) { + int c = 0; + for (int j= 0; j < 64; j += 4 ) { test_prepare(TEST_LEVEL); set_attenuation(((float)j)/2.0); if (setting.test_argument) - set_sweep_frequency(ST_CENTER, ((freq_t)setting.test_argument) * 1000000ULL); + set_sweep_frequency(ST_CENTER, ((freq_t)setting.test_argument)); ultra_threshold = config.ultra_threshold; test_acquire(TEST_LEVEL); // Acquire test test_validate(TEST_LEVEL); // Validate test if (j == 0) reference_peak_level = peakLevel; shell_printf("Attenuation %.2fdB, measured level %.2fdBm, delta %.2fdB\n\r",((float)j)/2.0, peakLevel, peakLevel - reference_peak_level); + if ((j % 4) == 0) { + age[c++] = (uint8_t)((int)((peakLevel - reference_peak_level) * 8)+128); + } + } + shell_printf(" {"); + for (int i=0; i < 16;i++) + shell_printf("%d, ", (int)(((int)age[i])-128)); + shell_printf("}\n\r"); + #else test_prepare(TEST_ATTEN); test_acquire(TEST_ATTEN); // Acquire test @@ -5162,9 +5192,9 @@ again: config_save(); ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - ili9341_drawstring_7x13("Calibration complete", 30, 140); + ili9341_drawstring_7x13("Calibration complete", 40, 140); quit: - ili9341_drawstring_7x13("Touch screen to continue", 30, 200); + ili9341_drawstring_7x13("Touch screen to continue", 40, 200); wait_user(); ili9341_clear_screen(); set_sweep_points(old_sweep_points); diff --git a/ui.c b/ui.c index c6d0a6f..adae8d6 100644 --- a/ui.c +++ b/ui.c @@ -506,7 +506,7 @@ show_version(void) } #ifdef TINYSA3 if (has_esd) - ili9341_drawstring("ESD protected", x, y+=5); + ili9341_drawstring("ESD protected", x, y+=10); #endif #ifdef TINYSA4 extern const char *states[]; diff --git a/ui_sa.c b/ui_sa.c index 271045d..f760c4a 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1536,6 +1536,40 @@ static UI_FUNCTION_ADV_CALLBACK(menu_pause_acb) // draw_cal_status(); } +static UI_FUNCTION_ADV_CALLBACK(menu_shift_acb) +{ + (void) data; + (void) item; + if (b){ + b->icon = setting.frequency_offset != 0 ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK; + return; + } + if (setting.frequency_offset != 0) { + setting.frequency_offset = 0; + } else { + if (FREQ_IS_STARTSTOP()) { + freq_t old_start = get_sweep_frequency(ST_START); + freq_t old_stop = get_sweep_frequency(ST_STOP); + kp_help_text = "Actual start frequency"; + ui_mode_keypad(KM_START); + setting.frequency_offset = uistat.value - old_start; + set_sweep_frequency(ST_START, old_start); + set_sweep_frequency(ST_STOP, old_stop); + } else { + freq_t old_center = get_sweep_frequency(ST_CENTER); + freq_t old_span = get_sweep_frequency(ST_SPAN); + kp_help_text = "Actual center frequency"; + ui_mode_keypad(KM_CENTER); + setting.frequency_offset = uistat.value - old_center; + set_sweep_frequency(ST_CENTER, old_center); + set_sweep_frequency(ST_SPAN, old_span); + } + } + ui_mode_normal(); +// menu_move_back(true); +// draw_cal_status(); +} + #ifdef __REMOTE_DESKTOP__ static UI_FUNCTION_ADV_CALLBACK(menu_send_display_acb) { @@ -2165,6 +2199,7 @@ static const menuitem_t menu_config[] = { #ifdef __USE_SERIAL_CONSOLE__ { MT_SUBMENU, 0, "CONNECTION", menu_connection}, #endif + { MT_ADV_CALLBACK,0,"SHIFT\nFREQ", menu_shift_acb}, { MT_SUBMENU, 0, "EXPERT\nCONFIG", menu_settings}, { MT_SUBMENU, 0, S_RARROW" DFU", menu_dfu}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, @@ -2333,15 +2368,15 @@ static void fetch_numeric_target(void) { switch (keypad_mode) { case KM_START: - uistat.value = get_sweep_frequency(ST_START); + uistat.value = get_sweep_frequency(ST_START) + setting.frequency_offset; plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_STOP: - uistat.value = get_sweep_frequency(ST_STOP); + uistat.value = get_sweep_frequency(ST_STOP) + setting.frequency_offset; plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_CENTER: - uistat.value = get_sweep_frequency(ST_CENTER); + uistat.value = get_sweep_frequency(ST_CENTER) + setting.frequency_offset; plot_printf(uistat.text, sizeof uistat.text, "%3.4fMHz", uistat.value / 1000000.0); break; case KM_SPAN: @@ -2349,7 +2384,7 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_CW: - uistat.value = get_sweep_frequency(ST_CW); + uistat.value = get_sweep_frequency(ST_CW) + setting.frequency_offset; plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_SCALE: @@ -2503,20 +2538,20 @@ set_numeric_value(void) { switch (keypad_mode) { case KM_START: - set_sweep_frequency(ST_START, (freq_t)uistat.value); + set_sweep_frequency(ST_START, (freq_t)uistat.value - setting.frequency_offset); break; case KM_STOP: - set_sweep_frequency(ST_STOP, (freq_t)uistat.value); + set_sweep_frequency(ST_STOP, (freq_t)uistat.value - setting.frequency_offset); break; case KM_CENTER: - set_sweep_frequency(ST_CENTER, (freq_t)uistat.value); + set_sweep_frequency(ST_CENTER, (freq_t)uistat.value - setting.frequency_offset); break; case KM_SPAN: setting.modulation = MO_NONE; set_sweep_frequency(ST_SPAN, (freq_t)uistat.value); break; case KM_CW: - set_sweep_frequency(ST_CW, (freq_t)uistat.value); + set_sweep_frequency(ST_CW, (freq_t)uistat.value - setting.frequency_offset); break; case KM_SCALE: user_set_scale(uistat.value); @@ -2589,7 +2624,7 @@ set_numeric_value(void) #endif #ifdef __LIMITS__ case KM_LIMIT_FREQ: - setting.limits[active_limit].frequency = uistat.value; + setting.limits[active_limit].frequency = uistat.value - setting.frequency_offset; limits_update(); break; case KM_LIMIT_LEVEL: @@ -2631,7 +2666,7 @@ set_numeric_value(void) set_gridlines(uistat.value); break; case KM_MARKER: - set_marker_frequency(active_marker, (freq_t)uistat.value); + set_marker_frequency(active_marker, (freq_t)uistat.value - setting.frequency_offset); break; case KM_MODULATION: set_modulation_frequency((int)uistat.value); @@ -3038,11 +3073,11 @@ redraw_cal_status: // Version y += YSTEP + YSTEP/2 ; -//#ifdef TINYSA4 -// strncpy(buf,&VERSION[11], BLEN-1); -//#else +#ifdef TINYSA4 strncpy(buf,&VERSION[9], BLEN-1); -//#endif +#else + strncpy(buf,&VERSION[8], BLEN-1); +#endif ili9341_drawstring(buf, x, y);