diff --git a/main.c b/main.c index e9233e4..cb784dd 100644 --- a/main.c +++ b/main.c @@ -2057,6 +2057,7 @@ static const VNAShellCommand commands[] = { "agc", cmd_agc, CMD_RUN_IN_LOAD }, #endif { "actual_freq", cmd_actual_freq, CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD }, + { "freq_corr", cmd_freq_correction, CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD }, { "attenuate", cmd_attenuate, CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD }, { "level", cmd_level, CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD }, { "sweeptime", cmd_sweeptime, CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD }, diff --git a/nanovna.h b/nanovna.h index 41c9569..6c1fb4e 100644 --- a/nanovna.h +++ b/nanovna.h @@ -18,7 +18,7 @@ */ #include "ch.h" -#ifdef TINYSA_F303 +//#ifdef TINYSA_F303 #ifdef TINYSA_F072 #error "Remove comment for #ifdef TINYSA_F303" #endif @@ -26,7 +26,7 @@ #define TINYSA4 #endif #define TINYSA4_PROTO -#endif +//#endif #ifdef TINYSA_F072 #ifdef TINYSA_F303 @@ -457,7 +457,8 @@ void clear_frequency_cache(void); void toggle_high_out_adf4350(void); extern int high_out_adf4350; #endif -int set_actual_freq(int); +int set_actual_freq(freq_t); +int set_freq_corr(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 7c036b1..d733939 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -605,12 +605,24 @@ VNA_SHELL_FUNCTION(cmd_if1) VNA_SHELL_FUNCTION(cmd_actual_freq) { if (argc != 1 || argv[0][0] == '?') { - shell_printf("%DHz\r\n", config.setting_frequency_30mhz); + shell_printf("%D\r\n", config.setting_frequency_30mhz); return; } else { set_actual_freq(my_atoui(argv[0])); } } + + +VNA_SHELL_FUNCTION(cmd_freq_correction) +{ + if (argc != 1 || argv[0][0] == '?') { + shell_printf("%d ppb\r\n", (int)(((int64_t)config.setting_frequency_30mhz - (int64_t)3000000000ULL)/3)); + return; + } else { + set_freq_corr(my_atoi(argv[0])); + } +} + #endif diff --git a/sa_core.c b/sa_core.c index 5655d5d..50f90c7 100644 --- a/sa_core.c +++ b/sa_core.c @@ -819,7 +819,7 @@ void set_gridlines(int d) #ifdef TINYSA4 -int set_actual_freq(int f) +int set_freq_corr(int f) { if (f < - 100000 || f > +100000) return -1; @@ -830,6 +830,18 @@ int set_actual_freq(int f) update_grid(); return 0; } + +int set_actual_freq(freq_t f) +{ + if (f < 3000000000 - 30000 || f > 3000000000 + 30000) + return -1; + config.setting_frequency_30mhz =f; + ADF4351_recalculate_PFDRFout(); + config_save(); + dirty = true; + update_grid(); + return 0; +} #else void set_10mhz(freq_t f) { @@ -5326,7 +5338,7 @@ static volatile int dummy; } } } - + } #define __MIRROR_MASKING__ @@ -5369,7 +5381,7 @@ static volatile int dummy; #ifdef TINYSA4_4 && !setting.extra_lna #endif - ) { // calculate and apply auto attenuate + ) { // calculate and apply auto attenuate setting.atten_step = false; // No step attenuate in low mode auto attenuate int changed = false; int delta = 0; @@ -5414,7 +5426,7 @@ static volatile int dummy; #endif #endif calculate_static_correction(); // Update correction -// dirty = true; // Needed to recalculate the correction factor + // dirty = true; // Needed to recalculate the correction factor } } @@ -5629,7 +5641,7 @@ static volatile int dummy; } #endif - } + // } while (MODE_OUTPUT(setting.mode) && setting.modulation != MO_NONE); // Never exit sweep loop while in output mode with modulation #if 0 // Read ADC extern int fix_fft(short fr[], short fi[], short m, short inverse); diff --git a/ui_sa.c b/ui_sa.c index 1c29209..13d9a3b 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -575,7 +575,7 @@ char range_text[20]; #ifdef TINYSA4 int input_is_calibrated(void) { - if (!config.input_is_calibrated) + if (config.input_is_calibrated) return true; drawMessageBox("Error", "First calibrate 100kHz to 5.34GHz input", 2000); redraw_request|= REDRAW_AREA; @@ -584,7 +584,7 @@ int input_is_calibrated(void) int output_is_calibrated(void) { - if (!config.output_is_calibrated) + if (config.output_is_calibrated) return true; drawMessageBox("Error", "First calibrate 30MHz output", 2000); redraw_request|= REDRAW_AREA;