Freq calibration improvements and factions in k/M/G input

Removed_REF_marker
erikkaashoek 5 years ago
parent a43c28055b
commit 9dce56cabc

@ -517,6 +517,7 @@ static long_t my_atoi(const char *p)
// default dec radix // default dec radix
freq_t my_atoui(const char *p) freq_t my_atoui(const char *p)
{ {
int d = 1;
freq_t value = 0, radix = 10, c; freq_t value = 0, radix = 10, c;
if (*p == '+') p++; if (*p == '+') p++;
if (*p == '0') { if (*p == '0') {
@ -530,17 +531,23 @@ freq_t my_atoui(const char *p)
} }
calculate: calculate:
while (1) { while (1) {
c = *p++ - '0'; c = *p++;
// c = to_upper(*p) - 'A' + 10 if (c == '.') { d = 0; continue; }
c = c - '0';
if (c >= 'A' - '0') c = (c&(~0x20)) - ('A' - '0') + 10; if (c >= 'A' - '0') c = (c&(~0x20)) - ('A' - '0') + 10;
if (c >= radix) break; if (c >= radix) break;
if (d<=0) d--;
value = value * radix + c; value = value * radix + c;
} }
if (d == 1)
d = 0;
switch (*(--p)) { switch (*(--p)) {
case 'k': value *= 1000; break; case 'k': d += 3; break;
case 'M': value *= 1000000; break; case 'M': d += 6; break;
case 'G': value *= 1000000000; break; case 'G': d += 9; break;
} }
while (d-->0)
value *= radix;
return value; return value;
} }
@ -556,7 +563,7 @@ my_atof(const char *p)
while (_isdigit((int)*p)) while (_isdigit((int)*p))
p++; p++;
if (*p == '.') { if (*p == '.') {
float d = 1.0f; float d = 1.0;
p++; p++;
while (_isdigit((int)*p)) { while (_isdigit((int)*p)) {
d /= 10; d /= 10;
@ -1224,6 +1231,8 @@ update_marker_index(void)
for (m = 0; m < MARKERS_MAX; m++) { for (m = 0; m < MARKERS_MAX; m++) {
if (!markers[m].enabled) if (!markers[m].enabled)
continue; continue;
if (markers[m].mtype & M_STORED)
continue;
freq_t f = markers[m].frequency; freq_t f = markers[m].frequency;
if (f == 0) idx = markers[m].index; // Not need update index in no freq if (f == 0) idx = markers[m].index; // Not need update index in no freq
else if (f < fstart) idx = 0; else if (f < fstart) idx = 0;

@ -1387,6 +1387,7 @@ extern void ADF4351_CP(int p);
extern void ADF4351_modulo(int m); extern void ADF4351_modulo(int m);
extern void ADF4351_csr(int c); extern void ADF4351_csr(int c);
extern void ADF4351_fastlock(int c); extern void ADF4351_fastlock(int c);
extern void ADF4351_recalculate_PFDRFout(void);
extern int SI4463_R; extern int SI4463_R;
extern int64_t ADF4350_modulo; extern int64_t ADF4350_modulo;
extern void SI446x_set_AGC_LNA(uint8_t v); extern void SI446x_set_AGC_LNA(uint8_t v);

@ -425,6 +425,7 @@ void set_30mhz(freq_t f)
if (f < 29000000 || f > 31000000) if (f < 29000000 || f > 31000000)
return; return;
config.setting_frequency_30mhz = f; config.setting_frequency_30mhz = f;
ADF4351_recalculate_PFDRFout();
config_save(); config_save();
dirty = true; dirty = true;
update_grid(); update_grid();
@ -1420,7 +1421,7 @@ static const struct {
{ 100, 600, 120, 100, -115}, { 100, 600, 120, 100, -115},
{ 30, 1100, 300, 100, -120}, { 30, 1100, 300, 100, -120},
{ 10, 5000, 600, 100, -122}, { 10, 5000, 600, 100, -122},
{ 3, 10000, 3000, 100, -125} { 3, 14000, 3000, 100, -125}
}; };
#endif #endif
@ -2103,10 +2104,15 @@ void interpolate_maximum(int m)
if (idx > 0 && idx < sweep_points-1) if (idx > 0 && idx < sweep_points-1)
{ {
const int32_t delta_Hz = (int64_t)frequencies[idx + 0] - frequencies[idx + 1]; const int32_t delta_Hz = (int64_t)frequencies[idx + 0] - frequencies[idx + 1];
const float y1 = actual_t[idx - 1]; #ifdef TINYSA4
const float y2 = actual_t[idx + 0]; #define INTER_TYPE double
const float y3 = actual_t[idx + 1]; #else
const float d = abs(delta_Hz) * 0.5f * (y1 - y3) / ((y1 - (2 * y2) + y3) + 1e-12f); #define INTER_TYPE float
#endif
const INTER_TYPE y1 = actual_t[idx - 1];
const INTER_TYPE y2 = actual_t[idx + 0];
const INTER_TYPE y3 = actual_t[idx + 1];
const INTER_TYPE d = abs(delta_Hz) * 0.5 * (y1 - y3) / ((y1 - (2 * y2) + y3) + 1e-12);
//const float bin = (float)idx + d; //const float bin = (float)idx + d;
markers[m].frequency += d; markers[m].frequency += d;
} }
@ -2876,7 +2882,7 @@ modulation_again:
freq_t local_IF; freq_t local_IF;
#ifdef TINYSA4 #ifdef TINYSA4
local_IF = config.frequency_IF1 + STATIC_DEFAULT_SPUR_OFFSET/2; local_IF = config.frequency_IF1 + STATIC_DEFAULT_SPUR_OFFSET/2;
if (setting.mode == M_LOW && ultra && if (setting.mode == M_LOW && setting.frequency_step > 0 && ultra &&
((f < ULTRA_MAX_FREQ && f > MAX_LO_FREQ - local_IF) || ((f < ULTRA_MAX_FREQ && f > MAX_LO_FREQ - local_IF) ||
( f > config.ultra_threshold && f < MIN_BELOW_LO + local_IF)) ( f > config.ultra_threshold && f < MIN_BELOW_LO + local_IF))
) { ) {
@ -4107,29 +4113,6 @@ static bool sweep(bool break_on_operation)
while (m < MARKERS_MAX) { while (m < MARKERS_MAX) {
if (markers[m].enabled && markers[m].mtype & M_TRACKING) { // Available marker found if (markers[m].enabled && markers[m].mtype & M_TRACKING) { // Available marker found
markers[m].index = max_index[i]; markers[m].index = max_index[i];
interpolate_maximum(m);
// markers[m].frequency = frequencies[markers[m].index];
#if 0
float v = actual_t[markers[m].index] - 10.0; // -10dB points
int index = markers[m].index;
freq_t f = markers[m].frequency;
uint32_t s = actual_rbw_x10 * 200; // twice the selected RBW
int left = index, right = index;
while (t > 0 && actual_t[t+1] > v && markers[t].frequency > f - s) // Find left point
t--;
if (t > 0) {
left = t;
}
t = setting._sweep_points-1;;
while (t > setting._sweep_points-1 && actual_t[t+1] > v) // find right -3dB point
t++;
if (t > index) {
right = t;
markers[2].frequency = frequencies[t];
}
#endif
interpolate_maximum(m); interpolate_maximum(m);
m++; m++;
break; // Next maximum break; // Next maximum

@ -472,6 +472,7 @@ static freq_t prev_actual_freq = 0;
void ADF4351_force_refresh(void) { void ADF4351_force_refresh(void) {
prev_actual_freq = 0; prev_actual_freq = 0;
// old_R = -1; // Force updating from config.actual_frequency_30MHz
} }
void ADF4351_modulo(int m) void ADF4351_modulo(int m)
@ -542,6 +543,14 @@ void ADF4351_R_counter(int R)
ADF4351_Set(0); ADF4351_Set(0);
} }
void ADF4351_recalculate_PFDRFout(void){
int local_r = old_R;
old_R = -1;
ADF4351_R_counter(local_r);
}
void ADF4351_mux(int R) void ADF4351_mux(int R)
{ {
registers[2] &= ~ (((unsigned long)0x7) << 26); registers[2] &= ~ (((unsigned long)0x7) << 26);

Loading…
Cancel
Save

Powered by TurnKey Linux.