diff --git a/main.c b/main.c index d127fd6..55b826f 100644 --- a/main.c +++ b/main.c @@ -517,6 +517,7 @@ static long_t my_atoi(const char *p) // default dec radix freq_t my_atoui(const char *p) { + int d = 1; freq_t value = 0, radix = 10, c; if (*p == '+') p++; if (*p == '0') { @@ -530,17 +531,23 @@ freq_t my_atoui(const char *p) } calculate: while (1) { - c = *p++ - '0'; - // c = to_upper(*p) - 'A' + 10 + c = *p++; + if (c == '.') { d = 0; continue; } + c = c - '0'; if (c >= 'A' - '0') c = (c&(~0x20)) - ('A' - '0') + 10; if (c >= radix) break; + if (d<=0) d--; value = value * radix + c; } + if (d == 1) + d = 0; switch (*(--p)) { - case 'k': value *= 1000; break; - case 'M': value *= 1000000; break; - case 'G': value *= 1000000000; break; + case 'k': d += 3; break; + case 'M': d += 6; break; + case 'G': d += 9; break; } + while (d-->0) + value *= radix; return value; } @@ -556,7 +563,7 @@ my_atof(const char *p) while (_isdigit((int)*p)) p++; if (*p == '.') { - float d = 1.0f; + float d = 1.0; p++; while (_isdigit((int)*p)) { d /= 10; @@ -1224,6 +1231,8 @@ update_marker_index(void) for (m = 0; m < MARKERS_MAX; m++) { if (!markers[m].enabled) continue; + if (markers[m].mtype & M_STORED) + continue; freq_t f = markers[m].frequency; if (f == 0) idx = markers[m].index; // Not need update index in no freq else if (f < fstart) idx = 0; diff --git a/nanovna.h b/nanovna.h index cdc960a..0899e74 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1387,6 +1387,7 @@ extern void ADF4351_CP(int p); extern void ADF4351_modulo(int m); extern void ADF4351_csr(int c); extern void ADF4351_fastlock(int c); +extern void ADF4351_recalculate_PFDRFout(void); extern int SI4463_R; extern int64_t ADF4350_modulo; extern void SI446x_set_AGC_LNA(uint8_t v); diff --git a/sa_core.c b/sa_core.c index a1e9ea3..d8f9638 100644 --- a/sa_core.c +++ b/sa_core.c @@ -425,6 +425,7 @@ void set_30mhz(freq_t f) if (f < 29000000 || f > 31000000) return; config.setting_frequency_30mhz = f; + ADF4351_recalculate_PFDRFout(); config_save(); dirty = true; update_grid(); @@ -1420,7 +1421,7 @@ static const struct { { 100, 600, 120, 100, -115}, { 30, 1100, 300, 100, -120}, { 10, 5000, 600, 100, -122}, - { 3, 10000, 3000, 100, -125} + { 3, 14000, 3000, 100, -125} }; #endif @@ -2103,10 +2104,15 @@ void interpolate_maximum(int m) if (idx > 0 && idx < sweep_points-1) { const int32_t delta_Hz = (int64_t)frequencies[idx + 0] - frequencies[idx + 1]; - const float y1 = actual_t[idx - 1]; - const float y2 = actual_t[idx + 0]; - const float y3 = actual_t[idx + 1]; - const float d = abs(delta_Hz) * 0.5f * (y1 - y3) / ((y1 - (2 * y2) + y3) + 1e-12f); +#ifdef TINYSA4 +#define INTER_TYPE double +#else +#define INTER_TYPE float +#endif + const INTER_TYPE y1 = actual_t[idx - 1]; + const INTER_TYPE y2 = actual_t[idx + 0]; + const INTER_TYPE y3 = actual_t[idx + 1]; + const INTER_TYPE d = abs(delta_Hz) * 0.5 * (y1 - y3) / ((y1 - (2 * y2) + y3) + 1e-12); //const float bin = (float)idx + d; markers[m].frequency += d; } @@ -2876,7 +2882,7 @@ modulation_again: freq_t local_IF; #ifdef TINYSA4 local_IF = config.frequency_IF1 + STATIC_DEFAULT_SPUR_OFFSET/2; - if (setting.mode == M_LOW && ultra && + if (setting.mode == M_LOW && setting.frequency_step > 0 && ultra && ((f < ULTRA_MAX_FREQ && f > MAX_LO_FREQ - local_IF) || ( f > config.ultra_threshold && f < MIN_BELOW_LO + local_IF)) ) { @@ -4107,29 +4113,6 @@ static bool sweep(bool break_on_operation) while (m < MARKERS_MAX) { if (markers[m].enabled && markers[m].mtype & M_TRACKING) { // Available marker found markers[m].index = max_index[i]; - interpolate_maximum(m); - // markers[m].frequency = frequencies[markers[m].index]; -#if 0 - float v = actual_t[markers[m].index] - 10.0; // -10dB points - int index = markers[m].index; - freq_t f = markers[m].frequency; - uint32_t s = actual_rbw_x10 * 200; // twice the selected RBW - int left = index, right = index; - while (t > 0 && actual_t[t+1] > v && markers[t].frequency > f - s) // Find left point - t--; - if (t > 0) { - left = t; - } - t = setting._sweep_points-1;; - while (t > setting._sweep_points-1 && actual_t[t+1] > v) // find right -3dB point - t++; - if (t > index) { - right = t; - markers[2].frequency = frequencies[t]; - } - -#endif - interpolate_maximum(m); m++; break; // Next maximum diff --git a/si4468.c b/si4468.c index 96100ee..d69e8b1 100644 --- a/si4468.c +++ b/si4468.c @@ -472,6 +472,7 @@ static freq_t prev_actual_freq = 0; void ADF4351_force_refresh(void) { prev_actual_freq = 0; +// old_R = -1; // Force updating from config.actual_frequency_30MHz } void ADF4351_modulo(int m) @@ -542,6 +543,14 @@ void ADF4351_R_counter(int R) ADF4351_Set(0); } +void ADF4351_recalculate_PFDRFout(void){ + int local_r = old_R; + old_R = -1; + ADF4351_R_counter(local_r); +} + + + void ADF4351_mux(int R) { registers[2] &= ~ (((unsigned long)0x7) << 26);