From 1dbac1e03c98137519a6fcc3e3306b36f2009900 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 7 Jul 2020 16:46:17 +0200 Subject: [PATCH 1/2] Some corrections to FAST sweep --- sa_core.c | 31 ++++++++++++++++++------------- ui_sa.c | 18 +++++++++--------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/sa_core.c b/sa_core.c index 69a192a..edc58c1 100644 --- a/sa_core.c +++ b/sa_core.c @@ -920,6 +920,11 @@ extern int SI4432_frequency_changed; extern int SI4432_offset_changed; #define __WIDE_OFFSET__ +#ifdef __WIDE_OFFSET__ +#define OFFSET_LOWER_BOUND -80000 +#else +#define OFFSET_LOWER_BOUND 0 +#endif void set_freq(int V, unsigned long freq) // translate the requested frequency into a setting of the SI4432 { @@ -932,11 +937,11 @@ void set_freq(int V, unsigned long freq) // translate the requested frequency } #if 1 if (setting.step_delay_mode == SD_FAST) { // If in extra fast scanning mode - int delta = ((int32_t)freq) - (int32_t)real_old_freq[V]; // subtracting uint can't create a negative number + int delta = freq - real_old_freq[V]; if (real_old_freq[V] >= 480000000) // 480MHz, high band delta = delta >> 1; - if (delta > -80000 && delta < 80000) { // and requested frequency can be reached by using the offset registers + if (delta > OFFSET_LOWER_BOUND && delta < 80000) { // and requested frequency can be reached by using the offset registers #if 0 if (real_old_freq[V] >= 480000000) shell_printf("%d: Offs %q HW %d\r\n", SI4432_Sel, (uint32_t)(real_old_freq[V]+delta*2), real_old_freq[V]); @@ -953,17 +958,16 @@ void set_freq(int V, unsigned long freq) // translate the requested frequency } #endif #ifdef __WIDE_OFFSET__ + uint32_t target_f; // Impossible to use offset so set SI4432 to new frequency if (freq >= 480000000) { - SI4432_Set_Frequency(freq + 160000 ); // Impossible to use offset so set SI4432 to new frequency - SI4432_Write_Byte(SI4432_FREQ_OFFSET1, 0); // set offset to most negative - SI4432_Write_Byte(SI4432_FREQ_OFFSET2, 0x02); - real_old_freq[V] = freq + 160000; + target_f = freq + 160000; } else { - SI4432_Set_Frequency(freq + 80000 ); // Impossible to use offset so set SI4432 to new frequency - SI4432_Write_Byte(SI4432_FREQ_OFFSET1, 0); // set offset to most negative - SI4432_Write_Byte(SI4432_FREQ_OFFSET2, 0x02); - real_old_freq[V] = freq + 80000; + target_f = freq + 80000; } + SI4432_Set_Frequency(target_f); + SI4432_Write_Byte(SI4432_FREQ_OFFSET1, 0); // set offset to most negative + SI4432_Write_Byte(SI4432_FREQ_OFFSET2, 0x02); + real_old_freq[V] = target_f; #else SI4432_Set_Frequency(freq); // Impossible to use offset so set SI4432 to new frequency SI4432_Write_Byte(SI4432_FREQ_OFFSET1, 0); // set offset to zero @@ -1008,6 +1012,10 @@ void set_switches(int m) old_freq[1] = 0; real_old_freq[0] = 0; real_old_freq[1] = 0; + SI4432_Sel = SI4432_LO ; + SI4432_Write_Byte(SI4432_FREQ_OFFSET1, 0); // Back to nominal offset + SI4432_Write_Byte(SI4432_FREQ_OFFSET2, 0); + switch(m) { case M_LOW: // Mixed into 0 #ifdef __ULTRA__ @@ -1085,9 +1093,6 @@ case M_GENHIGH: // Direct output from 1 break; } - SI4432_Sel = SI4432_LO ; - SI4432_Write_Byte(SI4432_FREQ_OFFSET1, 0); // Back to nominal offset - SI4432_Write_Byte(SI4432_FREQ_OFFSET2, 0); } diff --git a/ui_sa.c b/ui_sa.c index 51f6cd5..6dd1497 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1390,12 +1390,12 @@ static const menuitem_t menu_harmonic[] = static const menuitem_t menu_scanning_speed[] = { - { MT_CALLBACK, SD_NORMAL, "NORMAL", menu_scanning_speed_cb}, // order must match definition of enum - { MT_CALLBACK, SD_PRECISE, "PRECISE", menu_scanning_speed_cb}, - { MT_CALLBACK, SD_FAST, "FAST", menu_scanning_speed_cb}, - { MT_KEYPAD, KM_SAMPLETIME, "\2SAMPLE\0DELAY", "300..30000"}, // item number must match SD_MANUAL - { MT_KEYPAD, KM_OFFSET_DELAY, "\2OFFSET\0DELAY", "300..30000"}, // item number must match SD_MANUAL - { MT_CANCEL, 0, "\032 BACK", NULL }, + { MT_CALLBACK, SD_NORMAL, "NORMAL", menu_scanning_speed_cb}, // order must match definition of enum + { MT_CALLBACK, SD_PRECISE, "PRECISE", menu_scanning_speed_cb}, + { MT_CALLBACK | MT_LOW,SD_FAST, "FAST", menu_scanning_speed_cb}, + { MT_KEYPAD, KM_SAMPLETIME, "\2SAMPLE\0DELAY", "300..30000"}, // item number must match SD_MANUAL + { MT_KEYPAD, KM_OFFSET_DELAY, "\2OFFSET\0DELAY", "300..30000"}, // item number must match SD_MANUAL + { MT_CANCEL, 0, "\032 BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -1511,9 +1511,9 @@ static const menuitem_t menu_trigger[] = { { MT_CALLBACK,T_AUTO, "AUTO", menu_trigger_cb}, { MT_CALLBACK,T_NORMAL, "NORMAL", menu_trigger_cb}, { MT_CALLBACK,T_SINGLE, "SINGLE", menu_trigger_cb}, - { MT_KEYPAD, KM_TRIGGER, "LEVEL", NULL}, - { MT_CALLBACK,T_UP, "UP", menu_trigger_cb}, - { MT_CALLBACK,T_DOWN, "DOWN", menu_trigger_cb}, + { MT_KEYPAD, KM_TRIGGER, "\2TRIGGER\0LEVEL", NULL}, + { MT_CALLBACK,T_UP, "\2UP\0EDGE", menu_trigger_cb}, + { MT_CALLBACK,T_DOWN, "\2DOWN\0EDGE", menu_trigger_cb}, { MT_CANCEL, 0, "\032 BACK",NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; From f000c4bfab1670028f3c5af31dc5eb766e2070d8 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 7 Jul 2020 17:38:27 +0200 Subject: [PATCH 2/2] Repaired correct_RSSI calculation and timing --- sa_core.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/sa_core.c b/sa_core.c index edc58c1..4009446 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1311,7 +1311,7 @@ static const int wfm_modulation[5] = { 0, 190, 118, -118, -190 }; // 5 step wi deviceRSSI_t age[POINTS_COUNT]; -static float old_a = -150; +static float old_a = -150; // cached value to reduce writes to level registers static float correct_RSSI; systime_t start_of_sweep_timestamp; @@ -1432,6 +1432,15 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M // chThdSleepMicroseconds(200); } } + // Calculate the RSSI correction for later use + if (MODE_INPUT(setting.mode) && (i == 0 || setting.frequency_step != 0) ){ // only cases where the value can change on 0 point of sweep + correct_RSSI = getSI4432_RSSI_correction() + + get_level_offset() + + get_attenuation() + - get_signal_path_loss() + - setting.offset + + get_frequency_correction(f); + } // -------------------------------- Acquisition loop for one requested frequency covering spur avoidance and vbwsteps ------------------------ pureRSSI_t RSSI = float_TO_PURE_RSSI(-150.0); @@ -1452,16 +1461,6 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M offs = (int)(offs * actual_rbw_x10/10.0); lf = (uint32_t)(f + offs); } - // Calculate the RSSI correction for later use - if (i == 0){ // only cases where the value can change on 0 point of sweep - correct_RSSI = getSI4432_RSSI_correction(); - if (setting.frequency_step != 0 ) - correct_RSSI+= get_level_offset() - + get_attenuation() - - get_signal_path_loss() - - setting.offset - + get_frequency_correction(f); - } // --------------- Set all the LO's ------------------------ if (/* MODE_INPUT(setting.mode) && */ i > 0 && FREQ_IS_CW()) // In input mode in zero span mode after first setting of the LO's