From 6edd5b2dfeb3ddf7baf50d62fd178eef1bb2ff42 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sat, 12 Jun 2021 13:19:03 +0200 Subject: [PATCH] tinySA3 harmonic mode --- nanovna.h | 3 ++- sa_core.c | 25 +++++++++++++++++++++++++ ui_sa.c | 7 +++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/nanovna.h b/nanovna.h index 926057a..c49e39d 100644 --- a/nanovna.h +++ b/nanovna.h @@ -94,6 +94,7 @@ //#define __FFT_VBW__ //#define __FFT_DECONV__ #else +#define __HARMONIC__ #endif #ifdef TINYSA3 @@ -1013,7 +1014,7 @@ typedef struct setting freq_t frequency_var; freq_t frequency_IF; freq_t frequency_offset; -#define FREQUENCY_SHIFT 100000000 // 100MHz upconversion maximum +#define FREQUENCY_SHIFT ((freq_t)100000000) // 100MHz upconversion maximum float trace_scale; float trace_refpos; marker_t _markers[MARKERS_MAX]; diff --git a/sa_core.c b/sa_core.c index 1aa6a0c..3a1c33a 100644 --- a/sa_core.c +++ b/sa_core.c @@ -142,6 +142,11 @@ float channel_power_watt[3]; //int setting.refer = -1; // Off by default const uint32_t reffer_freq[] = {30000000, 15000000, 10000000, 4000000, 3000000, 2000000, 1000000}; +#ifdef TINYSA3 +const freq_t fh_low[] = { 240000000, 480000000, 720000000, 960000000, 1200000000 }; +const freq_t fh_high[] = { 480000000, 960000000, 1920000000, 2880000000, 3840000000 }; +#endif + uint8_t in_selftest = false; void update_min_max_freq(void) @@ -172,6 +177,19 @@ void update_min_max_freq(void) case M_HIGH: minFreq = HIGH_MIN_FREQ_MHZ * 1000000; maxFreq = HIGH_MAX_FREQ_MHZ * 1000000; +#ifdef __HARMONIC__ + if (setting.harmonic) { + minFreq = setting.harmonic * HIGH_MIN_FREQ_MHZ * 1000000; + if (setting.harmonic < 4) + maxFreq = setting.harmonic * HIGH_MAX_FREQ_MHZ * 1000000; + else + maxFreq = 2880000000; + } + if (get_sweep_frequency(ST_START) < minFreq) + set_sweep_frequency(ST_START, minFreq); + if (get_sweep_frequency(ST_STOP) > maxFreq) + set_sweep_frequency(ST_STOP, maxFreq); +#endif break; case M_GENHIGH: #ifdef TINYSA4 @@ -1082,11 +1100,14 @@ void set_harmonic(int h) if ((freq_t)(setting.harmonic * 135000000)+config.frequency_IF1 > minFreq) minFreq = setting.harmonic * 135000000 + config.frequency_IF1; #endif +#if 0 maxFreq = 9900000000.0; if (setting.harmonic != 0 && (MAX_LO_FREQ * setting.harmonic + config.frequency_IF1 )< 9900000000.0) maxFreq = (MAX_LO_FREQ * setting.harmonic + config.frequency_IF1 ); set_sweep_frequency(ST_START, minFreq); set_sweep_frequency(ST_STOP, maxFreq); +#endif + update_min_max_freq(); } #endif @@ -3251,6 +3272,10 @@ again: // Spur redu else target_f = local_IF+lf; // otherwise to above IF, local_IF == 0 in high mode #ifdef __SI4432__ +#ifdef __HARMONIC__ + if (setting.harmonic) + target_f /= setting.harmonic; +#endif set_freq (SI4432_LO, target_f); // otherwise to above IF #endif #ifdef __ADF4351__ diff --git a/ui_sa.c b/ui_sa.c index 9943ab4..6fa09fd 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -2542,6 +2542,9 @@ static const menuitem_t menu_settings3[] = { MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"}, { MT_CALLBACK, 0 , "CLEAR\nCONFIG", menu_clearconfig_cb}, { MT_ADV_CALLBACK, 0, "PULSE\nHIGH", menu_settings_pulse_acb}, +#ifdef __HARMONIC__ + { MT_SUBMENU | MT_HIGH,0, "HARMONIC", menu_harmonic}, +#endif #ifdef __USE_SERIAL_CONSOLE__ { MT_SUBMENU, 0, "CONNECTION", menu_connection}, #endif @@ -2674,7 +2677,7 @@ static const menuitem_t menu_settings[] = #ifdef __USE_SERIAL_CONSOLE__ { MT_SUBMENU, 0, "CONNECTION", menu_connection}, #endif - #else +#else { MT_SUBMENU | MT_LOW,0, "MIXER\nDRIVE", menu_lo_drive}, #endif { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings2}, @@ -3106,7 +3109,7 @@ set_numeric_value(void) set_sweep_frequency(ST_START, uistat.freq_value - (setting.frequency_offset - FREQUENCY_SHIFT)); break; case KM_STOP: - set_sweep_frequency(ST_STOP, uistat.freq_value - (setting.frequency_offset - FREQUENCY_SHIFT)); + set_sweep_frequency(ST_STOP, (freq_t)(uistat.freq_value - (setting.frequency_offset - FREQUENCY_SHIFT))); break; case KM_CENTER: set_sweep_frequency(ST_CENTER, uistat.freq_value - (setting.frequency_offset - FREQUENCY_SHIFT));