diff --git a/main.c b/main.c index e8efe39..cf2e39c 100644 --- a/main.c +++ b/main.c @@ -87,9 +87,6 @@ static long_t my_atoi(const char *p); uint8_t sweep_mode = SWEEP_ENABLE; uint16_t sweep_once_count = 1; -#ifdef __GUARD__ -uint16_t current_guard = 0; -#endif uint16_t redraw_request = 0; // contains REDRAW_XXX flags // Version text, displayed in Config->Version menu, also send by info command const char * const info_about[]={ @@ -180,30 +177,7 @@ static THD_FUNCTION(Thread1, arg) } else #endif { -#ifdef __GUARD__ - if (setting.measurement == M_GUARD) { - while(!setting.guards[current_guard].enabled) { - current_guard++; - if (current_guard > GUARDS_MAX) - current_guard = 0; - } - if (setting.guards[current_guard].end > setting.guards[current_guard].start) { - set_sweep_frequency(ST_START, setting.guards[current_guard].start); - set_sweep_frequency(ST_STOP, setting.guards[current_guard].end); - set_rbw(8000); - set_sweep_points((setting.guards[current_guard].end - setting.guards[current_guard].start) / 800000); - } - DAC->DHR12R1 = 0; - } -#endif completed = sweep(true); -#ifdef __GUARD__ - if (setting.measurement == M_GUARD) { - current_guard++; - if (current_guard>=GUARDS_MAX) - current_guard = 0; - } -#endif if (sweep_once_count>1) { sweep_once_count--; } else diff --git a/sa_core.c b/sa_core.c index 45e178c..4f22808 100644 --- a/sa_core.c +++ b/sa_core.c @@ -67,6 +67,10 @@ freq_t maxFreq = 520000000; static float old_a = -150; // cached value to reduce writes to level registers int spur_gate = 100; +#ifdef __GUARD__ +uint16_t current_guard = 0; +#endif + #ifdef __ULTRA__ freq_t ultra_start; //bool ultra; @@ -4860,6 +4864,25 @@ static bool sweep(bool break_on_operation) clear_marker_cache(); #endif again: // Waiting for a trigger jumps back to here + +#ifdef __GUARD__ + if (setting.measurement == M_GUARD) { + do { + current_guard++; + if (current_guard > GUARDS_MAX) + current_guard = 0; + } + while(!setting.guards[current_guard].enabled); + if (setting.guards[current_guard].end > setting.guards[current_guard].start) { + set_sweep_frequency(ST_START, setting.guards[current_guard].start); + set_sweep_frequency(ST_STOP, setting.guards[current_guard].end); + set_rbw(8000); + set_sweep_points((setting.guards[current_guard].end - setting.guards[current_guard].start) / 800000); + } + DAC->DHR12R1 = 0; + } +#endif + setting.measure_sweep_time_us = 0; // start measure sweep time // start_of_sweep_timestamp = chVTGetSystemTimeX(); // Will be set in perform @@ -5310,7 +5333,12 @@ static volatile int dummy; goto sweep_again; // Keep repeating sweep loop till user aborts by input } // --------------- check if maximum is above trigger level ----------------- - +#ifdef __GUARD__ + if (setting.measurement == M_GUARD) { + if (measured[peakTrace][peakIndex] < setting.guards[current_guard].level) + goto again; + } +#endif if (setting.trigger != T_AUTO && setting.frequency_step > 0) { // Trigger active if (measured[peakTrace][peakIndex] < setting.trigger_level) { goto again; // not yet, sweep again diff --git a/ui.c b/ui.c index e20816f..44a3e83 100644 --- a/ui.c +++ b/ui.c @@ -5227,17 +5227,17 @@ set_numeric_value(void) case KM_GUARD_START: setting.guards[active_guard].start = uistat.freq_value - (setting.frequency_offset - FREQUENCY_SHIFT); dirty = true; - guards_update(); +// guards_update(); break; case KM_GUARD_END: setting.guards[active_guard].end = uistat.freq_value - (setting.frequency_offset - FREQUENCY_SHIFT); dirty = true; - guards_update(); +// guards_update(); break; case KM_GUARD_LEVEL: setting.guards[active_guard].level = to_dBm(uistat.value); dirty = true; - guards_update(); +// guards_update(); break; #endif case KM_NOISE: