From d781c3e6cd6fbb26cc1cab88ae8605b73d328924 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 26 Feb 2023 13:22:34 +0100 Subject: [PATCH] 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__