From d781c3e6cd6fbb26cc1cab88ae8605b73d328924 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 26 Feb 2023 13:22:34 +0100 Subject: [PATCH 1/3] Segmented working --- main.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- nanovna.h | 18 ++++++++++----- plot.c | 12 ++++++++++ sa_core.c | 11 +++++---- 4 files changed, 99 insertions(+), 11 deletions(-) diff --git a/main.c b/main.c index 2e4a0ca..c9e9406 100644 --- a/main.c +++ b/main.c @@ -1333,6 +1333,9 @@ set_frequencies(freq_t start, freq_t stop, uint16_t points) freq_t getFrequency(uint16_t idx) {return frequencies[idx];} #endif #else +#ifdef __BANDS__ +static uint8_t _f_band_index[POINTS_COUNT]; +#endif static freq_t _f_start; static freq_t _f_delta; static freq_t _f_error; @@ -1341,6 +1344,40 @@ static uint16_t _f_count; static void set_frequencies(freq_t start, freq_t stop, uint16_t points) { +#ifdef __BANDS__ + if (setting.measurement == M_BANDS) { + + freq_t span = 0; + for (int i=0; i= points) + return; + } + else { + b++; + break; + } + } + } while (b < BANDS_MAX); + return; + } +#endif freq_t span = stop - start; _f_start = start; _f_count = (points - 1); @@ -1349,7 +1386,26 @@ set_frequencies(freq_t start, freq_t stop, uint16_t points) setting.frequency_step = _f_delta; dirty = true; } -freq_t getFrequency(uint16_t idx) {return _f_start + _f_delta * idx + (_f_count / 2 + _f_error * idx) / _f_count;} +freq_t getFrequency(uint16_t idx) { +#ifdef __BANDS__ + if (setting.measurement == M_BANDS) { + if (idx >= POINTS_COUNT) + idx = POINTS_COUNT-1; + int b = _f_band_index[idx]; + band_t *bp = &setting.bands[b]; + freq_t f = bp->start + ((bp->end- bp->start) * (idx - bp->start_index)) / (bp->stop_index - bp->start_index) ; + return f; + } else +#endif + return _f_start + _f_delta * idx + (_f_count / 2 + _f_error * idx) / _f_count;} +#endif + +#ifdef __BANDS__ +int getBand(uint16_t idx) { + if (setting.measurement == M_BANDS) + return _f_band_index[idx]; + return 0; +} #endif @@ -1438,6 +1494,17 @@ set_sweep_frequency(int type, freq_t freq) freq_t get_sweep_frequency(int type) { +#ifdef __BANDS__ + if (setting.measurement == M_BANDS) { + switch (type) { + case ST_START: return getFrequency(0); + case ST_STOP: return getFrequency(sweep_points); + case ST_CENTER: return (getFrequency(sweep_points) + getFrequency(0))/2; + case ST_SPAN: return (getFrequency(sweep_points) - getFrequency(0))/2; + case ST_CW: return getFrequency(0); // Should never happen + } + } +#endif // Obsolete, ensure correct start/stop, start always must be < stop if (setting.frequency0 > setting.frequency1) { freq_t t = setting.frequency0; diff --git a/nanovna.h b/nanovna.h index c4b7908..eb2c936 100644 --- a/nanovna.h +++ b/nanovna.h @@ -18,7 +18,7 @@ */ #include "ch.h" -#ifdef TINYSA_F303 +//#ifdef TINYSA_F303 #ifdef TINYSA_F072 #error "Remove comment for #ifdef TINYSA_F303" #endif @@ -26,7 +26,7 @@ #define TINYSA4 #endif #define TINYSA4_PROTO -#endif +//#endif #ifdef TINYSA_F072 #ifdef TINYSA_F303 @@ -1162,10 +1162,12 @@ void spi_init(void); #ifdef __BANDS__ #define BANDS_MAX 8 typedef struct { - bool enabled; - freq_t start; - freq_t end; - float level; + bool enabled; + freq_t start; + freq_t end; + float level; + int start_index; + int stop_index; } band_t; #endif @@ -1449,6 +1451,10 @@ freq_t getFrequency(uint16_t idx); #else freq_t getFrequency(uint16_t idx); #endif +#ifdef __BANDS__ +int getBand(uint16_t idx); +#endif + //#define frequency0 current_props._frequency0 //#define frequency1 current_props._frequency1 #define sweep_points setting._sweep_points diff --git a/plot.c b/plot.c index 8ec445f..4e79e04 100644 --- a/plot.c +++ b/plot.c @@ -1101,6 +1101,18 @@ draw_cell(int m, int n) } } #endif +#ifdef __CHANNEL_POWER__ + if (setting.measurement == M_BANDS) { + c = GET_PALTETTE_COLOR(LCD_TRIGGER_COLOR); + for (x = 0; x < w; x++) { + int idx1 = ((x+x0) * sweep_points) / WIDTH; + int idx2 = ((x+x0+1) * sweep_points) / WIDTH; + if (getBand(idx1) != getBand(idx2) && idx2 < WIDTH-2) { + for (y = 0; y < h; y++) cell_buffer[y * CELLWIDTH + x] = c; + } + } + } +#endif // PULSE; #endif // Draw trigger line diff --git a/sa_core.c b/sa_core.c index 017e4a5..afe5fd3 100644 --- a/sa_core.c +++ b/sa_core.c @@ -4847,6 +4847,12 @@ static bool sweep(bool break_on_operation) #endif if (dirty) { // Calculate new scanning solution +#ifdef __BANDS__ + if (setting.measurement == M_BANDS) { + set_frequencies(0,0,sweep_points); + update_rbw(); + } +#endif sweep_counter = 0; if (get_sweep_frequency(ST_SPAN) < 300000) // Check if AM signal check_for_AM = true; @@ -4879,7 +4885,7 @@ static bool sweep(bool break_on_operation) uint16_t triggered = false; again: // Waiting for a trigger jumps back to here -#ifdef __BANDS__ +#ifdef __BANDS__xx if (setting.measurement == M_BANDS) { do { current_band++; @@ -4897,11 +4903,8 @@ static bool sweep(bool break_on_operation) setting.trigger_level = setting.bands[current_band].level; setting.auto_attenuation = false; } - set_audio_mode(A_PWM); - pwm_stop(); } else { last_band = -1; - set_audio_mode(A_DAC); } #endif #ifdef __BEEP__ From 4ad3b092e2248d6e6a29c62b96c8860d1aa58ec5 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 26 Feb 2023 14:32:13 +0100 Subject: [PATCH 2/3] Multi band under frequency menu --- main.c | 8 ++++---- nanovna.h | 7 +++++-- plot.c | 2 +- sa_core.c | 4 ++-- ui.c | 50 +++++++++++++++++++++++++++++++++++++------------- 5 files changed, 49 insertions(+), 22 deletions(-) diff --git a/main.c b/main.c index c9e9406..2fe87af 100644 --- a/main.c +++ b/main.c @@ -1345,7 +1345,7 @@ static void set_frequencies(freq_t start, freq_t stop, uint16_t points) { #ifdef __BANDS__ - if (setting.measurement == M_BANDS) { + if (setting.multi_band) { freq_t span = 0; for (int i=0; i= POINTS_COUNT) idx = POINTS_COUNT-1; int b = _f_band_index[idx]; @@ -1402,7 +1402,7 @@ freq_t getFrequency(uint16_t idx) { #ifdef __BANDS__ int getBand(uint16_t idx) { - if (setting.measurement == M_BANDS) + if (setting.multi_band) return _f_band_index[idx]; return 0; } @@ -1495,7 +1495,7 @@ freq_t get_sweep_frequency(int type) { #ifdef __BANDS__ - if (setting.measurement == M_BANDS) { + if (setting.multi_band) { switch (type) { case ST_START: return getFrequency(0); case ST_STOP: return getFrequency(sweep_points); diff --git a/nanovna.h b/nanovna.h index eb2c936..8215343 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1229,6 +1229,9 @@ typedef struct setting uint8_t draw_line; // uses the trigger level setting #ifdef TINYSA4 uint8_t lock_display; +#endif +#ifdef __BANDS__ + uint8_t multi_band; #endif uint16_t repeat; // 1...100 uint16_t linearity_step; // range equal POINTS_COUNT @@ -1773,9 +1776,9 @@ void interpolate_maximum(int m); void calibrate_modulation(int modulation, int8_t *correction); enum { - M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_SNR, M_PASS_BAND, M_LINEARITY, M_AM, M_FM, M_THD, M_CP, M_NF_TINYSA, M_NF_STORE, M_NF_VALIDATE, M_NF_AMPLIFIER, M_BANDS, M_DECONV,M_MAX + M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_SNR, M_PASS_BAND, M_LINEARITY, M_AM, M_FM, M_THD, M_CP, M_NF_TINYSA, M_NF_STORE, M_NF_VALIDATE, M_NF_AMPLIFIER, M_DECONV,M_MAX }; -#define MEASUREMENT_TEXT "OFF","IMD","OIP3","PN","SNR","PASS","LIN","AM","FM","THD","CP","NF T","NF S","NF V","NF A","MULTI","DECONF" +#define MEASUREMENT_TEXT "OFF","IMD","OIP3","PN","SNR","PASS","LIN","AM","FM","THD","CP","NF T","NF S","NF V","NF A", "DECONF" enum { T_AUTO, T_NORMAL, T_SINGLE, T_DONE, T_UP, T_DOWN, T_MODE, T_PRE, T_POST, T_MID, T_BEEP, diff --git a/plot.c b/plot.c index 4e79e04..08083a8 100644 --- a/plot.c +++ b/plot.c @@ -1102,7 +1102,7 @@ draw_cell(int m, int n) } #endif #ifdef __CHANNEL_POWER__ - if (setting.measurement == M_BANDS) { + if (setting.multi_band) { c = GET_PALTETTE_COLOR(LCD_TRIGGER_COLOR); for (x = 0; x < w; x++) { int idx1 = ((x+x0) * sweep_points) / WIDTH; diff --git a/sa_core.c b/sa_core.c index afe5fd3..de0e933 100644 --- a/sa_core.c +++ b/sa_core.c @@ -4848,7 +4848,7 @@ static bool sweep(bool break_on_operation) if (dirty) { // Calculate new scanning solution #ifdef __BANDS__ - if (setting.measurement == M_BANDS) { + if (setting.multi_band) { set_frequencies(0,0,sweep_points); update_rbw(); } @@ -4886,7 +4886,7 @@ static bool sweep(bool break_on_operation) again: // Waiting for a trigger jumps back to here #ifdef __BANDS__xx - if (setting.measurement == M_BANDS) { + if (setting.multi_band) { do { current_band++; if (current_band > BANDS_MAX) diff --git a/ui.c b/ui.c index 9df4471..5be9704 100644 --- a/ui.c +++ b/ui.c @@ -1468,8 +1468,8 @@ static const menuitem_t menu_limit_modify[]; static const menuitem_t menu_limit_select[]; #endif #ifdef __BANDS__ -static const menuitem_t menu_BAND_modify[]; -static const menuitem_t menu_BAND_select[]; +static const menuitem_t menu_band_modify[]; +static const menuitem_t menu_band_select[]; #endif static const menuitem_t menu_average[]; static const menuitem_t menu_reffer[]; @@ -2874,9 +2874,9 @@ validate: } break; #endif -#ifdef __BANDS__ +#ifdef __BANDS__xx case M_BANDS: - menu_push_submenu(menu_BAND_select); + menu_push_submenu(menu_band_select); goto leave; break; #endif @@ -3200,9 +3200,24 @@ static UI_FUNCTION_ADV_CALLBACK(menu_band_select_acb) setting.bands[active_band].enabled = true; dirty = true; // BANDs_update(); - menu_push_submenu(menu_BAND_modify); + menu_push_submenu(menu_band_modify); +} + +static UI_FUNCTION_ADV_CALLBACK(menu_multi_band_acb) +{ + (void)item; + (void)data; + if(b){ + b->icon = (setting.multi_band?BUTTON_ICON_CHECK:BUTTON_ICON_NOCHECK) ; + return; + } + dirty = true; + setting.multi_band = ! setting.multi_band; + redraw_request|= REDRAW_AREA | REDRAW_FREQUENCY | REDRAW_CAL_STATUS; + if (setting.multi_band) menu_push_submenu(menu_band_select); } +# #endif extern const menuitem_t menu_marker_select[]; @@ -4158,16 +4173,16 @@ static const menuitem_t menu_limit_select[] = { #endif #ifdef __BANDS__ -static const menuitem_t menu_BAND_modify[] = +static const menuitem_t menu_band_modify[] = { { MT_KEYPAD, KM_BAND_START, "START\n\b%s", "Start"}, { MT_KEYPAD, KM_BAND_END, "STOP\n\b%s", "Stop"}, - { MT_KEYPAD, KM_BAND_LEVEL, "LEVEL\n\b%s", "Level"}, - { MT_CALLBACK,0, "DISABLE", menu_BAND_disable_cb}, + { MT_KEYPAD, KM_BAND_LEVEL, "LEVEL\n\b%s", "Level"}, + { MT_CALLBACK,0, "DISABLE", menu_BAND_disable_cb}, { MT_NONE, 0, NULL, menu_back} // next-> menu_back }; -static const menuitem_t menu_BAND_select[] = { +static const menuitem_t menu_band_select[] = { { MT_ADV_CALLBACK | MT_REPEATS, DATA_STARTS_REPEATS(0,BANDS_MAX), MT_CUSTOM_LABEL, menu_band_select_acb }, #ifdef __USE_SD_CARD__ { MT_CALLBACK, FMT_BND_FILE, "BANDS"S_RARROW"\nSD", menu_sdcard_cb}, @@ -4509,9 +4524,9 @@ static const menuitem_t menu_measure2[] = { #ifdef __NOISE_FIGURE__ { MT_SUBMENU | MT_LOW, 0, "NOISE\nFIGURE", menu_measure_noise_figure}, #endif -#ifdef __BANDS__ -{ MT_ADV_CALLBACK, M_BANDS, "MULTI\nBAND", menu_measure_acb}, -#endif +//#ifdef __BANDS__ +//{ MT_ADV_CALLBACK, M_BANDS, "MULTI\nBAND", menu_measure_acb}, +//#endif #ifdef __FFT_DECONV__ { MT_ADV_CALLBACK, M_DECONV, "DECONV", menu_measure_acb}, #endif @@ -4773,6 +4788,9 @@ static const menuitem_t menu_stimulus[] = { { MT_KEYPAD, KM_CENTER, "CENTER\n\b%s", NULL}, { MT_KEYPAD, KM_SPAN, "SPAN\n\b%s", NULL}, { MT_KEYPAD, KM_CW, "ZERO SPAN", NULL}, +#ifdef __BANDS__ + { MT_ADV_CALLBACK, 0, "MULTI\nBAND", menu_multi_band_acb}, +#endif { MT_SUBMENU,0, "RBW", menu_rbw}, #ifdef __VBW__ { MT_SUBMENU, 0, "VBW", menu_vbw}, @@ -5567,7 +5585,13 @@ redraw_cal_status: } quick_menu_y[max_quick_menu] = y; quick_menu[max_quick_menu++] = (menuitem_t *)NULL; - +#ifdef __BANDS__ + if (setting.multi_band){ + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); + lcd_printf(x, y, "MULTI"); + y += 2*YSTEP + YSTEP/2; + } +#endif #ifdef TINYSA4 if (setting.measurement != M_OFF){ ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); From f91dad70e7145e9388a2aa3c49666791ddbd5145 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 28 Feb 2023 11:22:02 +0100 Subject: [PATCH 3/3] Added multi trace mode --- main.c | 19 ++++++++++++++----- nanovna.h | 3 ++- plot.c | 21 ++++++++++++++++++--- sa_core.c | 12 ++++++------ ui.c | 23 +++++++++++++++++++++-- 5 files changed, 61 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index 2fe87af..c1d834b 100644 --- a/main.c +++ b/main.c @@ -1345,7 +1345,7 @@ static void set_frequencies(freq_t start, freq_t stop, uint16_t points) { #ifdef __BANDS__ - if (setting.multi_band) { + if (setting.multi_band && !setting.multi_trace) { freq_t span = 0; for (int i=0; i= POINTS_COUNT) idx = POINTS_COUNT-1; int b = _f_band_index[idx]; @@ -1402,7 +1402,7 @@ freq_t getFrequency(uint16_t idx) { #ifdef __BANDS__ int getBand(uint16_t idx) { - if (setting.multi_band) + if (setting.multi_band && !setting.multi_trace) return _f_band_index[idx]; return 0; } @@ -1495,12 +1495,21 @@ freq_t get_sweep_frequency(int type) { #ifdef __BANDS__ - if (setting.multi_band) { + if (setting.multi_band && !setting.multi_trace) { switch (type) { case ST_START: return getFrequency(0); case ST_STOP: return getFrequency(sweep_points); case ST_CENTER: return (getFrequency(sweep_points) + getFrequency(0))/2; - case ST_SPAN: return (getFrequency(sweep_points) - getFrequency(0))/2; + case ST_SPAN: + { + freq_t span = 0; + for (int i=0; i BANDS_MAX) @@ -4897,9 +4897,9 @@ static bool sweep(bool break_on_operation) last_band = current_band; set_sweep_frequency(ST_START, setting.bands[current_band].start); set_sweep_frequency(ST_STOP, setting.bands[current_band].end); - set_step_delay(SD_FAST); - set_rbw(8000); - set_sweep_points((setting.bands[current_band].end - setting.bands[current_band].start) / 800000); +// set_step_delay(SD_FAST); +// set_rbw(8000); +// set_sweep_points((setting.bands[current_band].end - setting.bands[current_band].start) / 800000); setting.trigger_level = setting.bands[current_band].level; setting.auto_attenuation = false; } diff --git a/ui.c b/ui.c index 5be9704..468b029 100644 --- a/ui.c +++ b/ui.c @@ -3199,6 +3199,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_band_select_acb) active_band = data; setting.bands[active_band].enabled = true; dirty = true; + update_grid(); // BANDs_update(); menu_push_submenu(menu_band_modify); } @@ -3217,6 +3218,19 @@ static UI_FUNCTION_ADV_CALLBACK(menu_multi_band_acb) if (setting.multi_band) menu_push_submenu(menu_band_select); } +static UI_FUNCTION_ADV_CALLBACK(menu_multi_trace_acb) +{ + (void)item; + (void)data; + if(b){ + b->icon = (setting.multi_trace?BUTTON_ICON_CHECK:BUTTON_ICON_NOCHECK) ; + return; + } + dirty = true; + setting.multi_trace = ! setting.multi_trace; + redraw_request|= REDRAW_AREA | REDRAW_FREQUENCY | REDRAW_CAL_STATUS; +} + # #endif @@ -3358,6 +3372,7 @@ static UI_FUNCTION_CALLBACK(menu_BAND_disable_cb) if (active_band