From 012f915af9fc262e71c42b46c19e22869c21e06f Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Fri, 10 Apr 2020 16:33:46 +0200 Subject: [PATCH] Calibrate frequency --- sa_core.c | 24 +++++++++++++++++++++--- si4432.c | 13 ++++++++++--- ui_sa.c | 19 ++++++++++++++++++- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/sa_core.c b/sa_core.c index eeb80f2..7f16767 100644 --- a/sa_core.c +++ b/sa_core.c @@ -634,8 +634,9 @@ static const int spur_table[] = 580000, 961000, 1600000, - 1837000, - 2755000, + 1837000, // Real signal + 2755000, // Real signal + 2760000, 2961000, 4933000, 4960000, @@ -664,7 +665,7 @@ static const int spur_table[] = 7371 -/* + 870000, 970000, 1460000, @@ -714,6 +715,23 @@ static const int spur_table[] = #endif }; +int binary_search(int f) +{ + int L = 0; + int R = (sizeof spur_table)/sizeof(int); + while (L <= R) { + int m = (L + R) / 2; + if (spur_table[m] < f) + L = m + 1; + else if (spur_table[m] > f) + R = m - 1; + else + return m; + } + return 0; +} + + int avoid_spur(int f) { int window = ((int)actual_rbw ) * 1000*2; diff --git a/si4432.c b/si4432.c index 71ba3c7..b79572c 100644 --- a/si4432.c +++ b/si4432.c @@ -218,11 +218,18 @@ float SI4432_force_RBW(int i) float SI4432_RBW_table(int i){ if (i < 0) return 0; - if (i * 4 >= (sizeof RBW_choices) / 2 ) + if (i * 4 >= (int)(sizeof RBW_choices) / 2 ) return 0; return(RBW_choices[i*4-1]); } +int setting_10mhz = 10000000; + +void set_10mhz(int f) +{ + setting_10mhz = f; +} + void SI4432_Set_Frequency ( long Freq ) { int hbsel; long Carrier; @@ -233,8 +240,8 @@ void SI4432_Set_Frequency ( long Freq ) { hbsel = 0; } int sbsel = 1; - int N = Freq / 10000000; - Carrier = ( 4 * ( Freq - N * 10000000 )) / 625; + int N = Freq / setting_10mhz; + Carrier = ( 4 * ( Freq - N * setting_10mhz )) / 625; int Freq_Band = ( N - 24 ) | ( hbsel << 5 ) | ( sbsel << 6 ); #if 0 SI4432_Write_Byte ( 0x75, Freq_Band ); diff --git a/ui_sa.c b/ui_sa.c index f86c096..0b4aa47 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -55,6 +55,8 @@ extern int setting_auto_reflevel; extern int setting_auto_attenuation; extern int setting_reflevel; extern int setting_scale; +extern int setting_10mhz; +void set_10mhz(int); void SetModulation(int); extern int setting_modulation; void set_measurement(int); @@ -65,7 +67,7 @@ extern int setting_step_delay; enum { KM_START=1, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_REFPOS, KM_SCALE, KM_ATTENUATION, - KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE, KM_LOWOUTLEVEL, KM_DECAY, KM_NOISE + KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE, KM_LOWOUTLEVEL, KM_DECAY, KM_NOISE, KM_10MHZ }; @@ -173,6 +175,7 @@ static const keypads_t * const keypads_mode_tbl[] = { keypads_level, // KM_LOWOUTLEVEL keypads_level, // KM_DECAY keypads_level, // KM_NOISE + keypads_level, // KM_10MHz }; #ifdef __VNA__ @@ -610,6 +613,7 @@ const menuitem_t menu_lowoutputmode[] = { { MT_FORM | MT_KEYPAD, KM_LOWOUTLEVEL, "LEVEL: %s", NULL}, { MT_FORM | MT_SUBMENU, 0, "MODULATION: %s", menu_modulation}, { MT_FORM | MT_KEYPAD, KM_SPAN, "SPAN: %s", NULL}, + { MT_FORM | MT_KEYPAD, KM_10MHZ, "10MHZ: %s", NULL}, { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel }; @@ -787,6 +791,7 @@ static const menuitem_t menu_settings2[] = { MT_CALLBACK, 2, "BPF", menu_settings2_cb}, { MT_KEYPAD, KM_DECAY, "\2HOLD\0TIME", NULL}, { MT_KEYPAD, KM_NOISE, "\2NOISE\0LEVEL", NULL}, + { MT_KEYPAD, KM_10MHZ, "\00210MHZ\0ACTUAL", NULL}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -1090,6 +1095,11 @@ static void fetch_numeric_target(void) uistat.value = setting_noise; plot_printf(uistat.text, sizeof uistat.text, "%3d", uistat.value); break; + case KM_10MHZ: + uistat.value = setting_10mhz; + plot_printf(uistat.text, sizeof uistat.text, "%3.6fMHz", uistat.value / 1000000.0); + break; + } { @@ -1157,5 +1167,12 @@ set_numeric_value(void) case KM_NOISE: set_noise(uistat.value); break; + case KM_10MHZ: + if (uistat.value < 9000000) { + set_10mhz(setting_10mhz + uistat.value); + } else + set_10mhz(uistat.value); + dirty = true; + break; } }