From abe80d56417a2643a10ee97bb812160953cb7dc3 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 24 Feb 2021 14:50:40 +0100 Subject: [PATCH] Selftest working --- plot.c | 2 +- sa_core.c | 52 ++++++++++++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/plot.c b/plot.c index b58242d..1f9c10a 100644 --- a/plot.c +++ b/plot.c @@ -119,7 +119,7 @@ float2int(float v) void update_grid(void) { - freq_t gdigit = 100000000; + freq_t gdigit = 1000000000; freq_t fstart = get_sweep_frequency(ST_START); freq_t fspan = get_sweep_frequency(ST_SPAN); freq_t grid; diff --git a/sa_core.c b/sa_core.c index 1431edf..104e01c 100644 --- a/sa_core.c +++ b/sa_core.c @@ -589,7 +589,7 @@ void set_attenuation(float a) // Is used both in low output mode and high/ } a = -a; } else { - if (setting.mode == M_LOW && a > 31) { + if (setting.mode == M_LOW && a > 31.5) { setting.atten_step = 1; a = a - RECEIVE_SWITCH_ATTENUATION; } else if (setting.mode == M_HIGH && a > 0) { @@ -3461,7 +3461,7 @@ enum { #define W2P(w) (sweep_points * w / 100) // convert width in % to actual sweep points #ifdef TINYSA4 -#define CAL_LEVEL -29 +#define CAL_LEVEL -30 #else #define CAL_LEVEL -25 #endif @@ -3480,13 +3480,13 @@ const test_case_t test_case [] = {// Condition Preparation Center Span Pass Width(%)Stop {TC_BELOW, TP_SILENT, 0.005, 0.01, 0, 0, 0}, // 1 Zero Hz leakage {TC_BELOW, TP_SILENT, 0.015, 0.01, -30, 0, 0}, // 2 Phase noise of zero Hz - {TC_SIGNAL, TP_30MHZ, 30, 7, -29, 10, -90 }, // 3 + {TC_SIGNAL, TP_30MHZ, 30, 7, -30, 10, -90 }, // 3 {TC_SIGNAL, TP_30MHZ, 60, 7, -70, 10, -90 }, // 4 #define TEST_SILENCE 4 {TC_BELOW, TP_SILENT, 200, 100, -75, 0, 0}, // 5 Wide band noise floor low mode {TC_BELOW, TPH_SILENT, 600, 720, -75, 0, 0}, // 6 Wide band noise floor high mode {TC_SIGNAL, TP_10MHZEXTRA, 30, 14, -20, 27, -80 }, // 7 BPF loss and stop band - {TC_FLAT, TP_10MHZEXTRA, 30, 8, -18, 9, -60}, // 8 BPF pass band flatness + {TC_FLAT, TP_10MHZEXTRA, 30, 14, -18, 9, -60}, // 8 BPF pass band flatness {TC_BELOW, TP_30MHZ, 400, 60, -75, 0, -75}, // 9 LPF cutoff {TC_SIGNAL, TP_10MHZ_SWITCH,20, 7, -39, 10, -60 }, // 10 Switch isolation using high attenuation {TC_DISPLAY, TP_30MHZ, 30, 0, -25, 145, -60 }, // 11 Measure atten step accuracy @@ -3586,7 +3586,7 @@ int validate_signal_within(int i, float margin) return TS_CRITICAL; } test_fail_cause[i] = "Frequency "; - if (peakFreq < test_case[i].center * 1000000 - 600000 || test_case[i].center * 1000000 + 600000 < peakFreq ) + if (peakFreq < test_case[i].center * 1000000 - 1000000 || test_case[i].center * 1000000 + 1000000 < peakFreq ) return TS_FAIL; test_fail_cause[i] = ""; return TS_PASS; @@ -3641,37 +3641,41 @@ int validate_flatness(int i) { const float atten_step[7] = { 0.0, 0.5, 1.0, 2.0, 4.0, 8.0, 16.0 }; int validate_atten(int i) { + int status = TS_PASS; float reference_peak_level = 0.0; test_fail_cause[i] = "Attenuator "; // for (int j= 0; j < 64; j++ ) { for (int j= 0; j < 7; j++ ) { -// set_attenuation(((float)j)/2.0); + // set_attenuation(((float)j)/2.0); set_attenuation(atten_step[j]); float summed_peak_level = 0; #define ATTEN_TEST_SWEEPS 5 for (int k=0; k= ATTEN_TEST_CRITERIA) - return(TS_FAIL); + // shell_printf("Attenuation %.2fdB, measured level %.2fdBm, delta %.2fdB\n\r",((float)j)/2.0, summed_peak_level, summed_peak_level - reference_peak_level); + // shell_printf("Attenuation %.2fdB, measured level %.2fdBm, delta %.2fdB\n\r",atten_step[j], summed_peak_level, summed_peak_level - reference_peak_level); +#define ATTEN_TEST_CRITERIA 0.5 + if (summed_peak_level - reference_peak_level <= -ATTEN_TEST_CRITERIA || summed_peak_level - reference_peak_level >= ATTEN_TEST_CRITERIA) { + status = TS_FAIL; + // draw_all(true); + } } } - test_fail_cause[i] = ""; - return(TS_PASS); + if (status == TS_PASS) + test_fail_cause[i] = ""; + return(status); } int validate_display(int tc) @@ -4199,7 +4203,7 @@ void calibrate(void) goto quit; } else { #ifdef TINYSA4 - set_actual_power(-29.0); // Should be -23.5dBm (V0.2) OR 25 (V0.3) + set_actual_power(-30.0); // Should be -23.5dBm (V0.2) OR 25 (V0.3) #else set_actual_power(-25.0); // Should be -23.5dBm (V0.2) OR 25 (V0.3) #endif