Merge branch 'master' into tinySA-V4-SI4463

Removed_REF_marker
erikkaashoek 5 years ago
commit 082ff3572e

@ -98,7 +98,7 @@ tinySA is a trademark owned by its respective owner. Unauthorized use the the na
## Authorized Distributor ## Authorized Distributor
* [NotYet](https://www.notyet.com/) * [See the Wiki](https://tinysa.org/wiki/pmwiki.php?n=Main.Buying)
## Credit ## Credit

@ -1371,31 +1371,41 @@ search_maximum(int m, int center, int span)
//static int spur_old_stepdelay = 0; //static int spur_old_stepdelay = 0;
static const unsigned int spur_IF = 433800000; // The IF frequency for which the spur table is value static const unsigned int spur_IF = 433800000; // The IF frequency for which the spur table is value
static const unsigned int spur_alternate_IF = 433900000; // if the frequency is found in the spur table use this IF frequency static const unsigned int spur_alternate_IF = 434000000; // if the frequency is found in the spur table use this IF frequency
static const int spur_table[] = // Frequencies to avoid static const int spur_table[] = // Frequencies to avoid
{ {
580000, // 433.8 MHz table // 580000, // 433.8 MHz table
961000, 960000,
1600000, 1600000,
1837000, // Real signal // 1837000, // Real signal
2755000, // Real signal // 2755000, // Real signal
2760000, // 2760000,
2961000, 2960000,
4933000, 4933000,
4960000, 4960000,
6961000, 6960000,
6980000, // 6980000,
8267000, 8267000,
8961000, 8960000,
10000000, // 10000000,
10960000, 10960000,
11600000, 11600000,
12960000,
14960000,
16960000, 16960000,
22960000, 18960000,
21600000,
// 22960000,
24960000,
28960000, 28960000,
29800000, // 29800000,
38105000, 31600000,
49500000, 34960000,
33930000,
// 38105000,
40960000,
41600000,
49650000,
#ifdef IF_AT_4339 #ifdef IF_AT_4339
780000, // 433.9MHz table 780000, // 433.9MHz table
830000, 830000,
@ -1469,6 +1479,7 @@ static float old_a = -150; // cached value to reduce writes to level re
static pureRSSI_t correct_RSSI; static pureRSSI_t correct_RSSI;
static pureRSSI_t correct_RSSI_freq; static pureRSSI_t correct_RSSI_freq;
systime_t start_of_sweep_timestamp; systime_t start_of_sweep_timestamp;
static systime_t sweep_elapsed = 0; // Time since first start of sweeping, used only for auto attenuate
pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup
{ {
@ -1477,7 +1488,8 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking)
apply_settings(); // Initialize HW apply_settings(); // Initialize HW
scandirty = true; // This is the first pass with new settings scandirty = true; // This is the first pass with new settings
dirty = false; dirty = false;
if (setting.spur == -1) setting.spur = 1; // ensure spur processing starts in right phase sweep_elapsed = chVTGetSystemTimeX(); // for measuring accumulated time
if (setting.spur == -1) setting.spur = 1; // ensure spur processing starts in right phase
// Set for actual time pre calculated value (update after sweep) // Set for actual time pre calculated value (update after sweep)
setting.actual_sweep_time_us = calc_min_sweep_time_us(); setting.actual_sweep_time_us = calc_min_sweep_time_us();
// Change actual sweep time as user input if it greater minimum // Change actual sweep time as user input if it greater minimum
@ -1573,7 +1585,7 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking)
else else
auto_set_AGC_LNA(true); auto_set_AGC_LNA(true);
} }
modulation_again:
// ----------------------------------------------------- modulation for output modes --------------------------------------- // ----------------------------------------------------- modulation for output modes ---------------------------------------
if (MODE_OUTPUT(setting.mode)){ if (MODE_OUTPUT(setting.mode)){
if (setting.modulation == MO_AM_1kHz || setting.modulation == MO_AM_10Hz) { // AM modulation if (setting.modulation == MO_AM_1kHz || setting.modulation == MO_AM_10Hz) { // AM modulation
@ -1763,6 +1775,11 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking)
start_of_sweep_timestamp = chVTGetSystemTimeX(); // initialize start sweep time start_of_sweep_timestamp = chVTGetSystemTimeX(); // initialize start sweep time
if (MODE_OUTPUT(setting.mode)) { // No substepping and no RSSI in output mode if (MODE_OUTPUT(setting.mode)) { // No substepping and no RSSI in output mode
if (break_on_operation && operation_requested) // break subscanning if requested
return(0); // abort
if (MODE_OUTPUT(setting.mode) && setting.modulation != MO_NONE && setting.modulation != MO_EXTERNAL) // if in output mode with modulation
goto modulation_again; // Keep repeating sweep loop till user aborts by input
return(0); return(0);
} }
// ---------------- Prepare RSSI ---------------------- // ---------------- Prepare RSSI ----------------------
@ -1872,7 +1889,8 @@ int16_t max_index[MAX_MAX];
int16_t cur_max = 0; int16_t cur_max = 0;
static int low_count = 0; static int low_count = 0;
static int sweep_counter = 0; static int sweep_counter = 0; // Only used for HW refresh
// main loop for measurement // main loop for measurement
static bool sweep(bool break_on_operation) static bool sweep(bool break_on_operation)
{ {
@ -2115,17 +2133,21 @@ sweep_again: // stay in sweep loop when output mo
if (!in_selftest && setting.mode == M_LOW && setting.auto_attenuation && max_index[0] > 0) { // calculate and apply auto attenuate if (!in_selftest && setting.mode == M_LOW && setting.auto_attenuation && max_index[0] > 0) { // calculate and apply auto attenuate
setting.atten_step = false; // No step attenuate in low mode auto attenuate setting.atten_step = false; // No step attenuate in low mode auto attenuate
int changed = false; int changed = false;
int delta = 0;
int actual_max_level = (int) (actual_t[max_index[0]] - get_attenuation()); int actual_max_level = (int) (actual_t[max_index[0]] - get_attenuation());
if (actual_max_level < AUTO_TARGET_LEVEL && setting.attenuate > 0) { if (actual_max_level < AUTO_TARGET_LEVEL && setting.attenuate > 0) {
setting.attenuate -= AUTO_TARGET_LEVEL - actual_max_level; delta = - (AUTO_TARGET_LEVEL - actual_max_level);
} else if (actual_max_level > AUTO_TARGET_LEVEL && setting.attenuate < 30) {
delta = actual_max_level - AUTO_TARGET_LEVEL;
}
if ((chVTGetSystemTimeX() - sweep_elapsed > 10000 && delta != 0) || delta > 5 ) {
setting.attenuate += delta;
if (setting.attenuate < 0) if (setting.attenuate < 0)
setting.attenuate= 0; setting.attenuate= 0;
changed = true;
} else if (actual_max_level > AUTO_TARGET_LEVEL && setting.attenuate < 30) {
setting.attenuate += actual_max_level - AUTO_TARGET_LEVEL;
if (setting.attenuate > 30) if (setting.attenuate > 30)
setting.attenuate = 30; setting.attenuate = 30;
changed = true; changed = true;
sweep_elapsed = chVTGetSystemTimeX();
} }
// Try update settings // Try update settings
@ -3223,43 +3245,41 @@ void self_test(int test)
ili9341_clear_screen(); ili9341_clear_screen();
reset_settings(M_LOW); reset_settings(M_LOW);
set_refer_output(-1); set_refer_output(-1);
} else if (test ==1) { } else if (test == 1) {
float p2, p1, p;
in_selftest = true; // Spur search in_selftest = true; // Spur search
reset_settings(M_LOW); reset_settings(M_LOW);
test_prepare(4); test_prepare(4);
setting.auto_IF = false;
setting.frequency_IF=433850000;
setting.frequency_step = 30000;
if (setting.test_argument > 0)
setting.frequency_step=setting.test_argument;
int f = 400000; // Start search at 400kHz int f = 400000; // Start search at 400kHz
// int i = 0; // Index in spur table (temp_t) // int i = 0; // Index in spur table (temp_t)
pureRSSI_t p2, p1, p; set_RBW(setting.frequency_step/100);
#define FREQ_STEP 3000
set_RBW(FREQ_STEP/100);
last_spur = 0; last_spur = 0;
for (int j = 0; j < 10; j++) { for (int j = 0; j < 4; j++) {
p2 = perform(false, 0, f, false); p2 = PURE_TO_float(perform(false, 0, f, false));
vbwSteps = 1; vbwSteps = 1;
f += FREQ_STEP; f += setting.frequency_step;
p1 = perform(false, 1, f, false); p1 = PURE_TO_float(perform(false, 1, f, false));
f += FREQ_STEP; f += setting.frequency_step;
shell_printf("\n\rStarting with %4.2f, %4.2f and IF at %d\n\r", p2, p1, setting.frequency_IF); shell_printf("\n\rStarting with %4.2f, %4.2f and IF at %d and step of %d\n\r", p2, p1, setting.frequency_IF, setting.frequency_step );
f = 400000; f = 400000;
while (f < 100000000) { while (f < 100000000) {
p = perform(false, 1, f, false); p = PURE_TO_float(perform(false, 1, f, false));
#define SPUR_DELTA float_TO_PURE_RSSI(6) #define SPUR_DELTA 6
if ( p2 < p1 - SPUR_DELTA && p < p1 - SPUR_DELTA) { if ( p2 < p1 - SPUR_DELTA && p < p1 - SPUR_DELTA) {
// temp_t[i++] = f - FREQ_STEP; shell_printf("Spur of %4.2f at %d with count %d\n\r", p1,(f - setting.frequency_step)/1000, add_spur(f - setting.frequency_step));
shell_printf("Spur of %4.2f at %d with count %d\n\r", p1,(f - FREQ_STEP)/1000, add_spur(f - FREQ_STEP));
} }
// else
// shell_printf("%f at %d\n\r", p1,f - FREQ_STEP);
p2 = p1; p2 = p1;
p1 = p; p1 = p;
f += FREQ_STEP; f += setting.frequency_step;
} }
} }
shell_printf("\n\rTable for IF at %d\n\r", setting.frequency_IF); shell_printf("\n\rTable for IF at %d and step of %d\n\r", setting.frequency_IF, setting.frequency_step);
for (int j = 0; j < last_spur; j++) { for (int j = 0; j < last_spur; j++) {
if ((int)stored_t[j] > 1) if ((int)stored_t[j] > 1)
shell_printf("%d, %d\n\r", ((int)temp_t[j])/1000, (int)stored_t[j]); shell_printf("%d, %d\n\r", ((int)temp_t[j])/1000, (int)stored_t[j]);

@ -446,6 +446,9 @@ static int written[2]= {0,0};
void SI4432_Set_Frequency ( uint32_t Freq ) { void SI4432_Set_Frequency ( uint32_t Freq ) {
// int mode = SI4432_Read_Byte(0x02) & 0x03; // Disabled as unreliable // int mode = SI4432_Read_Byte(0x02) & 0x03; // Disabled as unreliable
// SI4432_Write_Byte(0x07, 0x02); // Switch to tune mode // SI4432_Write_Byte(0x07, 0x02); // Switch to tune mode
Freq = (Freq / 1000 ) * 1000; // force freq to 1000 grid
uint8_t hbsel; uint8_t hbsel;
if (0) shell_printf("%d: Freq %q\r\n", SI4432_Sel, Freq); if (0) shell_printf("%d: Freq %q\r\n", SI4432_Sel, Freq);
if (Freq >= 480000000U) { if (Freq >= 480000000U) {

Loading…
Cancel
Save

Powered by TurnKey Linux.