From 02f06319d8b93cda32f52a6afac9420fccf5f8d1 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 29 Mar 2021 17:45:46 +0200 Subject: [PATCH] Correction updates --- main.c | 4 ++-- sa_core.c | 33 +++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/main.c b/main.c index f84541c..faddb28 100644 --- a/main.c +++ b/main.c @@ -1017,8 +1017,8 @@ config_t config = { .high_level_output_offset = 0.0, // Uncalibrated .correction_frequency = {{ 1000000, 500000000, 1000000000, 1500000000, 2000000000, 2500000000, 3000000000, 3500000000, 4000000000, 4500000000, 5000000000, 5500000000, 6000000000, 6500000000, 7000000000, 7500000000, 8000000000, 8500000000, 9000000000, 10000000000 }, { 1000000, 500000000, 1000000000, 1500000000, 2000000000, 2500000000, 3000000000, 3500000000, 4000000000, 4500000000, 5000000000, 5500000000, 6000000000, 6500000000, 7000000000, 7500000000, 8000000000, 8500000000, 9000000000, 10000000000 }}, - .correction_value = {{ 0, +3, +11, +8.5, +2, +3, +10, +15, +12, +4, +0, +18, +22, +30, +30, +30, +30, +30, +30, +30 }, - { 0, +3, +11, +8.5, +2, +3, +10, +15, +12, +4, +0, +18, +22, +30, +30, +30, +30, +30, +30, +30 }}, + .correction_value = {{ 0, +1.5, +4, +4, +2, +3.5, +8, +12, +15, +13, +12, +23, +27, +27, +27, +27, +27, +27, +27, +27 }, + { 0, +1, +4.5, +1, +2.5, +6.5, +9, +15, +15.5, +28, +29, +41, +48, +48, +48, +48, +48, +48, +48, +48 }}, .setting_frequency_30mhz = 30000000, .cor_am = 0, .cor_wfm = 0, diff --git a/sa_core.c b/sa_core.c index 2c607ce..39d7430 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1362,8 +1362,8 @@ static const struct { int16_t noise_level; } step_delay_table[]={ // RBWx10 step_delay offset_delay spur_gate (value divided by 1000) - { 8500, 200, 50, 400, -90}, - { 3000, 200, 50, 200, -95}, + { 8500, 250, 50, 400, -90}, + { 3000, 250, 50, 200, -95}, { 1000, 400, 100, 100, -105}, { 300, 400, 120, 100, -110}, { 100, 700, 120, 100, -115}, @@ -1445,8 +1445,8 @@ static const float correction_value[CORRECTION_POINTS] = * The frequency steps between correction factors is assumed to be maximum 500MHz or 0x2000000 and minimum 100kHz or > 0x10000 * The divider 1/m is pre-calculated into delta_div as 2^scale_factor * correction_step/frequency_step */ - -#define SCALE_FACTOR 14 // min scaled correction = 2^15, max scaled correction = 256 * 2^15 +#define FREQ_SCALE_FACTOR 10 +#define SCALE_FACTOR 5 // min scaled correction = 2^15, max scaled correction = 256 * 2^15 // min scaled f = 6, max scaled f = 1024 static int32_t scaled_correction_multi[CORRECTION_POINTS]; @@ -1458,8 +1458,8 @@ static void calculate_correction(void) for (int i = 1; i < CORRECTION_POINTS; i++) { scaled_correction_value[i] = setting.correction_value[i] * (1 << (SCALE_FACTOR)); int32_t m = scaled_correction_value[i] - scaled_correction_value[i-1]; - int32_t d = (setting.correction_frequency[i] - setting.correction_frequency[i-1]) >> SCALE_FACTOR; - scaled_correction_multi[i] = (int32_t) ( m / d ); +// int32_t d = (setting.correction_frequency[i] - setting.correction_frequency[i-1]) >> SCALE_FACTOR; + scaled_correction_multi[i] = m; // (int32_t) ( m / d ); } } #pragma GCC push_options @@ -1502,8 +1502,12 @@ pureRSSI_t get_frequency_correction(freq_t f) // Frequency dependent RSSI c float multi = (setting.correction_value[i] - setting.correction_value[i-1]) * (1 << (SCALE_FACTOR -1)) / (float)m; float cv = setting.correction_value[i-1] + ((f >> SCALE_FACTOR) * multi) / (float)(1 << (SCALE_FACTOR -1)) ; #else - int32_t scaled_f = f >> SCALE_FACTOR; - cv += (scaled_correction_value[i-1] + (scaled_f * scaled_correction_multi[i])) >> (SCALE_FACTOR - 5) ; + int32_t scaled_f = f >> FREQ_SCALE_FACTOR; + int32_t scaled_f_divider = (setting.correction_frequency[i] - setting.correction_frequency[i-1]) >> FREQ_SCALE_FACTOR; + if (scaled_f_divider!=0) + cv += (scaled_correction_value[i-1] + ((scaled_f * scaled_correction_multi[i])/scaled_f_divider)) >> (SCALE_FACTOR - 5) ; + else + cv += scaled_correction_value[i-1] >> (SCALE_FACTOR - 5) ; #endif done: return(cv); @@ -2410,10 +2414,15 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / #endif #ifdef TINYSA4 // ----------------------------- set mixer drive -------------------------------------------- - if (setting.lo_drive & 0x40 || f >=2000000000UL) { - if (old_drive != 3) { - ADF4351_drive(3); // Max drive - old_drive = 3; + if (setting.lo_drive & 0x40){ + int target_drive = 1; + if (f >=400000000ULL) + target_drive = 2; + else if (f >=2000000000ULL) + target_drive = 3; + if (old_drive != target_drive) { + ADF4351_drive(target_drive); // Max drive + old_drive = target_drive; } } else { if (old_drive != setting.lo_drive) {