Merge branch 'main' of https://github.com/erikkaashoek/tinySA into DiSlord_triggers

DiSlord_triggers
DiSlord 1 year ago
commit 457123f05e

@ -232,7 +232,7 @@ static THD_FUNCTION(Thread1, arg)
} }
} else if (sweep_mode & SWEEP_SELFTEST) { } else if (sweep_mode & SWEEP_SELFTEST) {
// call from lowest level to save stack space // call from lowest level to save stack space
self_test(setting.test); selftest(setting.test);
completed = true; completed = true;
// sweep_mode = SWEEP_ENABLE; // sweep_mode = SWEEP_ENABLE;
#ifdef __SINGLE_LETTER__ #ifdef __SINGLE_LETTER__
@ -1269,34 +1269,34 @@ const float v5_2_lna_level_offset = 7;
const freq_t v4_6_correction_frequency[CORRECTION_SIZE][CORRECTION_POINTS]= const freq_t v4_6_correction_frequency[CORRECTION_SIZE][CORRECTION_POINTS]=
{ {
/* low */ { 100000, 1000000, 30000000, 220000000, 420000000, 750000000, 860000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000}, /* low */ { 100000, 1000000, 7000000, 30000000, 90000000, 220000000, 420000000, 460000000, 750000000, 860000000, 870000000, 880000000, 890000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000},
/* low lna */ { 100000, 1000000, 30000000, 220000000, 360000000, 420000000, 630000000, 750000000, 810000000, 860000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000}, /* low lna */ { 100000, 1000000, 30000000, 220000000, 360000000, 420000000, 630000000, 750000000, 810000000, 870000000, 880000000, 890000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000, 900000000},
/* ultra */ { 30000000, 700000000, 1270000000, 2090000000, 2620000000, 4130000000, 4710000000, 5090000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000}, /* ultra */ { 30000000, 700000000, 1270000000, 2090000000, 2620000000, 4130000000, 4710000000, 5090000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000},
/* ultra lna */ { 30000000, 1120000000, 2400000000, 3780000000, 3930000000, 4110000000, 4360000000, 4450000000, 4970000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000}, /* ultra lna */ { 30000000, 1120000000, 2400000000, 3540000000, 3780000000, 3930000000, 4110000000, 4360000000, 4450000000, 4540000000, 4700000000, 4970000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000, 5410000000},
/* direct */ { 140000000, 180000000, 280000000, 330000000, 420000000, 560000000, 830000000, 910000000, 980000000, 1040000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000}, /* direct */ { 140000000, 180000000, 280000000, 420000000, 560000000, 830000000, 920000000, 1000000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000},
/* direct lna */ { 140000000, 180000000, 280000000, 330000000, 420000000, 560000000, 830000000, 910000000, 980000000, 1040000000, 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, 4000000000, 4601336303, 5095768374, 5296213808, 5496659243, 5804008909, 6298440980, 6806236080, 7193763920, 7501113586, 7701559020, 7995545657, 8302895323, 8797327394, 9104677060, 9305122494, 9505567929, 9799554566, 10000000000, }, /* harm */ { 30000000, 5000000000, 5420000000, 6790000000, 7240000000, 7650000000, 7870000000, 8220000000, 8520000000, 8810000000, 9090000000, 9240000000, 9810000000, 10000000000, 10000000000, 10000000000, 10000000000, 10000000000, 10000000000, 10000000000},
/* harm lna */ { 30000000, 4000000000, 4093541203, 4200445434, 4293986637, 4400890869, 4601336303, 5296213808, 5897550111, 6405345212, 6498886414, 6806236080, 7100222717, 7594654788, 7795100223, 8102449889, 8503340757, 8997772829, 9599109131, 10000000000, }, /* harm lna */ { 30000000, 5000000000, 5440000000, 5950000000, 6420000000, 6780000000, 7200000000, 7570000000, 7780000000, 7930000000, 8230000000, 8540000000, 9610000000, 9700000000, 10000000000, 10000000000, 10000000000, 10000000000, 10000000000, 10000000000},
/* out */ { 100000, 800000, 5000000, 20000000, 100000000, 230000000, 450000000, 700000000, 850000000, 890000000, 920000000, 920000000, 920000000, 920000000, 920000000, 920000000, 920000000, 920000000, 920000000, 920000000, }, /* out */ { 100000, 800000, 3000000, 8000000, 80000000, 120000000, 200000000, 250000000, 550000000, 650000000, 780000000, 850000000, 890000000, 920000000, 920000000, 920000000, 920000000, 920000000, 920000000, 920000000,},
/* direct */ { 823000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, }, /* direct */ { 823000000, 970000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000, 1130000000},
/* adf */ { 140000000, 210000000, 260000000, 290000000, 340000000, 370000000, 410000000, 460000000, 500000000, 520000000, 570000000, 700000000, 1170000000, 1370000000, 2700000000, 3000000000, 3300000000, 4300000000, 4400000000, 4400000000, }, /* adf */ { 140000000, 230000000, 410000000, 510000000, 590000000, 740000000, 1150000000, 1320000000, 1390000000, 1700000000, 4500000000, 4500000000, 4500000000, 4500000000, 4500000000, 4500000000, 4500000000, 4500000000, 4500000000, 4400000000},
/* ultra */ { 100000, 600000, 3000000, 40000000, 260000000, 730000000, 1020000000, 3600000000, 4700000000, 5400000000, 5400000000, 5400000000, 5400000000, 5400000000, 5400000000, 5400000000, 5400000000, 5400000000, 5400000000, 5400000000, }, /* ultra */ { 100000, 800000, 5000000, 80000000, 310000000, 700000000, 840000000, 1130000000, 2100000000, 3300000000, 4100000000, 4800000000, 5300000000, 5400000000, 5400000000, 5400000000, 5400000000, 5400000000, 5400000000, 5400000000}
}; };
const float v4_6_correction_value[CORRECTION_SIZE][CORRECTION_POINTS]= const float v4_6_correction_value[CORRECTION_SIZE][CORRECTION_POINTS]=
{ {
/* low */ { 4, 0.25, 0.0001, 1, 0.0001, 0.0001, 1.5, 2.97, 2.97, 2.97, 2.97, 2.97, 2.97, 2.97, 2.97, 2.97, 2.97, 2.97, 2.97, 2.97, }, /* low */ { 4, 0.1, -1, -0.6, -1, 0.5, 0.0001, -1, -0.7, 0.5, 0.3, 1, 1.5, 2.28, 2.28, 2.28, 2.28, 2.28, 2.28, 2.28},
/* low lna */ { 4.78, 0.12, 0.0001, 1, 1, 0.5, -0.5, 0.4, 0.5, 1.5, 2.97, 2.97, 2.97, 2.97, 2.97, 2.97, 2.97, 2.97, 2.97, 2.97, }, /* low lna */ { 4.78, -0.5, -1.1, -0.05, 0.5, -0.2, -1, -0.5, -0.4, 0.2, 0.8, 1, 1.7, 1.7, 1.7, 1.7, 1.7, 1.7, 1.7, 1.7},
/* ultra */ { 0.0001, 0.22, 1.5, 1.75, 3.4, 2.97, 6.97, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, }, /* ultra */ { 0.0001, 0.3, 2.4, 2.34, 3.3, 4.3, 8.3, 7.8, 8.4, 8.4, 8.4, 8.4, 8.4, 8.4, 8.4, 8.4, 8.4, 8.4, 8.4, 8.4},
/* ultra lna */ { 0.0001, 1.5, 1.5, 6, 6.5, 8.5, 16, 16.5, 16.6, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, }, /* ultra lna */ { 0.0001, 1.8, 2.1, 7.1, 7.4, 8.02, 10, 17, 17.4, 18.3, 18.3, 17.7, 21, 21, 21, 21, 21, 21, 21, 21},
/* direct */ { 53.7, 46, 34.2, 30.5, 24.3, 17.2, 4.46, 1.2, -0.34, -0.25, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, }, /* 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 */ { 54.5, 47, 35, 31, 25, 17.3, 5.62, 2.12, 1.1, 0.7, 2.16, 2.16, 2.16, 2.16, 2.16, 2.16, 2.16, 2.16, 2.16, 2.16, }, /* 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 */ { 2, 18.69, 21.69, 21.69, 20.69, 20.69, 23.1, 25.19, 29.7, 26.69, 26.19, 27.69, 33.69, 37.19, 40.69, 45.69, 48.19, 49.48, 47.7, 48.7, }, /* harm */ { 0, 15.5, 14.5, 21.5, 18, 17.5, 19.8, 27.6, 29.3, 33, 38.9, 39.4, 33.3, 31.47, 31.47, 31.47, 31.47, 31.47, 31.47, 31.47},
/* harm lna */ { 2.8, 22.25, 23.25, 25.75, 29.75, 32.25, 34.25, 33.25, 36.25, 42.75, 43.75, 44.7, 42.7, 42.25, 43.75, 50.25, 55.75, 61.25, 65.25, 72.75, }, /* harm lna */ { 0.01, 26.2, 25.26, 26.68, 33.02, 35.12, 32.01, 30.4, 30.87, 32.8, 40.46, 45.4, 54.47, 55.82, 68.5, 68.5, 68.5, 68.5, 68.5, 68.5},
/* out */ { 0.0001, -1.82, -3, -3.16, -3.5, -2.06, -3.68, -3.7, -2.74, -1.3, 1.28, 1.28, 1.28, 1.28, 1.28, 1.28, 1.28, 1.28, 1.28, 1.28, }, /* out */ { -1, -2.81, -4.11, -4.26, -5.15, -5.08, -3.57, -3.32, -5.24, -4.6, -4.88, -4.15, -3.27, -0.82, -0.82, -0.82, -0.82, -0.82, -0.82, -0.82},
/* direct */ { -3.14, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, }, /* direct */ { -4.12, -2.58 , -0.48, -0.48, -0.48, -0.48, -0.48, -0.48, -0.48, -0.48, -0.48, -0.48, -0.48, -0.48, -0.48, -0.48, -0.48, -0.48, -0.48, -0.48},
/* adf */ { 31.4, 17.14, 15.46, 21.6, 14.3, 18.2, 30.7, 11.04, 1.74, -1.16, 1.67, -5.96, -6.55, -11.4, -7.34, -10.7, -5.4, -0.77, 3.07, 3.07, }, /* adf */ { 29.57, 17, 22.88, 0.1, 2, -4.5, -3.8, -9.43, -10, -10.9, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 3.07},
/* ultra */ { -0.5, -2.15, -3.18, -3.45, -2.33, -3.48, -2.05, -0.01, 3.48, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, 0.73, }, /* ultra */ { -1.4, -3, -4.46, -5, -3.8, -5, -4.56, -3.38, -3.2, 1, 0.6, 4, 5, 2.53, 2.53, 2.53, 2.53, 2.53, 2.53, 2.53},
}; };
const float v4_6_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 const float v4_6_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
@ -2404,7 +2404,9 @@ static const VNAShellCommand commands[] =
{"touchcal" , cmd_touchcal , CMD_WAIT_MUTEX}, {"touchcal" , cmd_touchcal , CMD_WAIT_MUTEX},
{"touchtest" , cmd_touchtest , CMD_WAIT_MUTEX}, {"touchtest" , cmd_touchtest , CMD_WAIT_MUTEX},
{"pause" , cmd_pause , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD}, {"pause" , cmd_pause , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD},
#ifdef TINYSA4
{"restart" , cmd_restart , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD}, {"restart" , cmd_restart , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD},
#endif
{"resume" , cmd_resume , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD}, {"resume" , cmd_resume , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD},
{"wait" , cmd_wait , CMD_RUN_IN_LOAD}, // This lets the sweep continue {"wait" , cmd_wait , CMD_RUN_IN_LOAD}, // This lets the sweep continue
{"repeat" , cmd_repeat , CMD_RUN_IN_LOAD}, {"repeat" , cmd_repeat , CMD_RUN_IN_LOAD},
@ -3144,11 +3146,15 @@ int main(void)
memcpy(config.correction_value, v4_6_correction_value, sizeof(config.correction_value)); memcpy(config.correction_value, v4_6_correction_value, sizeof(config.correction_value));
config.harmonic_level_offset = v4_6_harmonic_level_offset; config.harmonic_level_offset = v4_6_harmonic_level_offset;
config.harmonic_lna_level_offset = v4_6_harmonic_lna_level_offset; config.harmonic_lna_level_offset = v4_6_harmonic_lna_level_offset;
config.low_level_output_offset = 1;
// ULTRA_MAX_FREQ = 5450000000ULL; // ULTRA_MAX_FREQ = 5450000000ULL;
} }
// else // else
// ULTRA_MAX_FREQ = 5340000000ULL; // ULTRA_MAX_FREQ = 5340000000ULL;
ULTRA_MAX_FREQ = 4350000000 + config.frequency_IF1; ULTRA_MAX_FREQ = 4350000000 + config.frequency_IF1;
config.direct_start = config.frequency_IF1 - 10000000;
config.direct_stop = config.frequency_IF1 + 10000000;
} }
set_freq_boundaries(); set_freq_boundaries();
#endif #endif

