From 09ab2f583cd357472c8ed6f0c828230d63c785c8 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 2 May 2021 07:53:24 +0200 Subject: [PATCH] Reverted back to old si4468.c code --- nanovna.h | 1 + plot.c | 19 ++++++++++++++++++- sa_core.c | 7 ++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/nanovna.h b/nanovna.h index 734936f..941adb7 100644 --- a/nanovna.h +++ b/nanovna.h @@ -76,6 +76,7 @@ #define __LISTEN__ #define __CHANNEL_POWER__ #define __LIMITS__ +#define __MCU_CLOCK_SHIFT__ #ifdef TINYSA4 #define __HARMONIC__ #define __VBW__ diff --git a/plot.c b/plot.c index 810c6a5..60b6a4d 100644 --- a/plot.c +++ b/plot.c @@ -376,6 +376,23 @@ dBm_to_Watt(const float v) return logf(v*1000.0)*(10.0/logf(10.0)); } +static float fast_expf(float x) +{ + union { float f; int32_t i; } v; + v.i = (int32_t)(12102203.0f*x) + 0x3F800000; + int32_t m = (v.i >> 7) & 0xFFFF; // copy mantissa +#if 1 + // cubic spline approximation + // empirical values for small maximum relative error (8.34e-5): + v.i += ((((((((1277*m) >> 14) + 14825)*m) >> 14) - 79749)*m) >> 11) - 626; +#else + // quartic spline approximation + // empirical values for small maximum relative error (1.21e-5): + v.i += (((((((((((3537*m) >> 16) + 13668)*m) >> 18) + 15817)*m) >> 14) - 80470)*m) >> 11); +#endif + return v.f; +} + static void trace_into_index_x_array(index_x_t *x, uint16_t points){ // Not need update if index calculated for this points count @@ -417,7 +434,7 @@ trace_into_index_y_array(index_y_t *y, float *array, int points) int max = NGRIDY * GRIDY, i; for (i=0;i 40000000){ uint32_t tf = lf; + while (tf > 240000000) tf -= 240000000; // Wrap between 0-48MHz while (tf > 48000000) tf -= 48000000; // Wrap between 0-48MHz if (tf < 20000000 ) set_below = true;