From 0e3f97c21781f3f357c033de804efbd018dfa7af Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 7 Feb 2021 09:28:13 +0100 Subject: [PATCH] Automatic harmonic mode and some small bugs --- flash.c | 2 +- main.c | 1 + nanovna.h | 3 +++ plot.c | 5 +++-- sa_cmd.c | 1 + sa_core.c | 36 +++++++++++++++++++----------------- 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/flash.c b/flash.c index ada40b1..bb90a12 100644 --- a/flash.c +++ b/flash.c @@ -72,7 +72,7 @@ checksum(const void *start, size_t len) uint32_t value = 0; while (p < tail) { value = __ROR(value, 31) + *p++; - if (SDU1.config->usbp->state == USB_ACTIVE) shell_printf("%x\r\n", value); + // if (SDU1.config->usbp->state == USB_ACTIVE) shell_printf("%x\r\n", value); } return value; } diff --git a/main.c b/main.c index f53542a..418ebbb 100644 --- a/main.c +++ b/main.c @@ -356,6 +356,7 @@ VNA_SHELL_FUNCTION(cmd_pause) (void)argc; (void)argv; pause_sweep(); + draw_cal_status(); } VNA_SHELL_FUNCTION(cmd_resume) diff --git a/nanovna.h b/nanovna.h index 5a97791..f9bce3e 100644 --- a/nanovna.h +++ b/nanovna.h @@ -72,6 +72,8 @@ #define DEFAULT_MAX_FREQ ((freq_t)800000000) #define HIGH_MIN_FREQ_MHZ 136// 825 #define HIGH_MAX_FREQ_MHZ 1130 +#define ULTRA_MAX_FREQ 5290000000ULL +#define LOW_MAX_FREQ 800000000ULL #endif /* * main.c @@ -874,6 +876,7 @@ typedef struct setting int extra_lna; int ultra; int R; + uint32_t dummy; uint32_t checksum; // must be last }setting_t; diff --git a/plot.c b/plot.c index dedd76c..b58242d 100644 --- a/plot.c +++ b/plot.c @@ -2131,9 +2131,10 @@ static void cell_draw_marker_info(int x0, int y0) plot_printf(buf, sizeof buf, "DEPTH: %3d%%", depth); goto show_computed; } else if (setting.measurement == M_FM){ - freq_t dev = ( markers[2].frequency - markers[1].frequency - actual_rbw_x10 * 100 ) >> 1; - if (dev < 0 ) + freq_t dev = markers[1].frequency + actual_rbw_x10 * 100; // Temp value to prevent calculation of negative deviation + if ( markers[2].frequency < dev) break; + dev = ( markers[2].frequency - dev ) >> 1; plot_printf(buf, sizeof buf, "DEVIATION:%6.1LqHz", dev); goto show_computed; } else if (setting.measurement == M_THD && markers[0].enabled && (markers[0].index << 5) > sweep_points ) { diff --git a/sa_cmd.c b/sa_cmd.c index b52e8e0..fdbbd3a 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -792,6 +792,7 @@ VNA_SHELL_FUNCTION(cmd_scanraw) } streamPut(shell_stream, '}'); setting.frequency_step = old_step; + dirty = true; redraw_request = 0; // disable screen update in this mode } diff --git a/sa_core.c b/sa_core.c index d37e976..837a4ae 100644 --- a/sa_core.c +++ b/sa_core.c @@ -71,9 +71,9 @@ void update_min_max_freq(void) case M_LOW: minFreq = 0; if (config.ultra) - maxFreq = 5290000000ULL; + maxFreq = 9900000000.0; // ULTRA_MAX_FREQ; // make use of harmonic mode above ULTRA_MAX_FREQ else - maxFreq = 850000000; + maxFreq = LOW_MAX_FREQ; break; #ifdef __ULTRA__ case M_ULTRA: @@ -83,7 +83,7 @@ void update_min_max_freq(void) #endif case M_GENLOW: minFreq = 0; - maxFreq = DEFAULT_MAX_FREQ; + maxFreq = LOW_MAX_FREQ; break; case M_HIGH: minFreq = HIGH_MIN_FREQ_MHZ * 1000000; @@ -119,7 +119,7 @@ void reset_settings(int m) setting.level = SL_GENLOW_LEVEL_MIN + SL_GENLOW_LEVEL_RANGE; // This is the level with above settings. setting.rbw_x10 = 0; setting.average = 0; - setting.harmonic = 0; + setting.harmonic = 3; // Automatically used when above ULTRA_MAX_FREQ setting.show_stored = 0; setting.auto_attenuation = false; setting.subtract_stored = 0; @@ -175,10 +175,10 @@ void reset_settings(int m) case M_LOW: set_sweep_frequency(ST_START, minFreq); set_sweep_frequency(ST_STOP, maxFreq); - if (config.ultra) - set_sweep_frequency(ST_STOP, 2900000000); // TODO <----------------- temp ---------------------- - else - set_sweep_frequency(ST_STOP, 800000000); // TODO <----------------- temp ---------------------- +// if (config.ultra) +// set_sweep_frequency(ST_STOP, 2900000000); // TODO <----------------- temp ---------------------- +// else + set_sweep_frequency(ST_STOP, LOW_MAX_FREQ); // TODO <----------------- temp ---------------------- setting.attenuate_x2 = 10; setting.auto_attenuation = true; setting.sweep_time_us = 0; @@ -737,11 +737,13 @@ void toggle_spur(void) void set_harmonic(int h) { setting.harmonic = h; +#if 0 minFreq = 684000000.0; if ((freq_t)(setting.harmonic * 135000000)+config.frequency_IF1 > minFreq) minFreq = setting.harmonic * 135000000 + config.frequency_IF1; - maxFreq = 4290000000.0; - if (setting.harmonic != 0 && (4400000000.0 * setting.harmonic + config.frequency_IF1 )< 4360000000.0) +#endif + maxFreq = 9900000000.0; + if (setting.harmonic != 0 && (4400000000.0 * setting.harmonic + config.frequency_IF1 )< 9900000000.0) maxFreq = (4400000000.0 * setting.harmonic + config.frequency_IF1 ); set_sweep_frequency(ST_START, minFreq); set_sweep_frequency(ST_STOP, maxFreq); @@ -2120,7 +2122,7 @@ modulation_again: // if (setting.step_delay_mode == SD_PRECISE) // offs>>=1; // steps of a quarter rbw // if (lf > -offs) // No negative frequencies - if (offs >= 0 || lf > -offs) + if (offs >= 0 || lf > (unsigned int)(-offs)) lf += offs; // if (lf > 4290000000U) // lf = 0; @@ -2262,7 +2264,7 @@ modulation_again: #define TXCO_DIV3 10000000 if (setting.R == 0) { - if (lf < 850000000U && lf >= TXCO_DIV3) { + if (lf < LOW_MAX_FREQ && lf >= TXCO_DIV3) { freq_t tf = ((lf + actual_rbw_x10*100) / TCXO) * TCXO; if (tf + actual_rbw_x10*100 >= lf && tf < lf + actual_rbw_x10*100) { // ADF4351_R_counter(8); no impact @@ -2279,7 +2281,7 @@ modulation_again: else ADF4351_R_counter(setting.R); - +#if 0 // No 72MHz spur avoidance yet if (false) { // Avoid 72MHz spur #define SPUR 2 * 72000000 freq_t tf = ((lf + actual_rbw_x10*100) / SPUR) * SPUR; @@ -2314,8 +2316,8 @@ modulation_again: #endif } } - #endif +#endif // __ADF4351__ #if 0 freq_t target_f; if (!setting.tracking && S_STATE(setting.below_IF)) { // if in low input mode and below IF @@ -2326,7 +2328,7 @@ modulation_again: } else target_f = local_IF+lf; // otherwise to above IF #endif - if (setting.harmonic) { + if (setting.harmonic && f > ULTRA_MAX_FREQ) { target_f /= setting.harmonic; } set_freq(ADF4351_LO, target_f); @@ -2339,7 +2341,7 @@ modulation_again: goto correct_min; } correct_plus: - if (setting.harmonic) { + if (setting.harmonic && f > ULTRA_MAX_FREQ) { error_f *= setting.harmonic; } if (error_f > actual_rbw_x10 * 5) //RBW / 4 @@ -2351,7 +2353,7 @@ modulation_again: goto correct_plus; } correct_min: - if (setting.harmonic) { + if (setting.harmonic && f > ULTRA_MAX_FREQ) { error_f *= setting.harmonic; } if ( error_f < - actual_rbw_x10 * 5) //RBW / 4