diff --git a/nanovna.h b/nanovna.h index 98cb1aa..b9734e5 100644 --- a/nanovna.h +++ b/nanovna.h @@ -456,7 +456,7 @@ void clear_frequency_cache(void); void toggle_high_out_adf4350(void); extern int high_out_adf4350; #endif -void set_30mhz(freq_t); +int set_actual_freq(int); void set_IF2(int f); void set_R(int f); extern void set_modulo(uint32_t f); diff --git a/sa_cmd.c b/sa_cmd.c index 03aab2b..ffaff9c 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -591,7 +591,7 @@ VNA_SHELL_FUNCTION(cmd_actual_freq) shell_printf("%DHz\r\n", config.setting_frequency_30mhz); return; } else { - set_30mhz(my_atoui(argv[0])); + set_actual_freq(my_atoui(argv[0])); } } #endif diff --git a/sa_core.c b/sa_core.c index 9af22d4..9330d10 100644 --- a/sa_core.c +++ b/sa_core.c @@ -803,15 +803,19 @@ void set_gridlines(int d) } #ifdef TINYSA4 -void set_30mhz(freq_t f) + +int set_actual_freq(int f) { -// if (f < 29000000 || f > 31000000) -// return; - config.setting_frequency_30mhz = f; + if (get_sweep_frequency(ST_CENTER) > 1000000000) + return -1; + if (f < - 10000 || f > +10000) + return -1; + config.setting_frequency_30mhz = 3000000000 + f * 3 ; ADF4351_recalculate_PFDRFout(); config_save(); dirty = true; update_grid(); + return 0; } #else void set_10mhz(freq_t f) @@ -7325,7 +7329,7 @@ void calibrate(void) set_auto_reflevel(true); setting.repeat = 10; //setting.scale = 1; - if (i == 5) { + if (i == 5) { // Not used !!!!! set_sweep_points(51); set_sweep_frequency(ST_SPAN, 50); setting.rbw_x10 = 3; diff --git a/si4468.c b/si4468.c index ea885b1..b0cc862 100644 --- a/si4468.c +++ b/si4468.c @@ -444,6 +444,7 @@ void ADF4351_R_counter(int R) void ADF4351_recalculate_PFDRFout(void){ int local_r = old_R; old_R = -1; + local_setting_frequency_30mhz_x100 = config.setting_frequency_30mhz; ADF4351_R_counter(local_r); } @@ -458,7 +459,7 @@ void ADF4350_shift_ref(int f) { if (f == shifted) return; shifted = false; - local_setting_frequency_30mhz_x100 = 3000000000; + local_setting_frequency_30mhz_x100 = config.setting_frequency_30mhz; if (shifted) { local_setting_frequency_30mhz_x100 = (local_setting_frequency_30mhz_x100 * SHIFT_MUL) / SHIFT_DIV; } diff --git a/ui_sa.c b/ui_sa.c index f5156c8..64e74f0 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -404,7 +404,7 @@ enum { // #10 KM_SAMPLETIME, KM_LOWOUTLEVEL, KM_DECAY, KM_NOISE, #ifdef TINYSA4 - KM_30MHZ, + KM_FREQ_CORR, #else KM_10MHZ, #endif @@ -469,7 +469,7 @@ static const struct { [KM_DECAY] = {keypads_positive , "DECAY"}, // KM_DECAY [KM_NOISE] = {keypads_positive , "NOISE\nLEVEL"}, // KM_NOISE #ifdef TINYSA4 -[KM_30MHZ] = {keypads_freq , "FREQ"}, // KM_30MHz +[KM_FREQ_CORR] = {keypads_plusmin , "PPB"}, // KM_FREQ_CORR #else [KM_10MHZ] = {keypads_freq , "FREQ"}, // KM_10MHz #endif @@ -2971,7 +2971,7 @@ static const menuitem_t menu_settings2[] = { MT_KEYPAD, KM_ATTACK, "ATTACK\n\b%s", "0..100000ms"}, #endif #ifdef TINYSA4 - { MT_KEYPAD, KM_30MHZ, "30MHz*100\n\b%s", "Enter actual 30MHz * 100"}, + { MT_KEYPAD, KM_FREQ_CORR, "FREQ CORR\n\b%s", "Enter ppb correction"}, #endif { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings3}, { MT_NONE, 0, NULL, menu_back} // next-> menu_back @@ -3501,9 +3501,13 @@ static void fetch_numeric_target(uint8_t mode) plot_printf(uistat.text, sizeof uistat.text, "%d", ((int32_t)uistat.value)); break; #ifdef TINYSA4 - case KM_30MHZ: - uistat.freq_value = config.setting_frequency_30mhz; - plot_printf(uistat.text, sizeof uistat.text, "%.5QHz", uistat.freq_value); + case KM_FREQ_CORR: + if (config.setting_frequency_30mhz >= 3000000000ULL) + uistat.value = (config.setting_frequency_30mhz - 3000000000ULL)/3; + else + uistat.value = - ((int)(3000000000ULL - config.setting_frequency_30mhz))/3; + + plot_printf(uistat.text, sizeof uistat.text, "%d", (int32_t)uistat.value); break; #else case KM_10MHZ: @@ -3711,8 +3715,8 @@ set_numeric_value(void) set_noise(uistat.value); break; #ifdef TINYSA4 - case KM_30MHZ: - set_30mhz(uistat.freq_value); + case KM_FREQ_CORR: + set_actual_freq(uistat.value); break; #else case KM_10MHZ: