From 65f6118b8abf3178d5b86e4280b4685ed6aa6ea7 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 13 Dec 2022 12:51:03 +0100 Subject: [PATCH] Check calibration levels --- sa_cmd.c | 8 ++++---- sa_core.c | 15 +++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/sa_cmd.c b/sa_cmd.c index 2da7f5e..7645e36 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -978,7 +978,7 @@ VNA_SHELL_FUNCTION(cmd_z) return; } if (argc == 1) { - setting.step_delay = atoi(argv[0]); + setting.step_delay = my_atoi(argv[0]); dirty = true; } } @@ -990,7 +990,7 @@ VNA_SHELL_FUNCTION(cmd_n) return; } if (argc == 1) { - setting.offset_delay = atoi(argv[0]); + setting.offset_delay = my_atoi(argv[0]); dirty = true; } } @@ -1321,8 +1321,8 @@ again: switch (m) { default: goto usage; case 's': test_output_switch = *a - '0'; break; - case 'd': test_output_drive = atoi(a); break; - case 'a': test_output_attenuate = atoi(a); break; + case 'd': test_output_drive = my_atoi(a); break; + case 'a': test_output_attenuate = my_atoi(a); break; #ifdef TINYSA4 case 'p': test_path = *a - '0'; break; #endif diff --git a/sa_core.c b/sa_core.c index 5ecb87f..641deba 100644 --- a/sa_core.c +++ b/sa_core.c @@ -18,6 +18,7 @@ #include "si4432.h" // comment out for simulation //#endif #include "stdlib.h" +//#define TINYSA4 #pragma GCC push_options #ifdef TINYSA4 @@ -2795,7 +2796,7 @@ void interpolate_maximum(int m) const INTER_TYPE y1 = ref_marker_levels[idx - 1]; const INTER_TYPE y2 = ref_marker_levels[idx + 0]; const INTER_TYPE y3 = ref_marker_levels[idx + 1]; - const INTER_TYPE d = abs(delta_Hz) * 0.5 * (y1 - y3) / ((y1 - (2 * y2) + y3) + 1e-12); + const INTER_TYPE d = fabs(delta_Hz) * 0.5 * (y1 - y3) / ((y1 - (2 * y2) + y3) + 1e-12); //const float bin = (float)idx + d; markers[m].frequency += d; } @@ -7450,7 +7451,6 @@ void calibrate(void) { int local_test_status; int old_sweep_points = setting._sweep_points; - reset_calibration(); #ifdef TINYSA4 int old_ultra = config.ultra; config.ultra = true; @@ -7516,6 +7516,7 @@ void calibrate(void) #endif #endif + reset_calibration(); in_calibration = true; for (calibration_stage = CS_NORMAL; calibration_stage < CS_MAX ; calibration_stage++) { for (int k = 0; k<3; k++) { @@ -7594,7 +7595,7 @@ void calibrate(void) local_test_status = test_validate(test_case); calibration_busy(); } - local_test_status = TS_PASS; + local_test_status = TS_PASS; // Must be forced because test_validate calculates pass band wrong #else // set_RBW(power_rbw[j]); // set_sweep_points(21); @@ -7634,7 +7635,13 @@ void calibrate(void) local_test_status = test_validate(test_case); // Validate test also sets attenuation if zero span #endif #endif - if (calibration_stage == CS_NORMAL && peakLevel < -40) { + if ((calibration_stage == CS_NORMAL && peakLevel < -40) +#ifdef TINYSA4 + || (calibration_stage == CS_LNA && peakLevel < -40) + || (calibration_stage == CS_ULTRA && peakLevel < -40) + || (calibration_stage == CS_DIRECT && peakLevel < direct_level - 10) +#endif + ) { #ifdef TINYSA4 low_level: #endif