diff --git a/main.c b/main.c index ee36749..06a948e 100644 --- a/main.c +++ b/main.c @@ -1012,10 +1012,13 @@ config_t config = { .ultra_threshold = 750000000, .low_level_offset = 100.0, // Uncalibrated .high_level_offset = 100.0, // Uncalibrated + .lna_level_offset = 100, .low_level_output_offset = 0.0, // Uncalibrated .high_level_output_offset = 0.0, // Uncalibrated - .correction_frequency[0] = { 10000, 100000, 200000, 500000, 30000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, - .correction_value[0] = { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 }, + .correction_frequency = {{ 1000000, 500000000, 1000000000, 1500000000, 2000000000, 2500000000, 3000000000, 3500000000, 4000000000, 4500000000, 5000000000, 5500000000, 6000000000, 6500000000, 7000000000, 7500000000, 8000000000, 8500000000, 9000000000, 10000000000 }, + { 1000000, 500000000, 1000000000, 1500000000, 2000000000, 2500000000, 3000000000, 3500000000, 4000000000, 4500000000, 5000000000, 5500000000, 6000000000, 6500000000, 7000000000, 7500000000, 8000000000, 8500000000, 9000000000, 10000000000 }}, + .correction_value = {{ 0, 0, +1, +2, +2, +4, +9, +10, +16, +15, +17, +22, +30, +30, +30, +30, +30, +30, +30, +30 }, + { 0, 0, +1, +2, +2, +4, +9, +10, +16, +15, +17, +22, +30, +30, +30, +30, +30, +30, +30, +30 }}, .setting_frequency_30mhz = 30000000, .cor_am = 0, .cor_wfm = 0, diff --git a/nanovna.h b/nanovna.h index 392d3fd..42175f0 100644 --- a/nanovna.h +++ b/nanovna.h @@ -628,6 +628,7 @@ typedef struct config { float high_level_offset; float low_level_output_offset; float high_level_output_offset; + float lna_level_offset; float correction_value[CORRECTION_SIZE][CORRECTION_POINTS]; freq_t correction_frequency[CORRECTION_SIZE][CORRECTION_POINTS]; #ifdef TINYSA4 diff --git a/sa_cmd.c b/sa_cmd.c index fd743b6..89f418c 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -293,7 +293,11 @@ VNA_SHELL_FUNCTION(cmd_levelchange) VNA_SHELL_FUNCTION(cmd_leveloffset) { // 0 1 2 +#ifdef TINYSA4 static const char cmd_mode_list[] = "low|high|switch"; +#else + static const char cmd_mode_list[] = "low|high|switch|lna"; +#endif if (argc == 0) { const char *p = "leveloffset %s %.1f\r\n"; shell_printf(p, "low", config.low_level_offset); @@ -301,6 +305,9 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) shell_printf(p, "low output", config.low_level_output_offset); shell_printf(p, "high output", config.high_level_output_offset); shell_printf(p, "switch", config.switch_offset); +#ifdef TINYSA4 + shell_printf(p, "lna", config.lna_level_offset); +#endif return; } int mode = get_str_index(argv[0], cmd_mode_list); @@ -312,6 +319,9 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) case 0: config.low_level_offset = v; break; case 1: config.high_level_offset = v; break; case 2: config.switch_offset = v; break; +#ifdef TINYSA4 + case 3: config.lna_level_offset = v; break; +#endif default: goto usage; } dirty = true; diff --git a/sa_core.c b/sa_core.c index e7596d6..aa32444 100644 --- a/sa_core.c +++ b/sa_core.c @@ -882,7 +882,12 @@ void set_actual_power(float o) // Set peak level to known value if (setting.mode == M_HIGH) { config.high_level_offset = new_offset; } else if (setting.mode == M_LOW) { - config.low_level_offset = new_offset; +#ifdef TINYSA4 + if (setting.extra_lna) + config.lna_level_offset = new_offset; + else +#endif + config.low_level_offset = new_offset; } dirty = true; config_save(); @@ -897,9 +902,18 @@ float get_level_offset(void) return(config.high_level_offset); } if (setting.mode == M_LOW) { - if (config.low_level_offset == 100) - return 0; - return(config.low_level_offset); +#ifdef TINYSA4 + if (setting.extra_lna) { + if (config.lna_level_offset == 100) + return 0; + return(config.lna_level_offset); + } else +#endif + { + if (config.low_level_offset == 100) + return 0; + return(config.low_level_offset); + } } if (setting.mode == M_GENLOW) { return(config.low_level_output_offset); @@ -914,8 +928,16 @@ int level_is_calibrated(void) { if (setting.mode == M_HIGH && config.high_level_offset != 100) return 1; - if (setting.mode == M_LOW && config.low_level_offset != 100) - return 1; + if (setting.mode == M_LOW) { +#ifdef TINYSA4 + if (setting.extra_lna) { + if (config.lna_level_offset != 100) + return 1; + } else +#endif + if (config.low_level_offset != 100) + return 1; + } return(0); } @@ -2270,7 +2292,7 @@ static void calculate_static_correction(void) // Calculate the #ifdef TINYSA4 - (S_STATE(setting.agc)? 0 : 33) - (S_STATE(setting.lna)? 0 : 0) - + (setting.extra_lna ? -25.5 : 0) // TODO <------------------------- set correct value + + (setting.extra_lna ? -23.5 : 0) // TODO <------------------------- set correct value #endif - setting.external_gain); } @@ -3200,6 +3222,7 @@ static bool sweep(bool break_on_operation) #endif } + bool show_bar = ( MODE_INPUT(setting.mode) || setting.frequency_step != 0 || setting.level_sweep != 0.0 ? true : false); again: // Waiting for a trigger jumps back to here setting.measure_sweep_time_us = 0; // start measure sweep time // start_of_sweep_timestamp = chVTGetSystemTimeX(); // Will be set in perform @@ -3265,9 +3288,9 @@ sweep_again: // stay in sweep loop when output mo //if (MODE_INPUT(setting.mode)) { #ifdef TINYSA4 - if ((i & 0x07) == 0 && (setting.actual_sweep_time_us > ONE_SECOND_TIME || (chVTGetSystemTimeX() - start_of_sweep_timestamp) > ONE_SECOND_TIME / 100)) { // if required + if (show_bar && (i & 0x07) == 0 && (setting.actual_sweep_time_us > ONE_SECOND_TIME || (chVTGetSystemTimeX() - start_of_sweep_timestamp) > ONE_SECOND_TIME / 100)) { // if required #else - if ( (i & 0x07) == 0 && setting.actual_sweep_time_us > ONE_SECOND_TIME) { // if required + if ( show_bar && (i & 0x07) == 0 && setting.actual_sweep_time_us > ONE_SECOND_TIME) { // if required #endif int pos = i * (WIDTH+1) / sweep_points; ili9341_set_background(LCD_SWEEP_LINE_COLOR); @@ -4068,6 +4091,7 @@ const test_case_t test_case [] = TEST_CASE_STRUCT(TC_BELOW, TP_SILENT, 144, 8, -95, 0, 0), // 22 Measure 48MHz spur #define TEST_LEVEL 24 TEST_CASE_STRUCT(TC_LEVEL, TP_30MHZ, 30, 0, CAL_LEVEL, 145, -55), // 23 Measure level + TEST_CASE_STRUCT(TC_LEVEL, TP_30MHZ_LNA, 30, 0, CAL_LEVEL, 145, -55), // 23 Measure level TEST_CASE_STRUCT(TC_LEVEL, TPH_30MHZ, 150, 0, CAL_LEVEL-30, 145, -55), // 23 Measure level }; @@ -4374,7 +4398,7 @@ int test_validate(int i) current_test_status = validate_atten(i); break; case TC_LEVEL: - current_test_status = validate_level(i, 0.0); + current_test_status = validate_level(i, 10.0); break; case TC_DISPLAY: current_test_status = validate_display(i); @@ -4388,6 +4412,7 @@ int test_validate(int i) test_status[i] = current_test_status; // Must be set before draw_all() !!!!!!!! // draw_frequencies(); // draw_cal_status(); + redraw_request != REDRAW_CAL_STATUS; draw_all(TRUE); return current_test_status; } @@ -4495,7 +4520,6 @@ common_silent: break; case TP_30MHZ_LNA: setting.extra_lna = true; - chThdSleepMilliseconds(200); break; #endif case TP_10MHZ_SWITCH: @@ -4909,22 +4933,22 @@ quit: if (setting.test_argument != 0) break; } - +#if 0 // Does not center on frequency!!!!! shell_printf("\n\r"); for (int j= SI4432_RBW_count-1; j >= 0; j-- ) { if (setting.test_argument != 0) j = setting.test_argument; - test_prepare(TEST_LEVEL+1); + test_prepare(TEST_LEVEL+2); setting.rbw_x10 = force_rbw(j); - test_acquire(TEST_LEVEL+1); // Acquire test - test_validate(TEST_LEVEL+1); // Validate test + test_acquire(TEST_LEVEL+2); // Acquire test + test_validate(TEST_LEVEL+2); // Validate test if (j == SI4432_RBW_count-1) first_level = peakLevel; shell_printf("RBW = %7.1fk, level = %6.2f, corr = %6.2f\n\r",actual_rbw_x10/10.0 , peakLevel, (first_level - peakLevel + 1.5)*10.0 ); if (setting.test_argument != 0) break; } - +#endif reset_settings(M_LOW); } @@ -4938,6 +4962,9 @@ void reset_calibration(void) { config.high_level_offset = 100; config.low_level_offset = 100; +#ifdef TINYSA4 + config.lna_level_offset = 100; +#endif } void calibrate_modulation(int modulation, int8_t *correction) @@ -4974,28 +5001,38 @@ void calibrate(void) #endif reset_calibration(); reset_settings(M_LOW); +#ifdef TINYSA4 + bool calibrate_lna = false; +again: +#endif for (int k = 0; k<2; k++) { for (int j= 0; j < CALIBRATE_RBWS; j++ ) { // set_RBW(power_rbw[j]); // set_sweep_points(21); #if 0 - test_prepare(TEST_POWER); + int test_case = TEST_POWER; + test_prepare(test_case); setting.step_delay_mode = SD_PRECISE; #ifndef TINYSA4 setting.agc = S_ON; setting.lna = S_OFF; -// set_RBW(6000); + // set_RBW(6000); #else set_RBW(8500); set_attenuation(10); #endif - test_acquire(TEST_POWER); // Acquire test - local_test_status = test_validate(TEST_POWER); // Validate test + test_acquire(test_case); // Acquire test + local_test_status = test_validate(test_case); // Validate test #else - test_prepare(TEST_LEVEL); + int test_case = TEST_LEVEL; +#ifdef TINYSA4 + if (calibrate_lna) + test_case += 1; +#endif + test_prepare(test_case); set_RBW(8500); - test_acquire(TEST_LEVEL); // Acquire test - local_test_status = test_validate(TEST_LEVEL); // Validate test + test_acquire(test_case); // Acquire test + local_test_status = test_validate(test_case); // Validate test also sets attenuation if zero span #endif if (k ==0 || k == 1) { if (peakLevel < -50) { @@ -5016,7 +5053,13 @@ void calibrate(void) } } } -#if 0 // No high input calibration as CAL OUTPUT is unreliable +#ifdef TINYSA4 + if (!calibrate_lna) { + calibrate_lna = true; + goto again; + } +#endif + #if 0 // No high input calibration as CAL OUTPUT is unreliable set_RBW(100); test_prepare(TEST_POWER+1); diff --git a/si4468.c b/si4468.c index 80bcc39..69731c9 100644 --- a/si4468.c +++ b/si4468.c @@ -2701,6 +2701,7 @@ void enable_extra_lna(int s) else palClearLine(LINE_LNA); old_extra_lna = s; + osalThreadSleepMilliseconds(500); } #else (void)s;