diff --git a/chconf.h b/chconf.h index deb0f9e..56a273b 100644 --- a/chconf.h +++ b/chconf.h @@ -48,7 +48,7 @@ * @details Frequency of the system timer that drives the system ticks. This * setting also defines the system tick time unit. */ -#define CH_CFG_ST_FREQUENCY 10000 +#define CH_CFG_ST_FREQUENCY 2000 /** * @brief Time delta constant for the tick-less mode. diff --git a/main.c b/main.c index d0057d9..096593b 100644 --- a/main.c +++ b/main.c @@ -883,7 +883,7 @@ config_t config = { .harmonic_freq_threshold = 300000000, #endif .lcd_palette = LCD_DEFAULT_PALETTE, - .vbat_offset = 500, + .vbat_offset = 220, #ifdef TINYSA4 .frequency_IF1 = DEFAULT_IF, .frequency_IF2 = 0, diff --git a/nanovna.h b/nanovna.h index 5ba9a6c..28e3e70 100644 --- a/nanovna.h +++ b/nanovna.h @@ -300,7 +300,7 @@ extern int32_t frequencyExtra; void set_10mhz(uint32_t f); void set_modulation(int); void set_modulation_frequency(int); -int search_maximum(int m, int center, int span); +int search_maximum(int m, uint32_t center, int span); //extern int setting.modulation; void set_measurement(int); // extern int settingSpeed; diff --git a/sa_core.c b/sa_core.c index a29c445..5046c4a 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1657,17 +1657,17 @@ void update_rbw(void) // calculate the actual_rbw and the vbwSteps (# #define frequency_seatch_gate 60 // 120% of the RBW -int binary_search_frequency(int f) // Search which index in the frequency tabled matches with frequency f using actual_rbw +int binary_search_frequency(uint32_t f) // Search which index in the frequency tabled matches with frequency f using actual_rbw { int L = 0; int R = (sizeof frequencies)/sizeof(int) - 1; - int fmin = f - actual_rbw_x10 * frequency_seatch_gate; - int fplus = f + actual_rbw_x10 * frequency_seatch_gate; + uint32_t fmin = f - actual_rbw_x10 * frequency_seatch_gate; + uint32_t fplus = f + actual_rbw_x10 * frequency_seatch_gate; while (L <= R) { int m = (L + R) / 2; - if ((int)frequencies[m] < fmin) + if (frequencies[m] < fmin) L = m + 1; - else if ((int)frequencies[m] > fplus) + else if (frequencies[m] > fplus) R = m - 1; else return m; // index is m @@ -1693,14 +1693,12 @@ void interpolate_maximum(int m) #define MAX_MAX 4 int -search_maximum(int m, int center, int span) +search_maximum(int m, uint32_t center, int span) { - center = binary_search_frequency(center); - if (center < 0) - return false; - int from = center - span/2; + int center_index = binary_search_frequency(center); + int from = center_index - span/2; int found = false; - int to = center + span/2; + int to = center_index + span/2; int cur_max = 0; // Always at least one maximum int max_index[4]; if (from<0)