diff --git a/chconf.h b/chconf.h index deb0f9e..29c99d7 100644 --- a/chconf.h +++ b/chconf.h @@ -156,7 +156,9 @@ * * @note The default is @p TRUE. */ -#define CH_CFG_USE_WAITEXIT FALSE +#ifdef TINYSA4 +#define CH_CFG_USE_WAITEXIT TRUE +#endif /** * @brief Semaphores APIs. diff --git a/main.c b/main.c index 157fb0f..830f648 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,9 @@ int32_t frequencyExtra; */ // If need run shell as thread (use more amount of memory fore stack), after // enable this need reduce spi_buffer size, by default shell run in main thread -// #define VNA_SHELL_THREAD +#ifdef TINYSA4 +#define VNA_SHELL_THREAD +#endif static BaseSequentialStream *shell_stream; threads_queue_t shell_thread; @@ -1183,7 +1185,7 @@ config_t config = { .correction_value = { /* low */ { 12.2, 7.57, 4.46, 2.17, 0.36, -0.36, 0, -0.84, -0.39, 0.5, 0.25, 1, 0.08, 0.48, 0.37, 1.53, 2.98, 4.74, 6.25, 8.73, }, - /* low lna */ { 11, 8.54, 6.32, 4.46, 3.18, 1.02, 0.69, 0.2, -0.43, -0.41, 0.58, 0.66, -0.08, 0.58, 0.77, 1.7, 1.77, 3.55, 5.51, 7.99, }, + /* low lna */ { 11, 8.54, 6.32, 4.46, 3.18, 1.02, 0.69, 0.2, -0.43, -0.41, 0.58, 0.66, -0.08, 0.58, 0.77, 1.7, 1.77, 3.55, 5.51, 7.99, }, /* ultra */ { 0, 0.58, 1.7, 4.53, 4.46, 3.23, 4.64, 6.29, 5.67, 7.03, 8.78, 7.04, 8.25, 11.42, 11.63, 13.29, 12.38, 12.58, 15.75, 15.93, }, /* ultra lna */ { 0, 0.49, 0.52, 1.26, 3.13, 2.68, 2.68, 3.45, 4.7, 6.2, 8.49, 11.54, 13.51, 15.82, 15.82, 18.66, 19.41, 22.6, 22.8, 28.1, }, /* direct */ { 35.12, 34.22, 32.41, 30, 21.7, 20.41, 16.45, 15.91, 14.86, 14.34, 11.63, 10.71, 8.88, 1.25, 0.629999999999999, 1.45, 0.59, 2.2, 3.79, 6.28, }, @@ -1226,41 +1228,41 @@ config_t config = { }; -const int to_calibrate[6] = {9,10,11,12,13,14}; +// const int to_calibrate[6] = {9,10,11,12,13,14}; //properties_t current_props; //properties_t *active_props = ¤t_props; #ifdef TINYSA4 const freq_t v5_2_correction_frequency[CORRECTION_SIZE][CORRECTION_POINTS]= { - /* low */ { 100000, 500000, 8000000, 40000000, 60000000, 70000000, 110000000, 300000000, 330000000, 420000000, 450000000, 460000000, 510000000, 560000000, 620000000, 710000000, 760000000, 800000000, 810000000, 830000000}, - /* low lna */ { 100000, 200000, 400000, 700000, 1000000, 2000000, 4000000, 30000000, 50000000, 210000000, 240000000, 260000000, 270000000, 300000000, 330000000, 510000000, 720000000, 790000000, 820000000, 830000000}, - /* ultra */ { 30000000, 700000000, 1900000000, 2600000000, 2800000000, 2850000000, 3200000000, 3750000000, 4300000000, 4600000000, 4900000000, 5000000000, 5300000000, 5600000000, 5750000000, 6000000000, 6450000000, 6700000000, 7050000000, 7250000000}, - /* ultra lna */ { 30000000, 700000000, 2050000000, 2300000000, 2600000000, 2800000000, 2900000000, 3100000000, 3550000000, 3850000000, 4400000000, 4800000000, 5000000000, 5200000000, 5400000000, 6000000000, 6200000000, 6450000000, 6550000000, 7250000000}, - /* direct */ { 140000000, 160000000, 180000000, 280000000, 300000000, 400000000, 420000000, 430000000, 510000000, 560000000, 823000000, 880000000, 930000000, 940000000, 960000000, 990000000, 1060000000, 1080000000, 1110000000, 1130000000}, - /* direct lna */ { 140000000, 180000000, 280000000, 300000000, 330000000, 400000000, 410000000, 430000000, 460000000, 470000000, 490000000, 550000000, 560000000, 823000000, 850000000, 870000000, 940000000, 960000000, 980000000, 1130000000, }, - /* harm */ { 30000000, 6000000000, 6195991091, 6302895323, 6400890869, 6899777283, 7104677060, 7398663697, 7701559020, 7799554566, 8200445434, 8298440980, 8503340757, 8904231626, 9002227171, 9100222717, 9198218263, 9296213808, 9501113586, 9804008909, }, - /* harm lna */ { 30000000, 6000000000, 6097995546, 6204899777, 6498886414, 6596881960, 6801781737, 7496659243, 7701559020, 7995545657, 8102449889, 8298440980, 8396436526, 8699331849, 8904231626, 9100222717, 9198218263, 9403118040, 9697104677, 10000000000, }, - /* out */ { 10000, 30000, 100000, 200000, 600000, 5000000, 170000000, 250000000, 300000000, 390000000, 490000000, 650000000, 690000000, 740000000, 780000000, 800000000, 810000000, 820000000, 823000000, 830000000, }, - /* direct */ { 500000000, 823000000, 830000000, 850000000, 860000000, 870000000, 880000000, 890000000, 900000000, 910000000, 920000000, 930000000, 970000000, 1030000000, 1040000000, 1050000000, 1060000000, 1070000000, 1080000000, 1100000000, }, - /* adf */ { 500000000, 700000000, 1340000000, 1500000000, 2000000000, 2350000000, 2800000000, 2810000000, 3000000000, 3410000000, 3600000000, 3990000000, 4330000000, 4570000000, 4760000000, 5310000000, 5320000000, 5720000000, 6100000000, 6440000000, }, - /* ultra */ { 10000, 100000, 500000, 3000000, 50000000, 800000000, 2300000000, 2800000000, 3300000000, 3620000000, 4200000000, 4470000000, 4480000000, 4570000000, 4780000000, 5330000000, 5700000000, 6000000000, 6390000000, 7300000000, }, + /* low */ { 10000, 40000, 80000, 400000, 700000, 3000000, 30000000, 130000000, 170000000, 220000000, 420000000, 460000000, 750000000, 820000000, 860000000, 870000000, 880000000, 890000000, 900000000, 900000000}, + /* low lna */ { 20000, 50000, 100000, 500000, 700000, 1000000, 7000000, 30000000, 220000000, 360000000, 420000000, 630000000, 750000000, 810000000, 850000000, 860000000, 870000000, 880000000, 890000000, 900000000}, + /* ultra */ { 30000000, 700000000, 4110000000, 4740000000, 4890000000, 5010000000, 5110000000, 5440000000, 5780000000, 6430000000, 6590000000, 6800000000, 7350000000, 7350000000, 7350000000, 7350000000, 7350000000, 7350000000, 7350000000, 7350000000}, + /* ultra lna */ { 30000000, 700000000, 2670000000, 4040000000, 4390000000, 4770000000, 5240000000, 5470000000, 5880000000, 6020000000, 6200000000, 6410000000, 7100000000, 7350000000, 7350000000, 7350000000, 7350000000, 7350000000, 7350000000, 7350000000}, + /* direct */ { 140000000, 180000000, 280000000, 420000000, 560000000, 830000000, 920000000, 1000000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000}, + /* direct lna */ { 140000000, 170000000, 180000000, 280000000, 330000000, 440000000, 560000000, 830000000, 900000000, 960000000, 1040000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000}, + /* harm */ { 30000000, 5000000000, 5070000000, 5140000000, 5480000000, 6110000000, 6570000000, 7080000000, 7270000000, 7920000000, 8380000000, 8700000000, 8920000000, 9010000000, 9260000000, 10000000000, 10000000000, 10000000000, 10000000000, 10000000000}, + /* harm lna */ { 30000000, 5000000000, 5270000000, 5540000000, 6170000000, 6770000000, 7370000000, 7920000000, 8610000000, 9380000000, 10000000000, 10000000000, 10000000000, 10000000000, 10000000000, 10000000000, 10000000000, 10000000000, 10000000000, 10000000000}, + /* out */ { 100000, 300000, 700000, 5000000, 30000000, 90000000, 210000000, 550000000, 790000000, 870000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000}, + /* direct */ { 823000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000, 1140000000}, + /* adf */ { 740000000, 1120000000, 1310000000, 1430000000, 1700000000, 2100000000, 2200000000, 2300000000, 3100000000, 4000000000, 4200000000, 4500000000, 4600000000, 4900000000, 5300000000, 5600000000, 6000000000, 6400000000, 6400000000, 6400000000}, + /* ultra */ { 10000, 100000, 600000, 4000000, 20000000, 280000000, 750000000, 1230000000, 2900000000, 3400000000, 4100000000, 4500000000, 5300000000, 6000000000, 6600000000, 7400000000, 7400000000, 7400000000, 7400000000, 7400000000} }; const float v5_2_correction_value[CORRECTION_SIZE][CORRECTION_POINTS]= { - /* low */ { 2.88, 1.06, 0.9, 0.85, 1.3, 0.72, 0.8, 0.53, 1.03, 0.81, 0.55, 0.05, -0.06, 0.18, -0.28, 0.61, 0.98, 2.89, 3.89, 7.37, }, - /* low lna */ { 6.07, 2.97, 0.76, -0.73, -1.37, -2.36, -2.92, 1.36, 2.67, 3.52, 6.12, 9.45, 9.54, 5.97, 4.72, 3.88, 4.51, 6.38, 9.34, 11.81, }, - /* ultra */ { 0.8, -0.28, 0.73, 2.69, 2.03, 3.31, 3.66, 5.8, 6.23, 9.6, 9.98, 9.93, 9.51, 12.2, 12.78, 11.56, 15.13, 18.42, 26.5, 32.3, }, - /* ultra lna */ { 1.55, 4.69, 6.26, 7.85, 8.56, 7.06, 8.14, 8.05, 11.61, 11.11, 13, 16.08, 15.89, 14.81, 14.94, 19.78, 20.41, 19.04, 19.28, 38, }, - /* direct */ { 34.6, 32.01, 29.84, 21.67, 20.24, 14.92, 14.41, 13.69, 10.25, 8.75, -0.01, -0.14, 0.69, 1.18, 1.19, 1.94, 3.52, 4.36, 5.11, 5.69, }, - /* direct lna */ { 30.57, 26.24, 22.57, 18.99, 16.02, 12.32, 12.31, 11.59, 10.08, 9.92, 8.18, 5.66, 5.68, -2.2, -2.65, -2.68, -1.79, -0.94, -0.89, 3.09, }, - /* harm */ { 18.7, 18.91, 19.91, 19.41, 19.91, 21.91, 22.41, 23.91, 26.91, 28.41, 34.41, 36.41, 37.91, 35.94, 35.94, 36.9, 38.44, 40.94, 44.94, 48.94, }, - /* harm lna */ { 13.6, 24.41, 23.41, 23.41, 19.91, 19.41, 21.91, 27.41, 31.91, 39.91, 41.91, 43.41, 42.91, 38.91, 40.91, 44.41, 47.91, 57.91, 61.41, 61.46, }, - /* out */ { 3.84, 2.31, 1.04, 0.1, -0.82, -1.51, -2.33, -2.25, -2.04, -1.43, -2.2, -2.36, -1.84, -1.23, 0.51, 1.8, 3.17, 6.28, 7.85, 12.37, }, - /* direct */ { -7.76, -3.85, -3.71, -3.54, -3.45, -3.34, -3.23, -3.11, -2.98, -2.86, -2.74, -2.64, -2.14, -1.29, -1.14, -1.05, -0.89, -0.79, -0.62, -0.31, }, - /* adf */ { 5.58, 3.91, -4.52, -6, -3.36, -2.14, -2.3, -3.11, -3.11, -2.05, -1.5, -1.36, 1.28, 4.63, 5.89, 5.55, 5.47, 6.49, 3.86, 5.8, }, - /* ultra */ { 3.69, 0.75, -0.94, -1.61, -2.45, -3.16, -1.09, 0.2, 0.73, 2.14, 2.37, 4.84, 3.13, 4.15, 4.89, 4.13, 7.48, 7.14, 8.99, 18.8, }, + /* low */ { 18.66, 14.1, 11.7, 9.27, 1.91, -0.84, -0.9, -0.9, 0.15, 0.25, -0.2, -0.9, -0.5, -0.5, 0.5, 0.5, 0.8, 1, 1.5, 1.5}, + /* low lna */ { 15.48, 11.15, 9.23, 6.73, 1.23, -0.6, -2, -1.47, -0.05, 0.5, -0.2, -1, -0.5, -0.4, -0.06, 0.4, 0.44, 0.84, 1, 1}, + /* ultra */ { 0.001, -0.07, 4.68, 7, 7.13, 5.96, 7.05, 6.59, 8.94, 11.14, 12.1, 14.68, 26, 26, 26, 26, 26, 26, 26, 26}, + /* ultra lna */ { 0.0001, 0.81, 2.12, 6.26, 1.55, 9.08, 10.49, 9.2, 10.86, 11.01, 9.71, 11.71, 21.05, 28.26, 28.26, 28.26, 28.26, 28.26, 28.26, 28.26}, + /* direct */ { 55.9, 47.83, 35.46, 24.2, 15.84, 2.47, -0.03, -0.2, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5}, + /* direct lna */ { 55, 49.54, 48, 35.46, 31, 22.6, 15.49, 2.49, 0.001, -0.5, -0.5, 0.47, 0.47, 0.47, 0.47, 0.47, 0.47, 0.47, 0.47, 0.47}, + /* harm */ { 0.001, 15.49, 15.08, 14.77, 13.6, 14.37, 16.33, 23.47, 25.08, 25.87, 30.1, 34.5, 39.51, 40.5, 40.14, 42.77, 42.77, 42.77, 42.77, 42.77}, + /* harm lna */ { 0.001, 20.53, 20.89, 15.67, 13.32, 22.15, 27.77, 28.3, 34.67, 49.83, 52.42, 52.42, 52.42, 52.42, 52.42, 52.42, 52.42, 52.42, 52.42, 52.42}, + /* out */ { 0.77, -2.79, -3.73, -5.29, -5.74, -5.7, -4.08, -5.35, -4.77, -3.74, -2.53, -2.53, -2.53, -2.53, -2.53, -2.53, -2.53, -2.53, -2.53, -2.53}, + /* direct */ { -3.8, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31}, + /* adf */ { -4.8, 3.34, -6, -8.6, -10.7, -7.33, -7.73, -8.38, -4.39, -2.64, -0.58, 6.76, 6.76, 3.53, 3.93, 2.21, 2.43, 3.31, 3.31, 3.31}, + /* ultra */ { 5.72, 0.57, -3.73, -5.19, -5.49, -4.51, -5.35, -3.81, -2.44, -0.59, 0.12, 4.84, 2.21, 3.5, 6.29, 18.3, 18.3, 18.3, 18.3, 18.3}, }; const float v5_2_harmonic_lna_level_offset = 0; // should be in correction table now -7; // Depends on where the transition to harmonic is done!!!!!! TODO find best frequency to transition to harmonic @@ -2989,7 +2991,7 @@ void set_freq_boundaries(void) { MAX_ABOVE_IF_FREQ = 3030000000ULL + config.overclock; // Range to use for below IF MIN_BELOW_IF_FREQ = 2430000000ULL + config.overclock; // Range to use for below IF } - set_jump_freq( MAX_ABOVE_IF_FREQ, (config.harmonic_start?config.harmonic_start:ULTRA_MAX_FREQ), MIN_BELOW_IF_FREQ); + set_jump_freq( MAX_ABOVE_IF_FREQ, MIN_BELOW_IF_FREQ, (config.harmonic_start?config.harmonic_start:ULTRA_MAX_FREQ)); // Harmonic must be last } #endif diff --git a/nanovna.h b/nanovna.h index 24aedc2..9eb4193 100644 --- a/nanovna.h +++ b/nanovna.h @@ -822,6 +822,7 @@ typedef struct config { float shift1_level_offset; float shift2_level_offset; float shift3_level_offset; + float shift4_level_offset; float drive1_level_offset; float drive2_level_offset; float drive3_level_offset; @@ -1493,8 +1494,8 @@ typedef struct properties { //sizeof(properties_t) == 0x1200 -#define CONFIG_MAGIC 0x434f4e6b -#define SETTING_MAGIC 0x434f4e6b +#define CONFIG_MAGIC 0x434f4e6c +#define SETTING_MAGIC 0x434f4e6c extern int16_t lastsaveid; //extern properties_t *active_props; diff --git a/plot.c b/plot.c index 76ce72f..b3865cf 100644 --- a/plot.c +++ b/plot.c @@ -1836,7 +1836,7 @@ static void cell_draw_marker_info(int x0, int y0) j = 2; int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; int ypos = 1 + (j/2)*(16) - y0; - cell_printf(xpos, ypos, FONT_s"OIP3: %4.1fdB", ip); + cell_printf(xpos, ypos, FONT_s"OIP3: %4.1fdBm", ip); #ifdef __LEVEL_METER__ plot_printf(level_text, sizeof(level_text), "%4.1f", ip); #endif @@ -1846,7 +1846,7 @@ static void cell_draw_marker_info(int x0, int y0) j = 3; xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; ypos = 1 + (j/2)*(16) - y0; - cell_printf(xpos, ypos, FONT_s"OIP3: %4.1fdB", ip); + cell_printf(xpos, ypos, FONT_s"OIP3: %4.1fdBm", ip); break; } #if 0 diff --git a/sa_cmd.c b/sa_cmd.c index 400dd9e..739f82a 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -408,7 +408,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) { // 0 1 2 #ifdef TINYSA4 - static const char cmd_mode_list[] = "low|switch|receive_switch|out_switch|lna|harmonic|shift|shift1|shift2|shift3|drive1|drive2|drive3|direct|direct_lna|ultra|ultra_lna|harmonic_lna|adf"; + static const char cmd_mode_list[] = "low|switch|receive_switch|out_switch|lna|harmonic|shift|shift1|shift2|shift3|shift4|drive1|drive2|drive3|direct|direct_lna|ultra|ultra_lna|harmonic_lna|adf"; #else static const char cmd_mode_list[] = "low|high|switch|receive_switch"; #endif @@ -435,6 +435,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) shell_printf(p, "shift1", config.shift1_level_offset); shell_printf(p, "shift2", config.shift2_level_offset); shell_printf(p, "shift3", config.shift3_level_offset); + shell_printf(p, "shift4", config.shift4_level_offset); shell_printf(p, "drive1", config.drive1_level_offset); shell_printf(p, "drive2", config.drive2_level_offset); shell_printf(p, "drive3", config.drive3_level_offset); @@ -473,15 +474,16 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) case 7: config.shift1_level_offset = v; break; case 8: config.shift2_level_offset = v; break; case 9: config.shift3_level_offset = v; break; - case 10: config.drive1_level_offset = v; break; - case 11: config.drive2_level_offset = v; break; - case 12: config.drive3_level_offset = v; break; - case 13: config.direct_level_offset = v; break; - case 14: config.direct_lna_level_offset = v; break; - case 15: config.ultra_level_offset = v; break; - case 16: config.ultra_lna_level_offset = v; break; - case 17: config.harmonic_lna_level_offset = v; break; - case 18: config.adf_level_offset = v; break; + case 10: config.shift4_level_offset = v; break; + case 11: config.drive1_level_offset = v; break; + case 12: config.drive2_level_offset = v; break; + case 13: config.drive3_level_offset = v; break; + case 14: config.direct_level_offset = v; break; + case 15: config.direct_lna_level_offset = v; break; + case 16: config.ultra_level_offset = v; break; + case 17: config.ultra_lna_level_offset = v; break; + case 18: config.harmonic_lna_level_offset = v; break; + case 19: config.adf_level_offset = v; break; #endif default: goto usage; } diff --git a/sa_core.c b/sa_core.c index 20c56ab..dd62fb7 100644 --- a/sa_core.c +++ b/sa_core.c @@ -2190,14 +2190,14 @@ void calculate_step_delay(void) SI4432_step_delay = step_delay_table[i].step_delay; SI4432_offset_delay = step_delay_table[i].offset_delay; spur_gate = actual_rbw_x10 * (actual_rbw_x10 > 5000 ? (100/2) : 100); - if (spur_gate < 30000) - spur_gate = 30000; + if (spur_gate < 15000) + spur_gate = 15000; // spur_gate = step_delay_table[i].spur_div_1000 * 1000; noise_level = step_delay_table[i].noise_level - PURE_TO_float(get_signal_path_loss()); log_averaging_correction = step_delay_table[i].log_aver_correction; #endif if (setting.step_delay_mode == SD_PRECISE) // In precise mode wait twice as long for RSSI to stabilize - SI4432_step_delay += (SI4432_step_delay>>2) ; + SI4432_step_delay += SI4432_step_delay ; if (setting.fast_speedup >0) SI4432_offset_delay = SI4432_step_delay / setting.fast_speedup; if (setting.faster_speedup >0) @@ -2302,6 +2302,8 @@ pureRSSI_t get_frequency_correction(freq_t f) // Frequency dependent RSSI c cv += float_TO_PURE_RSSI(config.drive2_level_offset); if (actual_drive >= 3) cv += float_TO_PURE_RSSI(config.drive3_level_offset); + if (f>MIN_BELOW_IF_FREQ) + cv += float_TO_PURE_RSSI(config.shift4_level_offset); if (f>MAX_ABOVE_IF_FREQ) cv += float_TO_PURE_RSSI(config.shift3_level_offset); } @@ -3269,11 +3271,18 @@ void fill_spur_table(void) // dynamic_spur_table[dynamic_spur_table_size++] = 174600000; // dynamic_spur_table[dynamic_spur_table_size++] = 219000000; dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/4 -SPUR_FACTOR/2; - dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/4 -SPUR_FACTOR/2 + 60000; -// dynamic_spur_table[dynamic_spur_table_size++] = 266000000; + if (!hw_if) + dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/4 -SPUR_FACTOR/2 + 60000; + else + dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/4 - 400000; + dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/3 -SPUR_FACTOR/3; dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/2 -SPUR_FACTOR; - if (actual_rbw_x10 < 3000) - dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/2 -SPUR_FACTOR + 120000; + if (actual_rbw_x10 < 3000) { + if (!hw_if) + dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/2 -SPUR_FACTOR + 120000; + else + dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/2 - 800000; + } dynamic_spur_table[dynamic_spur_table_size++] = corr_IF*2/3 -SPUR_FACTOR*2/3; spur_table = dynamic_spur_table; spur_table_size = dynamic_spur_table_size; @@ -4109,6 +4118,7 @@ again: // Spur redu else { local_IF = (hw_if? config.frequency_IF1 - 500000 : config.frequency_IF1 - 500000); setting.frequency_IF = local_IF; + fill_spur_table(); } #else local_IF = DEFAULT_IF; @@ -4133,7 +4143,9 @@ again: // Spur redu } } if (S_IS_AUTO(setting.below_IF)) { - if ((freq_t)lf > MAX_ABOVE_IF_FREQ && lf <= ULTRA_MAX_FREQ && !LO_harmonic) + if (((freq_t)lf > MAX_ABOVE_IF_FREQ && lf <= ULTRA_MAX_FREQ && !LO_harmonic) + || (!in_calibration && hw_if && (((uint32_t)(lf>>2)+1000000) / 2000000 == ((uint32_t)local_IF+1000000)/2000000)) // Avoid IF harmonic spur + ) setting.below_IF = S_AUTO_ON; // Only way to reach this range. Use below IF in harmonic mode else setting.below_IF = S_AUTO_OFF; // default is above IF, Use below IF in harmonic mode @@ -4191,6 +4203,10 @@ again: // Spur redu local_IF = local_IF; // No spur removal and no spur, center in IF } else #endif + if(setting.below_IF == S_AUTO_OFF && lf < local_IF/2-10000000) { + setting.below_IF = S_AUTO_ON; // use below IF for lowest spurs + local_IF = local_IF; + } else if (setting.auto_IF) { local_IF = local_IF + (actual_rbw_x10 > 2000 || hw_if ? DEFAULT_SPUR_OFFSET : DEFAULT_SPUR_OFFSET/2); // TODO find better way to shift spur away at large RBW/2; // if (actual_rbw_x10 == 6000 ) @@ -4336,7 +4352,7 @@ again: // Spur redu ADF4350_shift_ref(false); } } else - if (get_sweep_frequency(ST_SPAN)<5000000) { // When scanning less then 5MHz + if (get_sweep_frequency(ST_SPAN)<50000000) { // When scanning less then 5MHz if (actual_rbw_x10 <= 3000) { freq_t tf = ((lf + actual_rbw_x10*1000) / TXCO_DIV3) * TXCO_DIV3; if (tf + actual_rbw_x10*100 >= lf && tf < lf + actual_rbw_x10*100) // 10MHz @@ -4372,7 +4388,7 @@ again: // Spur redu } else if (lf < 25000000 && max2871) { ADF4351_R_counter(-1); ADF4351_modulo(200); - } else if (lf > 8000000 && !(lf > 1000000000 && hw_if) && MODE_INPUT(setting.mode)) { + } else if (lf > 8000000 && (lf < 1000000000 || max2871) && MODE_INPUT(setting.mode)) { if (local_modulo == 0) { if (max2871) ADF4351_modulo(100); @@ -5525,7 +5541,12 @@ static volatile int dummy; #ifdef __QUASI_PEAK__ case AV_QUASI: { static float old_RSSI = -150.0; - if (i == 0) old_RSSI = trace_data[sweep_points-1]; + + if (setting.frequency_step == 0) { + if (i == 0) old_RSSI = trace_data[sweep_points-1]; + } else { + old_RSSI = trace_data[i]; + } if (RSSI_calc > old_RSSI && setting.attack > 1) old_RSSI += (RSSI_calc - old_RSSI)/setting.attack; else if (RSSI_calc < old_RSSI && setting.decay > 1) @@ -6278,7 +6299,7 @@ const test_case_t test_case [] = #ifdef TINYSA4 {// Condition Preparation Center Span Pass Width(%)Stop TEST_CASE_STRUCT(TC_BELOW, TP_SILENT, 0.06, 0.11, -30, 0, -30), // 1 Zero Hz leakage - TEST_CASE_STRUCT(TC_BELOW, TP_SILENT, 0.1, 0.1, -50, 0, 0), // 2 Phase noise of zero Hz + TEST_CASE_STRUCT(TC_BELOW, TP_SILENT, 0.1, 0.1, -40, 0, 0), // 2 Phase noise of zero Hz TEST_CASE_STRUCT(TC_SIGNAL, TP_30MHZ, 30, 1, CAL_LEVEL, 10, -85), // 3 TEST_CASE_STRUCT(TC_SIGNAL, TP_30MHZ_ULTRA, 30, 1, CAL_LEVEL, 10, -85), // 4 Test Ultra mode #define TEST_SILENCE 4 @@ -7123,6 +7144,7 @@ quit: setting.stored[TRACE_TEMP] = true; setting.stored[TRACE_STORED2] = true; setting.below_IF = S_OFF; + shell_printf("IF = %D\r", setting.frequency_IF); freq_t f; #ifdef TINYSA4 setting.frequency_step = 3000; @@ -7162,7 +7184,7 @@ quit: cnt++; p = PURE_TO_float(perform(false, 1, f, false)); #ifdef TINYSA4 -#define SPUR_DELTA 10 +#define SPUR_DELTA 15 #else #define SPUR_DELTA 15 #endif @@ -7178,17 +7200,25 @@ quit: shell_printf("Freq(kHz), count, level(dBm), level with spur removal\n\r"); in_selftest = false; setting.spur_removal = S_ON; - sort_spur_count(); // Reduce table to most certain spurs + + sort_spur_level(); // Reduce table to only strongest spurs if (last_spur > MAX_DYNAMIC_SPUR_TABLE_SIZE) last_spur = MAX_DYNAMIC_SPUR_TABLE_SIZE; - sort_spur_level(); // Reduce table to only strongest spurs + + for (int j = 0; j < last_spur; j++) { + if ((int)stored_t[j] >= 1 && j < MAX_DYNAMIC_SPUR_TABLE_SIZE && (int)stored_t[j] > SPUR_CHECK_COUNT-2 && stored_t[j] - stored2_t[j] > 2) { + shell_printf("%d, %d, %4.2f, %4.2f\n\r", ((int)temp_t[j])/1000, (int)stored_t[j], stored2_t[j], PURE_TO_float(perform(false, 1, (freq_t)temp_t[j], false))); + } + } + + sort_spur_count(); // Reduce table to most certain spurs if (last_spur > MAX_DYNAMIC_SPUR_TABLE_SIZE) last_spur = MAX_DYNAMIC_SPUR_TABLE_SIZE; + sort_spur_freq(); -// dynamic_spur_table_size = 0; + // dynamic_spur_table_size = 0; for (int j = 0; j < last_spur; j++) { if ((int)stored_t[j] >= 1 && j < MAX_DYNAMIC_SPUR_TABLE_SIZE && (int)stored_t[j] > SPUR_CHECK_COUNT-2 && stored_t[j] - stored2_t[j] > 2) { - shell_printf("%d, %d, %4.2f, %4.2f\n\r", ((int)temp_t[j])/1000, (int)stored_t[j], stored2_t[j], PURE_TO_float(perform(false, 1, (freq_t)temp_t[j], false))); dynamic_spur_table[dynamic_spur_table_size++] = temp_t[j]; } } @@ -7713,13 +7743,13 @@ const int power_rbw [5] = { 100, 300, 30, 10, 3 }; #ifdef TINYSA4 #define JUMP_FREQS 7 -#define HARMONIC_JUMP 5 +#define HARMONIC_JUMP JUMP_FREQS -1 // Must be last freq_t jump_freqs[JUMP_FREQS] = {LOW_SHIFT_FREQ, LOW_SHIFT_FREQ, DRIVE1_MAX_FREQ, DRIVE2_MAX_FREQ, 0, 0, 0}; void set_jump_freq(freq_t a, freq_t b, freq_t c) { jump_freqs[4] = a; jump_freqs[5] = b; - jump_freqs[6] = c; + jump_freqs[6] = c; // Harmonic } void set_jump_config(int i, float v) { @@ -7737,12 +7767,13 @@ void set_jump_config(int i, float v) { config.drive3_level_offset = v; break; case 4: - config.shift3_level_offset = v; + config.shift3_level_offset = v; // MAX_ABOVE_IF_FREQ break; case 5: - config.harmonic_level_offset = v; + config.shift4_level_offset = v; // MIN_BELOW_IF_FREQ break; case 6: + config.harmonic_level_offset = v; // Used in calibrate harmonic break; } } @@ -7760,14 +7791,14 @@ float get_jump_config(int i) { case 4: return config.shift3_level_offset; case 5: - return config.harmonic_level_offset; + return config.shift4_level_offset; case 6: - return 0.0; + return config.harmonic_level_offset; // Used in calibrate harmonic } return 0; } -enum {CS_NORMAL, CS_LNA, CS_SWITCH, CS_ULTRA, CS_ULTRA_LNA, CS_DIRECT_REF, CS_DIRECT, CS_DIRECT_LNA, CS_SPUR_REF, CS_SPUR_ERROR, CS_HARMONIC, CS_HARMONIC_LNA, /* CS_BPF_REF, CS_BPF, */ CS_CORRECTION_REF, CS_CORRECTION_LNA, CS_MAX }; +enum {CS_NORMAL, CS_LNA, CS_SWITCH, CS_ULTRA, CS_ULTRA_LNA, CS_DIRECT_REF, CS_DIRECT, CS_DIRECT_LNA, CS_SPUR_REF, CS_SPUR_ERROR, CS_HARMONIC, CS_HARMONIC_LNA, /* CS_BPF_REF, CS_BPF, CS_CORRECTION_REF, CS_CORRECTION_LNA, */ CS_MAX }; #define ULTRA_HARMONIC_CAL_FREQ 5340000000 #else enum {CS_NORMAL, CS_SWITCH, CS_MAX }; @@ -7795,7 +7826,7 @@ void calibrate_harmonic(void) test_freq = jump_freqs[HARMONIC_JUMP]; set_jump_config(HARMONIC_JUMP, -2); test_prepare(TEST_JUMP_HARMONIC); - set_RBW(1000); + set_RBW(6000); // set_auto_reflevel(true); set_reflevel(-20); setting.repeat = 10; @@ -7866,29 +7897,22 @@ void calibrate(void) setting.scale = 1; set_trace_scale(1); - for (int i =0; i menu_back };