@ -18,7 +18,7 @@
*/ */
#include "ch.h" #include "ch.h"
#ifdef TINYSA_F303 //#ifdef TINYSA_F303
#ifdef TINYSA_F072 #ifdef TINYSA_F072
#error "Remove comment for #ifdef TINYSA_F303" #error "Remove comment for #ifdef TINYSA_F303"
#endif #endif
@ -26,7 +26,7 @@
#define TINYSA4 #define TINYSA4
#endif #endif
#define TINYSA4_PROTO #define TINYSA4_PROTO
#endif //#endif
#ifdef TINYSA_F072 #ifdef TINYSA_F072
#ifdef TINYSA_F303 #ifdef TINYSA_F303
@ -143,6 +143,7 @@ typedef uint32_t freq_t;
#define DEFAULT_IF 433800000 #define DEFAULT_IF 433800000
#define DEFAULT_SPUR_IF 434000000 #define DEFAULT_SPUR_IF 434000000
#define DEFAULT_MAX_FREQ 350000000 #define DEFAULT_MAX_FREQ 350000000
#define NORMAL_MAX_FREQ DEFAULT_MAX_FREQ
#define MAX_LO_FREQ 959800000UL #define MAX_LO_FREQ 959800000UL
#define MIN_LO_FREQ 240000000UL #define MIN_LO_FREQ 240000000UL
#define MIN_BELOW_LO 550000000UL #define MIN_BELOW_LO 550000000UL
@ -156,7 +157,7 @@ typedef uint64_t freq_t;
#define FREQ_MULTIPLIER 100 // Multiplier of the 30MHz reference to get accurate frequency correction #define FREQ_MULTIPLIER 100 // Multiplier of the 30MHz reference to get accurate frequency correction
#define VARIANT(X,Y) (Y) #define VARIANT(X,Y) (Y)
#define DEFAULT_IF ((freq_t)977400000) #define DEFAULT_IF ((freq_t)977400000)
#define DEFAULT_IF_PLUS ((freq_t)1069500000) #define DEFAULT_IF_PLUS ((freq_t)1070100000)
extern uint16_t hw_if; extern uint16_t hw_if;
#define DEFAULT_SPUR_OFFSET ((freq_t)(actual_rbw_x10 > 3000 ? 1500000 : 1000000)) #define DEFAULT_SPUR_OFFSET ((freq_t)(actual_rbw_x10 > 3000 ? 1500000 : 1000000))
#define STATIC_DEFAULT_SPUR_OFFSET ((freq_t) 1500000) #define STATIC_DEFAULT_SPUR_OFFSET ((freq_t) 1500000)
@ -482,7 +483,7 @@ void MenuDirty(void);
void toggle_LNA(void); void toggle_LNA(void);
void toggle_AGC(void); void toggle_AGC(void);
void redrawHisto(void); void redrawHisto(void);
void self_test(int); void selftest(int);
void set_decay(int); void set_decay(int);
void set_attack(int); void set_attack(int);
void set_noise(int); void set_noise(int);
@ -1362,6 +1363,7 @@ typedef struct setting
#define PRESET_NAME_LENGTH 10 #define PRESET_NAME_LENGTH 10
char preset_name[PRESET_NAME_LENGTH]; char preset_name[PRESET_NAME_LENGTH];
#endif #endif
bool dBuV;
int64_t test_argument; // used for tests int64_t test_argument; // used for tests
uint32_t checksum; // must be last and at 4 byte boundary uint32_t checksum; // must be last and at 4 byte boundary
}setting_t; }setting_t;
@ -1498,8 +1500,8 @@ typedef struct properties {
//sizeof(properties_t) == 0x1200 //sizeof(properties_t) == 0x1200
#define CONFIG_MAGIC 0x434f4e69 #define CONFIG_MAGIC 0x434f4e6b
#define SETTING_MAGIC 0x434f4e69 #define SETTING_MAGIC 0x434f4e6b
extern int16_t lastsaveid; extern int16_t lastsaveid;
//extern properties_t *active_props; //extern properties_t *active_props;
@ -1845,7 +1847,7 @@ void update_rbw(void);
void set_fast_speedup(int); void set_fast_speedup(int);
void set_faster_speedup(int); void set_faster_speedup(int);
//extern int setting_measurement; //extern int setting_measurement;
void self_test(int); void selftest(int);
//extern int setting_test; //extern int setting_test;
void wait_user(void); void wait_user(void);
void calibrate(void); void calibrate(void);

@ -580,17 +580,23 @@ VNA_SHELL_FUNCTION(cmd_rbw)
VNA_SHELL_FUNCTION(cmd_if) VNA_SHELL_FUNCTION(cmd_if)
{ {
char *t = "975M..979M";
if (argc != 1 || argv[0][0] == '?') { if (argc != 1 || argv[0][0] == '?') {
usage: usage:
#ifdef TINYSA4 #ifdef TINYSA4
usage_printf("usage: if {975M..979M}\r\n%QHz\r\n", setting.frequency_IF); if (hw_if)
t = "1067M..1073M";
usage_printf("usage: if {%s}\r\n%QHz\r\n", t, setting.frequency_IF);
#else #else
usage_printf("usage: if {433M..435M}\r\n%QHz\r\n", setting.frequency_IF); usage_printf("usage: if {433M..435M}\r\n%QHz\r\n", setting.frequency_IF);
#endif #endif
return; return;
} }
freq_t a = (freq_t)my_atoi(argv[0]); freq_t a = (freq_t)my_atoi(argv[0]);
if (a!= 0 &&( a < (DEFAULT_IF - (freq_t)2000000) || a>(DEFAULT_IF + (freq_t)2000000))) freq_t f = DEFAULT_IF;
if (hw_if)
f = DEFAULT_IF_PLUS;
if (a!= 0 &&( a < (f - (freq_t)5000000) || a>(f + (freq_t)5000000)))
goto usage; goto usage;
setting.auto_IF = false; setting.auto_IF = false;
set_IF(a); set_IF(a);

@ -387,7 +387,7 @@ void set_output_path(freq_t f, float level)
SI4463_init_tx(); SI4463_init_tx();
break; break;
} }
setting.spur_removal &= 0xFE;
} }
static void calculate_static_correction(void); static void calculate_static_correction(void);
@ -405,21 +405,22 @@ void set_input_path(freq_t f)
} }
else if (MODE_HIGH(setting.mode)) else if (MODE_HIGH(setting.mode))
signal_path = PATH_HIGH; signal_path = PATH_HIGH;
else if (direct_test && f >= 900000000 && f < 1100000000) else if (direct_test && f >= 830000000 && f < 1130000000)
signal_path = PATH_DIRECT; signal_path = PATH_DIRECT;
else if (config.direct && f >= config.direct_start && f < config.direct_stop) else if (config.direct && f >= config.direct_start && f < config.direct_stop)
signal_path = PATH_DIRECT; signal_path = PATH_DIRECT;
else if(config.ultra && ((config.ultra_start == ULTRA_AUTO && f > ultra_start) || (config.ultra_start != ULTRA_AUTO && f >config.ultra_start))) { else if(config.ultra && ((config.ultra_start == ULTRA_AUTO && f > ultra_start) || (config.ultra_start != ULTRA_AUTO && f >config.ultra_start))) {
LO_harmonic = (f > (config.harmonic_start?config.harmonic_start:ULTRA_MAX_FREQ)); LO_harmonic = (f > (config.harmonic_start?config.harmonic_start:ULTRA_MAX_FREQ));
signal_path = PATH_ULTRA; signal_path = PATH_ULTRA;
} else } else {
signal_path = PATH_LOW; signal_path = PATH_LOW;
}
if (signal_path == PATH_HIGH) { if (signal_path == PATH_HIGH) {
return; // TODO setup high input path return; // TODO setup high input path
} }
enable_rx_output(setting.atten_step); enable_rx_output(setting.atten_step);
bool mirrors = false;
switch(signal_path) { switch(signal_path) {
case PATH_LOW: case PATH_LOW:
enable_ultra(false); enable_ultra(false);
@ -441,6 +442,7 @@ void set_input_path(freq_t f)
goto common2; goto common2;
case PATH_ULTRA: case PATH_ULTRA:
mirrors = true;
enable_ultra(true); enable_ultra(true);
enable_high(false); enable_high(false);
enable_direct(false); enable_direct(false);
@ -454,6 +456,12 @@ void set_input_path(freq_t f)
} }
if (force_signal_path) if (force_signal_path)
calculate_static_correction(); calculate_static_correction();
if (S_IS_AUTO(setting.spur_removal)) {
if (mirrors)
setting.spur_removal |= 0x01;
else
setting.spur_removal &= 0xFE;
}
} }
#endif #endif
@ -536,7 +544,7 @@ void update_min_max_freq(void)
maxFreq = MAX_LOW_OUTPUT_FREQ; maxFreq = MAX_LOW_OUTPUT_FREQ;
#endif #endif
#else #else
maxFreq = NORMAL_MAX_FREQ; maxFreq = DEFAULT_MAX_FREQ;
#endif #endif
break; break;
case M_HIGH: case M_HIGH:
@ -3061,7 +3069,7 @@ static const freq_t spur_table[] = // Frequenci
const int spur_table_size = (sizeof spur_table)/sizeof(freq_t); const int spur_table_size = (sizeof spur_table)/sizeof(freq_t);
#endif #endif
#ifdef TINYSA4 #ifdef TINYSA4
#define static_spur_IF DEFAULT_IF // The IF frequency for which the spur table is value #define static_spur_IF 977400000; // DEFAULT_IF // The IF frequency for which the spur table is value
#define STATIC_SPUR_TABLE_SIZE 56 #define STATIC_SPUR_TABLE_SIZE 56
static const freq_t static_spur_table[STATIC_SPUR_TABLE_SIZE] = // Valid for IF=977.4MHz static const freq_t static_spur_table[STATIC_SPUR_TABLE_SIZE] = // Valid for IF=977.4MHz
{ {
@ -3138,6 +3146,7 @@ static const freq_t static_spur_table_plus[] = // Valid for IF=977.4MHz
#define MAX_DYNAMIC_SPUR_TABLE_SIZE 100 #define MAX_DYNAMIC_SPUR_TABLE_SIZE 100
static freq_t dynamic_spur_table[MAX_DYNAMIC_SPUR_TABLE_SIZE]; // Frequencies to be calculated static freq_t dynamic_spur_table[MAX_DYNAMIC_SPUR_TABLE_SIZE]; // Frequencies to be calculated
static int dynamic_spur_table_size = 0; static int dynamic_spur_table_size = 0;
freq_t dynamic_spur_IF = 0;
static int always_use_dynamic_table = false; static int always_use_dynamic_table = false;
static freq_t *spur_table = (freq_t *)static_spur_table; static freq_t *spur_table = (freq_t *)static_spur_table;
@ -3229,36 +3238,41 @@ void fill_spur_table(void)
{ {
freq_t corr_IF; freq_t corr_IF;
if (always_use_dynamic_table) { if (always_use_dynamic_table) { // Only after doing selftest 1
spur_table = dynamic_spur_table; spur_table = dynamic_spur_table;
spur_table_size = dynamic_spur_table_size; spur_table_size = dynamic_spur_table_size;
return; return;
} }
if (actual_rbw_x10 < RBW_FOR_STATIC_TABLE) { // if less then 1100kHz use static table if (actual_rbw_x10 < RBW_FOR_STATIC_TABLE && !hw_if) { // if less then 1100kHz use static table
#if 0
if (hw_if) { if (hw_if) {
spur_table = (freq_t *)static_spur_table_plus; spur_table = (freq_t *)static_spur_table_plus;
spur_table_size = STATIC_SPUR_TABLE_SIZE_PLUS; spur_table_size = STATIC_SPUR_TABLE_SIZE_PLUS;
spur_IF = static_spur_IF_plus; spur_IF = static_spur_IF_plus;
} else { } else
#endif
{
spur_table = (freq_t *)static_spur_table; spur_table = (freq_t *)static_spur_table;
spur_table_size = STATIC_SPUR_TABLE_SIZE; spur_table_size = STATIC_SPUR_TABLE_SIZE;
spur_IF = static_spur_IF; spur_IF = static_spur_IF;
} }
return; return;
} }
if (!setting.auto_IF)
corr_IF = setting.frequency_IF; corr_IF = setting.frequency_IF;
else { if (dynamic_spur_IF == corr_IF)
corr_IF = config.frequency_IF1; return;
} dynamic_spur_IF = corr_IF;
dynamic_spur_table_size = 0; dynamic_spur_table_size = 0;
// dynamic_spur_table[dynamic_spur_table_size++] = 132000000; // dynamic_spur_table[dynamic_spur_table_size++] = 132000000;
// dynamic_spur_table[dynamic_spur_table_size++] = 153000000; // dynamic_spur_table[dynamic_spur_table_size++] = 153000000;
// dynamic_spur_table[dynamic_spur_table_size++] = 174600000; // dynamic_spur_table[dynamic_spur_table_size++] = 174600000;
// dynamic_spur_table[dynamic_spur_table_size++] = 219000000; // 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;
dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/4 -SPUR_FACTOR/2 + 60000;
// dynamic_spur_table[dynamic_spur_table_size++] = 266000000; // dynamic_spur_table[dynamic_spur_table_size++] = 266000000;
dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/2 -SPUR_FACTOR; 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;
dynamic_spur_table[dynamic_spur_table_size++] = corr_IF*2/3 -SPUR_FACTOR*2/3; dynamic_spur_table[dynamic_spur_table_size++] = corr_IF*2/3 -SPUR_FACTOR*2/3;
spur_table = dynamic_spur_table; spur_table = dynamic_spur_table;
spur_table_size = dynamic_spur_table_size; spur_table_size = dynamic_spur_table_size;
@ -3355,7 +3369,7 @@ int avoid_spur(freq_t f) // find if this frequency should be a
#ifdef TINYSA4 #ifdef TINYSA4
#if 1 #if 1
if (!setting.auto_IF && setting.frequency_IF-2000000 < f && f < setting.frequency_IF -200000) if (!setting.auto_IF && setting.frequency_IF-2000000 < f && f < setting.frequency_IF -200000)
return true; return F_AT_SPUR;
if(config.frequency_IF1+200000 > f && config.frequency_IF1 < f+200000) if(config.frequency_IF1+200000 > f && config.frequency_IF1 < f+200000)
return F_AT_SPUR; return F_AT_SPUR;
#endif #endif
@ -4083,29 +4097,23 @@ again: // Spur redu
#ifdef __ULTRA__ #ifdef __ULTRA__
// LO_harmonic = false; // LO_harmonic = false;
#endif #endif
if (MODE_LOW(setting.mode)){ // All low mode if (MODE_LOW(setting.mode) && !direct){ // All low input/output mode except direct that require setting of IF
if (!setting.auto_IF) if (!setting.auto_IF)
local_IF = setting.frequency_IF; local_IF = setting.frequency_IF;
else else
{ {
#ifdef TINYSA4 #ifdef TINYSA4
if (actual_rbw_x10 < RBW_FOR_STATIC_TABLE && setting.mode == M_LOW && lf > static_spur_table[0] - RBW_FOR_STATIC_TABLE * 100) if (!hw_if && actual_rbw_x10 < RBW_FOR_STATIC_TABLE && setting.mode == M_LOW && lf > static_spur_table[0] - RBW_FOR_STATIC_TABLE * 100)
local_IF = spur_IF; // static spur table IF local_IF = spur_IF; // static spur table IF
else else {
local_IF = config.frequency_IF1; local_IF = (hw_if? config.frequency_IF1 - 500000 : config.frequency_IF1 - 500000);
#if 0 setting.frequency_IF = local_IF;
if ( S_IS_AUTO(setting.below_IF)) {
// if (f < 2000000 && S_IS_AUTO(setting.spur_removal))
// local_IF += DEFAULT_SPUR_OFFSET;
// else // if (lf > ULTRA_MAX_FREQ || lf < local_IF/2 || ( lf + (uint64_t)local_IF< MAX_LO_FREQ && lf > 136000000ULL + local_IF) )
local_IF += DEFAULT_SPUR_OFFSET/2;
} }
#endif
#else #else
local_IF = DEFAULT_IF; local_IF = DEFAULT_IF;
#endif #endif
} }
if (setting.mode == M_LOW && !direct) { if (setting.mode == M_LOW) { // Low input mode
if (tracking) { // VERY SPECIAL CASE!!!!! Measure BPF if (tracking) { // VERY SPECIAL CASE!!!!! Measure BPF
#if 0 // Isolation test #if 0 // Isolation test
local_IF = lf; local_IF = lf;
@ -4123,9 +4131,6 @@ again: // Spur redu
setting.spur_removal= S_AUTO_OFF; setting.spur_removal= S_AUTO_OFF;
} }
} }
#endif
#ifdef __ULTRA__
if (S_IS_AUTO(setting.below_IF)) { 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)
setting.below_IF = S_AUTO_ON; // Only way to reach this range. Use below IF in harmonic mode setting.below_IF = S_AUTO_ON; // Only way to reach this range. Use below IF in harmonic mode
@ -4154,16 +4159,13 @@ again: // Spur redu
setting.below_IF = S_AUTO_OFF; // use below IF in second pass setting.below_IF = S_AUTO_OFF; // use below IF in second pass
} }
} }
else // if (setting.auto_IF) else // if (setting.auto_IF) // spur reduction is on and can not do above/below IF
{ {
if ((debug_avoid && debug_avoid_second) || spur_second_pass) { if ((debug_avoid && debug_avoid_second) || spur_second_pass) {
#ifdef TINYSA4 #ifdef TINYSA4
local_IF = local_IF + DEFAULT_SPUR_OFFSET-(actual_rbw_x10 > 1000 ? 200000 : 0); // apply IF spur shift local_IF = local_IF + DEFAULT_SPUR_OFFSET-(actual_rbw_x10 > 1000 ? 200000 : 0); // apply IF spur shift
LO_spur_shifted = true; LO_spur_shifted = true;
#ifdef TINYSA4
LO_shifting = true; LO_shifting = true;
#endif
} else { } else {
local_IF = local_IF; // - (actual_rbw_x10 > 5000 ? 200000 : 0);// - DEFAULT_SPUR_OFFSET/2; // apply IF spur shift local_IF = local_IF; // - (actual_rbw_x10 > 5000 ? 200000 : 0);// - DEFAULT_SPUR_OFFSET/2; // apply IF spur shift
} }
@ -4172,33 +4174,9 @@ again: // Spur redu
} }
#endif #endif
} }
} else { } else { // No spur removal
int spur_flag = avoid_spur(lf); int spur_flag = avoid_spur(lf);
#ifdef TINYSA4 #ifdef TINYSA4
#if 0
if (debug_avoid) {
if (spur_flag == F_NEAR_SPUR) {
stored_t[i] = -70.0; // Display when to do spur shift in the stored trace
// local_IF -= DEFAULT_SPUR_OFFSET/2;
} else if (spur_flag == F_AT_SPUR){
stored_t[i] = -60.0;
// Display when to do spur shift in the stored trace
if (debug_avoid_second) {
if (S_IS_AUTO(setting.below_IF) && lf < local_IF/2 - 2000000) {
setting.below_IF = S_AUTO_ON;
local_IF = local_IF; // No spur removal and no spur, center in IF
} else if (setting.auto_IF) {
local_IF = local_IF + DEFAULT_SPUR_OFFSET/2;
// if (actual_rbw_x10 == 6000 )
// local_IF = local_IF + 50000;
LO_spur_shifted = true;
}
}
} else {
stored_t[i] = -90.0; // Display when to do spur shift in the stored trace
}
} else
#endif
if(spur_flag) { // check if alternate IF is needed to avoid spur. if(spur_flag) { // check if alternate IF is needed to avoid spur.
if (spur_flag == F_NEAR_SPUR) { if (spur_flag == F_NEAR_SPUR) {
if (debug_avoid) stored_t[i] = -70.0; // Display when to do spur shift in the stored trace if (debug_avoid) stored_t[i] = -70.0; // Display when to do spur shift in the stored trace
@ -4213,7 +4191,7 @@ again: // Spur redu
} else } else
#endif #endif
if (setting.auto_IF) { if (setting.auto_IF) {
local_IF = local_IF + (actual_rbw_x10 > 2000 ? DEFAULT_SPUR_OFFSET : DEFAULT_SPUR_OFFSET/2); // TODO find better way to shift spur away at large RBW/2; 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 ) // if (actual_rbw_x10 == 6000 )
// local_IF = local_IF + 50000; // local_IF = local_IF + 50000;
LO_spur_shifted = true; LO_spur_shifted = true;
@ -4237,7 +4215,7 @@ again: // Spur redu
if (lf<LOW_SHIFT_FREQ) { // below 2MHz if (lf<LOW_SHIFT_FREQ) { // below 2MHz
local_IF += DEFAULT_SPUR_OFFSET-(actual_rbw_x10 > 1000 ? 200000 : 0); // Shift to avoid zero Hz peak local_IF += DEFAULT_SPUR_OFFSET-(actual_rbw_x10 > 1000 ? 200000 : 0); // Shift to avoid zero Hz peak
LO_shifting = true; LO_shifting = true;
} } else
if (config.hide_21MHz && S_IS_AUTO(setting.below_IF)) { if (config.hide_21MHz && S_IS_AUTO(setting.below_IF)) {
if (binary_search_table(lf, additional_spur_table, ADDITIONAL_SPUR_TABLE_SIZE, ADDITIONAL_SPUR_TABE_GATE)) if (binary_search_table(lf, additional_spur_table, ADDITIONAL_SPUR_TABLE_SIZE, ADDITIONAL_SPUR_TABE_GATE))
{ {
@ -4246,6 +4224,8 @@ again: // Spur redu
setting.below_IF= S_AUTO_OFF; setting.below_IF= S_AUTO_OFF;
} }
} }
else if (hw_if && actual_rbw_x10 < 8500)
local_IF += 250000;
#else #else
local_IF = local_IF; // + DEFAULT_SPUR_OFFSET/2; // No spure removal and no spur, center in IF local_IF = local_IF; // + DEFAULT_SPUR_OFFSET/2; // No spure removal and no spur, center in IF
@ -4265,7 +4245,7 @@ again: // Spur redu
if (setting.modulation == MO_EXTERNAL) // VERY SPECIAL CASE !!!!!! LO input via high port if (setting.modulation == MO_EXTERNAL) // VERY SPECIAL CASE !!!!!! LO input via high port
local_IF += lf; local_IF += lf;
} }
} // --------------- END IF calculation ------------------------ } // --------------- END IF calculation ------------------------ all low input/output modes with IF setting
TRACE(2); TRACE(2);
// ------------- Set LO --------------------------- // ------------- Set LO ---------------------------
@ -4412,7 +4392,7 @@ again: // Spur redu
ADF4351_R_counter(-3); ADF4351_R_counter(-3);
} else { } else {
if (hw_if) if (hw_if)
ADF4351_R_counter(7); ADF4351_R_counter(4);
else else
ADF4351_R_counter(4); ADF4351_R_counter(4);
} }
@ -4487,6 +4467,8 @@ again: // Spur redu
actual_drive = 3; actual_drive = 3;
// else if (lf < DRIVE0_MAX_FREQ) // below 600MHz // else if (lf < DRIVE0_MAX_FREQ) // below 600MHz
// actual_drive = 0; // actual_drive = 0;
else if (setting.mode == M_GENLOW && hw_if)
actual_drive = 0;
else if (lf < DRIVE1_MAX_FREQ || hw_if) // below 1.2GHz else if (lf < DRIVE1_MAX_FREQ || hw_if) // below 1.2GHz
actual_drive = 1; actual_drive = 1;
else if (lf < DRIVE2_MAX_FREQ) // below 2GHz else if (lf < DRIVE2_MAX_FREQ) // below 2GHz
@ -6300,7 +6282,7 @@ const test_case_t test_case [] =
TEST_CASE_STRUCT(TC_SIGNAL, TP_30MHZ_ULTRA, 30, 1, CAL_LEVEL, 10, -85), // 4 Test Ultra mode TEST_CASE_STRUCT(TC_SIGNAL, TP_30MHZ_ULTRA, 30, 1, CAL_LEVEL, 10, -85), // 4 Test Ultra mode
#define TEST_SILENCE 4 #define TEST_SILENCE 4
TEST_CASE_STRUCT(TC_BELOW, TP_SILENT, 200, 100, -70, 0, 0), // 5 Wide band noise floor low mode TEST_CASE_STRUCT(TC_BELOW, TP_SILENT, 200, 100, -70, 0, 0), // 5 Wide band noise floor low mode
TEST_CASE_STRUCT(TC_ABOVE, TP_30MHZ_DIRECT,900, 10, -90, 0, -90), // 6 Direct path with harmonic TEST_CASE_STRUCT(TC_ABOVE, TP_30MHZ_DIRECT,900, 10, -60, 0, -80), // 6 Direct path with harmonic
TEST_CASE_STRUCT(TC_SIGNAL, TP_10MHZEXTRA, 30, 14, CAL_LEVEL, 26, -45), // 7 BPF loss and stop band TEST_CASE_STRUCT(TC_SIGNAL, TP_10MHZEXTRA, 30, 14, CAL_LEVEL, 26, -45), // 7 BPF loss and stop band
TEST_CASE_STRUCT(TC_FLAT, TP_10MHZEXTRA, 30, 14, -28, 9, -60), // 8 BPF pass band flatness TEST_CASE_STRUCT(TC_FLAT, TP_10MHZEXTRA, 30, 14, -28, 9, -60), // 8 BPF pass band flatness
TEST_CASE_STRUCT(TC_BELOW, TP_15MHZ_LNA2, 855, 1, -80, 0, -80), // 9 LPF cutoff TEST_CASE_STRUCT(TC_BELOW, TP_15MHZ_LNA2, 855, 1, -80, 0, -80), // 9 LPF cutoff
@ -6390,19 +6372,18 @@ static volatile int test_wait = false;
static float test_value; static float test_value;
#ifdef TINYSA4 #ifdef TINYSA4
static freq_t spur_test_freq = 900000000; static freq_t spur_test_freq = 930000000;
static freq_t direct_test_freq = 180000000; static freq_t direct_test_freq = 990000000; // 180000000;
void determine_direct_test_freq(void) { void determine_direct_test_freq(void) {
if (hw_if) if (!hw_if)
direct_test_freq = 870000000;
return; return;
int old_ultra = config.ultra; int old_ultra = config.ultra;
config.ultra = true; config.ultra = true;
float max_level = -150; float max_level = -150;
set_refer_output(0); set_refer_output(0);
for (freq_t test_freq = 900000000UL; test_freq < 1000000000UL; test_freq += 30000000) { for (freq_t test_freq = 1020000000UL; test_freq < 1100000000UL; test_freq += 30000000) {
dirty = true; dirty = true;
float v = PURE_TO_float(perform(false, 0, test_freq, false)); float v = PURE_TO_float(perform(false, 0, test_freq, false));
if (v > max_level) { if (v > max_level) {
@ -6414,7 +6395,10 @@ void determine_direct_test_freq(void) {
} }
static float lpf_test_level = 0; static float lpf_test_level = 0;
#define LPF_TEST_FREQ 795000000 #define LPF_TEST_FREQ (hw_if ? 915000000 : 795000000)
#define LPF_TEST_FREQ2 (hw_if ? 1005000000 : 855000000)
void determine_lpf_test_level(void) { void determine_lpf_test_level(void) {
int old_ultra = config.ultra; int old_ultra = config.ultra;
config.ultra = true; config.ultra = true;
@ -6535,7 +6519,7 @@ int validate_signal_within(int i, float margin)
c_freq = LPF_TEST_FREQ; c_freq = LPF_TEST_FREQ;
#endif #endif
test_fail_cause[i] = "Frequency "; test_fail_cause[i] = "Frequency ";
if (peakFreq < c_freq - 500000 || c_freq + 500000 < peakFreq ) if ((peakFreq < c_freq - 500000 || c_freq + 500000 < peakFreq) && setting.measurement != M_PASS_BAND)
return TS_FAIL; return TS_FAIL;
test_fail_cause[i] = ""; test_fail_cause[i] = "";
return TS_PASS; return TS_PASS;
@ -6797,10 +6781,10 @@ common_silent:
setting.tracking = true; //Sweep BPF setting.tracking = true; //Sweep BPF
setting.auto_IF = false; setting.auto_IF = false;
#ifdef TINYSA4 #ifdef TINYSA4
setting.frequency_IF = config.frequency_IF1 + STATIC_DEFAULT_SPUR_OFFSET/3; // This is the place where the setting.frequency_IF = config.frequency_IF1; // Center on SAW filter
set_refer_output(0); set_refer_output(0);
#else #else
setting.frequency_IF = DEFAULT_IF+210000; // Center on SAW filters setting.frequency_IF = DEFAULT_IF + 210000; // Center on SAW filters
set_refer_output(2); set_refer_output(2);
#endif #endif
markers[1].enabled = M_ENABLED; markers[1].enabled = M_ENABLED;
@ -6842,6 +6826,8 @@ common_silent:
break; break;
#ifdef TINYSA4 #ifdef TINYSA4
case TP_15MHZ_LNA: case TP_15MHZ_LNA:
force_signal_path = true;
test_path = 1;
determine_lpf_test_level(); determine_lpf_test_level();
goto simple; goto simple;
case TP_15MHZ_LNA2: case TP_15MHZ_LNA2:
@ -6849,6 +6835,9 @@ common_silent:
test_path = 1; test_path = 1;
goto simple; goto simple;
case TP_30MHZ_DIRECT: case TP_30MHZ_DIRECT:
force_signal_path = true;
test_path = 4;
goto simple;
case TP_30MHZ_ULTRA: case TP_30MHZ_ULTRA:
case TP_30MHZ_LNA: case TP_30MHZ_LNA:
#endif #endif
@ -6910,23 +6899,20 @@ common_silent:
TRACE_ENABLE(TRACE_STORED_FLAG); TRACE_ENABLE(TRACE_STORED_FLAG);
setting.stored[TRACE_STORED] = true; setting.stored[TRACE_STORED] = true;
set_reflevel(test_case[i].pass+10); set_reflevel(test_case[i].pass+10);
freq_t c_freq = (freq_t)(test_case[i].center * 1000000);
#ifdef TINYSA4 #ifdef TINYSA4
if (test_case[i].kind == TC_JUMP) { if (test_case[i].kind == TC_JUMP) {
set_sweep_frequency(ST_CENTER, test_freq); c_freq = test_freq;
setting.repeat = 10; setting.repeat = 10;
} }
else else if (test_case[i].setup == TP_15MHZ_LNA2)
#endif c_freq = LPF_TEST_FREQ2;
{ else if (test_case[i].setup == TP_30MHZ_DIRECT)
freq_t c_freq = (freq_t)(test_case[i].center * 1000000);
#ifdef TINYSA4
if (test_case[i].setup == TP_30MHZ_DIRECT)
c_freq = direct_test_freq; c_freq = direct_test_freq;
if (test_case[i].setup == TP_15MHZ_LNA) else if (test_case[i].setup == TP_15MHZ_LNA)
c_freq = LPF_TEST_FREQ; c_freq = LPF_TEST_FREQ;
#endif #endif
set_sweep_frequency(ST_CENTER, c_freq); set_sweep_frequency(ST_CENTER, c_freq);
}
set_sweep_frequency(ST_SPAN, (freq_t)(test_case[i].span * 1000000)); set_sweep_frequency(ST_SPAN, (freq_t)(test_case[i].span * 1000000));
draw_cal_status(); draw_cal_status();
} }
@ -7018,16 +7004,16 @@ void sort_spur_count(void) {
//static bool test_wait = false; //static bool test_wait = false;
static int test_step = 0; static int test_step = 0;
void self_test(int test) void selftest(int test)
{ {
bool no_wait = false; bool no_wait = false;
#ifdef TINYSA4 #ifdef TINYSA4
bool old_ultra = config.ultra; bool old_ultra = config.ultra;
config.ultra = true; config.ultra = true;
if (adc_vbat_read() < 3800) { // if (adc_vbat_read() < 3800) {
drawMessageBox("Battery low", "Charge before testing", 2000); // drawMessageBox("Battery low", "Charge before testing", 2000);
goto quit; // goto quit;
} // }
#endif #endif
setting.external_gain = 0; // Must be 0 setting.external_gain = 0; // Must be 0
// set_sweep_points(POINTS_COUNT); // set_sweep_points(POINTS_COUNT);
@ -7774,7 +7760,7 @@ float get_jump_config(int i) {
return 0; 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 #define ULTRA_HARMONIC_CAL_FREQ 5340000000
#else #else
enum {CS_NORMAL, CS_SWITCH, CS_MAX }; enum {CS_NORMAL, CS_SWITCH, CS_MAX };
@ -7856,9 +7842,9 @@ void calibrate(void)
// setting.frequency_IF = config.frequency_IF1; // set in selftest // setting.frequency_IF = config.frequency_IF1; // set in selftest
float direct_level=0.0; float direct_level=0.0;
setting.test_argument = -7; setting.test_argument = -7;
self_test(0); selftest(0);
int if_error = peakFreq - 30000000; int if_error = peakFreq - 30000000;
if (if_error > -1000000 && if_error < 1000000) { if (if_error > -2000000 && if_error < 2000000) {
config.frequency_IF1 += if_error; config.frequency_IF1 += if_error;
setting.auto_IF = true; setting.auto_IF = true;
setting.frequency_IF = config.frequency_IF1; setting.frequency_IF = config.frequency_IF1;
@ -7998,13 +7984,13 @@ void calibrate(void)
force_signal_path = true; force_signal_path = true;
break; break;
case CS_DIRECT_REF: case CS_DIRECT_REF:
test_path = 0; // Normal test_path = 3; // Ultra LNA
setting.spur_removal = S_OFF; setting.spur_removal = S_OFF;
direct_common: direct_common:
set_sweep_frequency(ST_CENTER, direct_test_freq); set_sweep_frequency(ST_CENTER, direct_test_freq);
force_signal_path = true; force_signal_path = true;
break; break;
#if 0 #if 1
case CS_DIRECT: case CS_DIRECT:
test_path = 4; // Direct path at 900MHz test_path = 4; // Direct path at 900MHz
goto direct_common; goto direct_common;
@ -8120,11 +8106,11 @@ low_level:
config.shift_level_offset = direct_level - marker_to_value(0); config.shift_level_offset = direct_level - marker_to_value(0);
else if (calibration_stage == CS_DIRECT_REF) else if (calibration_stage == CS_DIRECT_REF)
direct_level = marker_to_value(0); direct_level = marker_to_value(0);
// else if (calibration_stage == CS_DIRECT) else if (calibration_stage == CS_DIRECT)
// offset = set_actual_power(direct_level); offset = set_actual_power(direct_level);
else if (calibration_stage == CS_DIRECT_LNA){ else if (calibration_stage == CS_DIRECT_LNA){
offset = set_actual_power(direct_level); offset = set_actual_power(direct_level);
config.direct_level_offset = config.direct_lna_level_offset - (config.low_level_offset - config.lna_level_offset); // config.direct_level_offset = config.direct_lna_level_offset - (config.low_level_offset - config.lna_level_offset);
} }
else else
#endif #endif

44
ui.c

@ -2453,6 +2453,18 @@ static UI_FUNCTION_ADV_CALLBACK(menu_modulation_acb)
// menu_move_back(false); // Don't move back // menu_move_back(false); // Don't move back
} }
static UI_FUNCTION_ADV_CALLBACK(menu_level_in_dBuV)
{
(void)item;
(void)data;
if (b){
b->icon = setting.dBuV ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK;
return;
}
setting.dBuV = !setting.dBuV;
menu_move_back(false);
}
static UI_FUNCTION_ADV_CALLBACK(menu_smodulation_acb){ static UI_FUNCTION_ADV_CALLBACK(menu_smodulation_acb){
(void)item; (void)item;
(void)data; (void)data;
@ -4361,6 +4373,7 @@ static const menuitem_t menu_modulation[] = {
{ MT_FORM | MT_ADV_CALLBACK | MT_LOW, MO_EXTERNAL,MT_CUSTOM_LABEL, menu_modulation_acb}, { MT_FORM | MT_ADV_CALLBACK | MT_LOW, MO_EXTERNAL,MT_CUSTOM_LABEL, menu_modulation_acb},
{ MT_FORM | MT_KEYPAD, KM_MODULATION, "FREQ: %s", "1Hz..5kHz"}, { MT_FORM | MT_KEYPAD, KM_MODULATION, "FREQ: %s", "1Hz..5kHz"},
#endif #endif
{ MT_FORM | MT_ADV_CALLBACK, 0, "Level in dBuV", menu_level_in_dBuV},
{ MT_FORM | MT_NONE, 0, NULL, menu_back} // next-> menu_back { MT_FORM | MT_NONE, 0, NULL, menu_back} // next-> menu_back
}; };
@ -5435,19 +5448,31 @@ static void fetch_numeric_target(uint8_t mode)
end_level = level_max(); end_level = level_max();
uistat.value += setting.external_gain; uistat.value += setting.external_gain;
end_level += setting.external_gain; end_level += setting.external_gain;
char *u = "m";
float el = end_level;
if (setting.dBuV) {
u = "uV";
uistat.value += 107;
el += 107;
}
if (setting.level_sweep != 0) if (setting.level_sweep != 0)
plot_printf(uistat.text, sizeof uistat.text, "%.1f to %.1fdBm", uistat.value, end_level); plot_printf(uistat.text, sizeof uistat.text, "%.1f to %.1fdBm", uistat.value, el);
else else
#ifdef TINYSA4 #ifdef TINYSA4
plot_printf(uistat.text, sizeof uistat.text, "%+.1fdBm %s", uistat.value, (setting.disable_correction?"Uncorrected":"")); plot_printf(uistat.text, sizeof uistat.text, "%+.1fdB%s %s", uistat.value, u, (setting.disable_correction?"Uncorrected":""));
#else #else
plot_printf(uistat.text, sizeof uistat.text, "%+.1fdBm", uistat.value); plot_printf(uistat.text, sizeof uistat.text, "%+.1fdB%s", uistat.value, u);
#endif #endif
break; break;
case KM_HIGHOUTLEVEL: case KM_HIGHOUTLEVEL:
uistat.value = get_level(); // compensation for dB offset during low output mode uistat.value = get_level(); // compensation for dB offset during low output mode
uistat.value += setting.external_gain; uistat.value += setting.external_gain;
plot_printf(uistat.text, sizeof uistat.text, "%+.1fdBm", uistat.value); char *unit = "m";
if (setting.dBuV) {
unit = "uV";
uistat.value += 107;
}
plot_printf(uistat.text, sizeof uistat.text, "%+.1fdB%s", uistat.value, unit);
break; break;
case KM_DECAY: case KM_DECAY:
uistat.value = setting.decay; uistat.value = setting.decay;
@ -5711,9 +5736,13 @@ set_numeric_value(void)
set_repeat(uistat.value); set_repeat(uistat.value);
break; break;
case KM_LOWOUTLEVEL: case KM_LOWOUTLEVEL:
if (setting.dBuV)
uistat.value -= 107;
set_level(uistat.value - setting.external_gain); set_level(uistat.value - setting.external_gain);
break; break;
case KM_HIGHOUTLEVEL: case KM_HIGHOUTLEVEL:
if (setting.dBuV)
uistat.value -= 107;
set_level(uistat.value - setting.external_gain); set_level(uistat.value - setting.external_gain);
break; break;
case KM_DECAY: case KM_DECAY:
@ -7015,7 +7044,6 @@ menu_select_touch(const menuitem_t * m, int i, int pos)
while (touch_check() != EVT_TOUCH_NONE){ while (touch_check() != EVT_TOUCH_NONE){
touch_position(&touch_x, &touch_y); touch_position(&touch_x, &touch_y);
if (abs(touch_x - prev_touch_x) < 2) continue; if (abs(touch_x - prev_touch_x) < 2) continue;
fetch_numeric_target(keypad); fetch_numeric_target(keypad);
int new_slider = touch_x - LCD_WIDTH/2; // Can have negative outcome int new_slider = touch_x - LCD_WIDTH/2; // Can have negative outcome
if (new_slider < - (MENU_FORM_WIDTH-8)/2 - 1) if (new_slider < - (MENU_FORM_WIDTH-8)/2 - 1)
@ -7081,7 +7109,10 @@ menu_select_touch(const menuitem_t * m, int i, int pos)
chThdSleepMilliseconds(100); chThdSleepMilliseconds(100);
} else if (keypad == KM_LOWOUTLEVEL) { } else if (keypad == KM_LOWOUTLEVEL) {
uistat.value = setting.external_gain + ((touch_x - OFFSETX+4) * level_range() ) / (MENU_FORM_WIDTH-8) + level_min() ; uistat.value = setting.external_gain + ((touch_x - OFFSETX+4) * level_range() ) / (MENU_FORM_WIDTH-8) + level_min() ;
bool old_dBuV = setting.dBuV;
setting.dBuV = false;
set_keypad_value(keypad); set_keypad_value(keypad);
setting.dBuV = old_dBuV;;
draw_menu_mask(1<<i); draw_menu_mask(1<<i);
perform(false, 0, get_sweep_frequency(ST_CENTER), false); perform(false, 0, get_sweep_frequency(ST_CENTER), false);
} else if (keypad == KM_HIGHOUTLEVEL) { } else if (keypad == KM_HIGHOUTLEVEL) {
@ -7127,7 +7158,10 @@ menu_select_touch(const menuitem_t * m, int i, int pos)
check_frequency_slider(uistat.freq_value); check_frequency_slider(uistat.freq_value);
} }
if (do_exit){ if (do_exit){
bool old_dBuV = setting.dBuV;
setting.dBuV = false;
set_keypad_value(keypad); set_keypad_value(keypad);
setting.dBuV = old_dBuV;;
selection = -1; selection = -1;
draw_menu_mask(1<<i); draw_menu_mask(1<<i);
perform(false, 0, get_sweep_frequency(ST_CENTER), false); perform(false, 0, get_sweep_frequency(ST_CENTER), false);

@ -204,6 +204,7 @@ finish3:
while (f_read(fs_file, buf_8, buffer_size, &size) == FR_OK && size > 0) { while (f_read(fs_file, buf_8, buffer_size, &size) == FR_OK && size > 0) {
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
uint8_t c = buf_8[i]; uint8_t c = buf_8[i];
if (c == ',') c = ' ';
if (c == '\r') { // New line (Enter) if (c == '\r') { // New line (Enter)
line[j] = 0; j = 0; line[j] = 0; j = 0;
char *args[16]; char *args[16];

Loading…
Cancel
Save

Powered by TurnKey Linux.