From 31d84067068c2ce1c9970030f1e19f848b56258f Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Thu, 11 Mar 2021 08:40:21 +0100 Subject: [PATCH] Optimize modulation calibration --- main.c | 41 +++++++---------------------------------- nanovna.h | 2 +- sa_core.c | 11 +++++++++++ 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/main.c b/main.c index e5a32f7..9d9bef4 100644 --- a/main.c +++ b/main.c @@ -993,9 +993,9 @@ config_t config = { .high_correction_frequency = { 240000000, 280000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 960000000 }, .high_correction_value = { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 }, .setting_frequency_10mhz = 10000000, - .cor_am = -10, - .cor_wfm = -18, - .cor_nfm = -18, + .cor_am = 0,// -10, + .cor_wfm = 0, //-18, + .cor_nfm = 0, //-18, .ext_zero_level = 128, #endif #ifdef TINYSA4 @@ -2967,42 +2967,15 @@ int main(void) chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO-1, Thread1, NULL); -#ifdef TINYSA4 - reset_settings(M_LOW); + reset_settings(M_LOW); // Calibrate the modulation frequencies set_mode(M_GENLOW); - set_sweep_frequency(ST_CENTER, (freq_t)30000000); set_sweep_frequency(ST_SPAN, (freq_t)0); in_selftest = true; - - if (config.cor_am == 0) { - setting.modulation = MO_AM; - setting.modulation_frequency = 5000; - config.cor_am = 0; - perform(false,0, 30000000, false); - perform(false,1, 30000000, false); - config.cor_am = -(start_of_sweep_timestamp - (ONE_SECOND_TIME / setting.modulation_frequency))/8; - } - - if (config.cor_nfm == 0) { - setting.modulation = MO_NFM; - setting.modulation_frequency = 5000; - config.cor_nfm = 0; - perform(false,0, 30000000, false); - perform(false,1, 30000000, false); - config.cor_nfm = -(start_of_sweep_timestamp - (ONE_SECOND_TIME / setting.modulation_frequency))/8; - } - - if (config.cor_wfm == 0) { - setting.modulation = MO_WFM; - setting.modulation_frequency = 5000; - config.cor_wfm = 0; - perform(false,0, 30000000, false); - perform(false,1, 30000000, false); - config.cor_wfm = -(start_of_sweep_timestamp - (ONE_SECOND_TIME / setting.modulation_frequency))/8; - } + calibrate_modulation(MO_AM, &config.cor_am); + calibrate_modulation(MO_NFM, &config.cor_nfm); + calibrate_modulation(MO_WFM, &config.cor_wfm); in_selftest = false; reset_settings(M_LOW); -#endif while (1) { diff --git a/nanovna.h b/nanovna.h index 9543618..ee11fae 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1076,7 +1076,7 @@ typedef struct properties { //sizeof(properties_t) == 0x1200 -#define CONFIG_MAGIC 0x434f4e4A /* 'CONF' */ +#define CONFIG_MAGIC 0x434f4e4b /* 'CONF' */ extern int16_t lastsaveid; //extern properties_t *active_props; diff --git a/sa_core.c b/sa_core.c index 7a6160c..ce837fc 100644 --- a/sa_core.c +++ b/sa_core.c @@ -4697,6 +4697,17 @@ void reset_calibration(void) config.low_level_offset = 100; } +void calibrate_modulation(int modulation, int8_t *correction) +{ + if (*correction == 0) { + setting.modulation = modulation; + setting.modulation_frequency = 5000; + perform(false,0, 30000000, false); + perform(false,1, 30000000, false); + *correction = -(start_of_sweep_timestamp - (ONE_SECOND_TIME / setting.modulation_frequency))/8; + } +} + #define CALIBRATE_RBWS 1 const int power_rbw [5] = { 100, 300, 30, 10, 3 };