diff --git a/main.c b/main.c index be97a17..096baf9 100644 --- a/main.c +++ b/main.c @@ -958,7 +958,7 @@ config_t config = { .correction_value = { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 }, // .correction_value = { 0, 0, 0, 0, 0.0, 1.5, 3, 6, 10, 10 }, #endif - .setting_frequency_10mhz = 10000000, + .setting_frequency_30mhz = 30000000, .cor_am = -14, .cor_wfm = -17, .cor_nfm = -17, diff --git a/nanovna.h b/nanovna.h index 95c277f..e3a0687 100644 --- a/nanovna.h +++ b/nanovna.h @@ -263,6 +263,7 @@ void set_R(int f); void set_step_delay(int t); void set_offset_delay(int t); void set_repeat(int); +void clear_frequency_cache(void); void set_level_sweep(float); void set_level(float); void set_sweep_time_us(uint32_t); @@ -304,7 +305,7 @@ void set_attack(int); void set_noise(int); void toggle_tracking_output(void); extern int32_t frequencyExtra; -void set_10mhz(uint32_t f); +void set_30mhz(uint32_t f); void set_modulation(int); void set_modulation_frequency(int); int search_maximum(int m, uint32_t center, int span); @@ -549,7 +550,7 @@ typedef struct config { uint32_t correction_frequency[CORRECTION_POINTS]; float correction_value[CORRECTION_POINTS]; uint32_t deviceid; - uint32_t setting_frequency_10mhz; + uint32_t setting_frequency_30mhz; uint16_t gridlines; uint16_t hambands; @@ -859,7 +860,7 @@ typedef struct setting extern setting_t setting; -extern int setting_frequency_10mhz; +//extern int setting_frequency_30mhz; void reset_settings(int m); diff --git a/sa_core.c b/sa_core.c index 2c53257..9343e71 100644 --- a/sa_core.c +++ b/sa_core.c @@ -50,6 +50,15 @@ static unsigned long old_freq[5] = { 0, 0, 0, 0,0}; static unsigned long real_old_freq[5] = { 0, 0, 0, 0,0}; static long real_offset = 0; +void clear_frequency_cache(void) +{ + for (unsigned int i = 0; i < sizeof(old_freq)/sizeof(unsigned long) ; i++) { + old_freq[i] = 0; + real_old_freq[i] = 0; + } + ADF4351_force_refresh(); +} + //int setting.refer = -1; // Off by default const int reffer_freq[] = {30000000, 15000000, 10000000, 4000000, 3000000, 2000000, 1000000}; @@ -159,8 +168,7 @@ void reset_settings(int m) setting.mirror_masking = 0; setting.slider_position = 0; setting.slider_span = 100000; - -#endif + #endif switch(m) { case M_LOW: set_sweep_frequency(ST_START, minFreq); @@ -296,11 +304,11 @@ void set_gridlines(int d) //int setting_frequency_10mhz = 10000000; -void set_10mhz(uint32_t f) +void set_30mhz(uint32_t f) { - if (f < 9000000 || f > 11000000) + if (f < 29000000 || f > 31000000) return; - config.setting_frequency_10mhz = f; + config.setting_frequency_30mhz = f; config_save(); dirty = true; update_grid(); @@ -474,17 +482,13 @@ void set_R(int f) setting.R = f; ADF4351_R_counter(f % 1000); ADF4351_spur_mode(f/1000); - ADF4351_force_refresh(); - old_freq[ADF4351_LO] = 0; dirty = true; } void set_modulo(uint32_t f) { ADF4351_modulo(f); - ADF4351_force_refresh(); - old_freq[ADF4351_LO] = 0; - ADF4351_set_frequency(0, real_old_freq[ADF4351_LO]); + clear_frequency_cache(); dirty = true; } #endif @@ -1087,7 +1091,7 @@ void calculate_step_delay(void) #endif #endif #ifdef __SI4463__ - if (actual_rbw_x10 >= 6000) { SI4432_step_delay = 200; SI4432_offset_delay = 100; spur_gate = 50; } + if (actual_rbw_x10 >= 6000) { SI4432_step_delay = 400; SI4432_offset_delay = 100; spur_gate = 50; } else if (actual_rbw_x10 >= 3000) { SI4432_step_delay = 400; SI4432_offset_delay = 100; spur_gate = 50; } else if (actual_rbw_x10 >= 1000) { SI4432_step_delay = 400; SI4432_offset_delay = 100; spur_gate = 70; } else if (actual_rbw_x10 >= 300) { SI4432_step_delay = 1000; SI4432_offset_delay = 30; spur_gate = 80; } @@ -1217,10 +1221,6 @@ void setupSA(void) #ifdef __SI4432__ SI4432_Init(); #endif - for (unsigned int i = 0; i < sizeof(old_freq)/sizeof(unsigned long) ; i++) { - old_freq[i] = 0; - real_old_freq[i] = 0; - } #ifdef __SI4432__ SI4432_Sel = SI4432_RX ; SI4432_Receive(); @@ -1349,7 +1349,7 @@ void set_freq(int V, unsigned long freq) // translate the requested frequency } else if (V==ADF4351_LO2) { real_old_freq[V] = ADF4351_set_frequency(V-ADF4351_LO, freq); } else if (V==SI4463_RX) { - if (setting.step_delay_mode == SD_FAST && fast_counter++ < 100) { // If in extra fast scanning mode and NOT SI4432_RX !!!!!! + if (setting.step_delay_mode == SD_FAST && fast_counter++ < 100 && real_old_freq[V] != 0) { // If in extra fast scanning mode and NOT SI4432_RX !!!!!! long delta = (long)freq - (long)real_old_freq[V]; #define OFFSET_STEP 14.30555 // 30MHz //#define OFFSET_STEP 12.3981 @@ -1892,7 +1892,7 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) int spur_second_pass = false; if (i == 0 && dirty ) { // if first point in scan and dirty #ifdef __ADF4351__ - ADF4351_force_refresh(); + clear_frequency_cache(); #endif calculate_correction(); // pre-calculate correction factor dividers to avoid float division apply_settings(); // Initialize HW @@ -2355,7 +2355,7 @@ modulation_again: f_error = ((float)f-(float)frequencies[i])/setting.frequency_step; } char shifted = ( LO_shifted ? '>' : ' '); - shell_printf ("%d:LO=%11.6q\t%cIF=%11.6q\tF=%11.6q\tD=%.2f\r\n", i, real_old_freq[ADF4351_LO], shifted, real_old_freq[SI4463_RX] + real_offset, f , f_error); + shell_printf ("%d:LO=%11.6q:%11.6q\t%cIF=%11.6q:%11.6q\tOF=%11.6q\tF=%11.6q\tD=%.2f\r\n", i, old_freq[ADF4351_LO],real_old_freq[ADF4351_LO], shifted, old_freq[SI4463_RX], real_old_freq[SI4463_RX], (int32_t)real_offset, f , f_error); osalThreadSleepMilliseconds(100); } // ------------------------- end of processing when in output mode ------------------------------------------------ diff --git a/si4432.c b/si4432.c index 2fa1439..7881332 100644 --- a/si4432.c +++ b/si4432.c @@ -1003,7 +1003,7 @@ int ADF4351_frequency_changed = false; #endif //double RFout; //Output freq in MHz uint64_t PFDRFout[6] = {XTAL,XTAL,XTAL,10000000,10000000,10000000}; //Reference freq in MHz -uint64_t Chrystal[6] = {XTAL,XTAL,XTAL,10000000,10000000,10000000}; +//uint64_t Chrystal[6] = {XTAL,XTAL,XTAL,10000000,10000000,10000000}; //double FRACF; // Temp volatile int64_t @@ -1161,8 +1161,9 @@ void ADF4351_R_counter(int R) bitClear (registers[2], 25); // Reference doubler } for (int channel=0; channel < 6; channel++) { - PFDRFout[channel] = (Chrystal[channel] * (dbl?2:1)) / R; + PFDRFout[channel] = (config.setting_frequency_30mhz * (dbl?2:1)) / R; } + clear_frequency_cache(); // When R changes the possible frequencies will change registers[2] &= ~ (((unsigned long)0x3FF) << 14); registers[2] |= (((unsigned long)R) << 14); ADF4351_Set(0); @@ -1876,8 +1877,7 @@ void si_set_offset(int16_t offset) }; SI4463_do_api(data, sizeof(data), NULL, 0); SI4463_offset_changed = true; - if (offset) - SI4463_offset_active = true; + SI4463_offset_active = (offset != 0); } @@ -1955,7 +1955,7 @@ int16_t Si446x_RSSI(void) ADF4351_frequency_changed = false; SI4463_offset_changed = false; } -#define SAMPLE_COUNT 1 +#define SAMPLE_COUNT 3 int j = SAMPLE_COUNT; //setting.repeat; int RSSI_RAW_ARRAY[3]; do{ @@ -2387,19 +2387,14 @@ uint32_t SI4463_set_freq(uint32_t freq) } if (SI4463_band == -1) return 0; -//#ifdef TINYSA4_PROTO -#define freq_xco 29999960 -//#else -//#define freq_xco 26000000 -//#endif if (SI4463_offset_active) { si_set_offset(0); SI4463_offset_active = false; } - int32_t R = (freq * SI4463_outdiv) / (Npresc ? 2*freq_xco : 4*freq_xco) - 1; // R between 0x00 and 0x7f (127) + int32_t R = (freq * SI4463_outdiv) / (Npresc ? 2*config.setting_frequency_30mhz : 4*config.setting_frequency_30mhz) - 1; // R between 0x00 and 0x7f (127) int64_t MOD = 524288; // = 2^19 - int32_t F = ((freq * SI4463_outdiv*MOD) / (Npresc ? 2*freq_xco : 4*freq_xco)) - R*MOD; - uint32_t actual_freq = (R*MOD + F) * (Npresc ? 2*freq_xco : 4*freq_xco)/ SI4463_outdiv/MOD; + int32_t F = ((freq * SI4463_outdiv*MOD) / (Npresc ? 2*config.setting_frequency_30mhz : 4*config.setting_frequency_30mhz)) - R*MOD; + uint32_t actual_freq = (R*MOD + F) * (Npresc ? 2*config.setting_frequency_30mhz : 4*config.setting_frequency_30mhz)/ SI4463_outdiv/MOD; int delta = freq - actual_freq; if (delta < -100 || delta > 100 ){ while(1) @@ -2552,6 +2547,7 @@ void SI4463_init_rx(void) i += SI4468_config[i]; } #endif + clear_frequency_cache(); SI4463_start_rx(SI4463_channel); #if 0 volatile si446x_state_t s ; diff --git a/ui_sa.c b/ui_sa.c index 50c9dcb..0919043 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -405,7 +405,7 @@ enum { KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, // These must be first to share common help text KM_REFLEVEL, KM_SCALE, KM_ATTENUATION, KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE, KM_LOWOUTLEVEL, KM_DECAY, KM_NOISE, - KM_10MHZ, KM_REPEAT, KM_OFFSET, KM_TRIGGER, KM_LEVELSWEEP, KM_SWEEP_TIME, KM_OFFSET_DELAY, + KM_30MHZ, KM_REPEAT, KM_OFFSET, KM_TRIGGER, KM_LEVELSWEEP, KM_SWEEP_TIME, KM_OFFSET_DELAY, KM_FAST_SPEEDUP, KM_GRIDLINES, KM_MARKER, KM_MODULATION, KM_R,KM_MOD,KM_CP, #if 0 @@ -436,7 +436,7 @@ static const struct { {keypads_plusmin , "LEVEL"}, // KM_LOWOUTLEVEL {keypads_positive , "DECAY"}, // KM_DECAY {keypads_positive , "NOISE\nLEVEL"}, // KM_NOISE - {keypads_freq , "FREQ"}, // KM_10MHz + {keypads_freq , "FREQ"}, // KM_30MHz {keypads_positive , "SAMPLE\nREPEAT"}, // KM_REPEA {keypads_plusmin , "OFFSET"}, // KM_OFFSET {keypads_plusmin_unit, "TRIGGER\nLEVEL"}, // KM_TRIGGER @@ -1860,7 +1860,6 @@ static const menuitem_t menu_sweep_speed[] = static const menuitem_t menu_settings3[] = { -// { MT_KEYPAD, KM_10MHZ, "CORRECT\nFREQUENCY", "Enter actual lMHz frequency"}, // { MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"}, { MT_ADV_CALLBACK, 0, "DEBUG\nFREQ", menu_debug_freq_acb}, { MT_ADV_CALLBACK, 0, "ADF OUT", menu_adf_out_acb}, @@ -1902,6 +1901,7 @@ static const menuitem_t menu_settings2[] = #ifdef __ULTRA__ { MT_SUBMENU,0, "HARMONIC", menu_harmonic}, #endif + { MT_KEYPAD, KM_30MHZ, "ACTUAL\n30MHz", "Enter actual l0MHz frequency"}, { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings3}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel @@ -2270,8 +2270,8 @@ static void fetch_numeric_target(void) uistat.value = setting.noise; plot_printf(uistat.text, sizeof uistat.text, "%3d", ((int32_t)uistat.value)); break; - case KM_10MHZ: - uistat.value = config.setting_frequency_10mhz; + case KM_30MHZ: + uistat.value = config.setting_frequency_30mhz; plot_printf(uistat.text, sizeof uistat.text, "%3.6fMHz", uistat.value / 1000000.0); break; case KM_OFFSET: @@ -2405,8 +2405,8 @@ set_numeric_value(void) case KM_NOISE: set_noise(uistat.value); break; - case KM_10MHZ: - set_10mhz(uistat.value); + case KM_30MHZ: + set_30mhz(uistat.value); break; case KM_OFFSET: set_offset(uistat.value);