diff --git a/main.c b/main.c index 6133260..07821cb 100644 --- a/main.c +++ b/main.c @@ -998,7 +998,8 @@ set_frequencies(uint32_t start, uint32_t stop, uint16_t points) // disable at out of sweep range for (; i < POINTS_COUNT; i++) frequencies[i] = 0; - update_rbw(frequencies[1] - frequencies[0]); + setting_frequency_step = delta; + update_rbw(); } static void @@ -2229,7 +2230,7 @@ VNA_SHELL_FUNCTION(cmd_d) { (void) argc; int32_t a = my_atoi(argv[0]); - settingDrive = a; + setting_drive = a; } @@ -2256,11 +2257,11 @@ VNA_SHELL_FUNCTION(cmd_t) VNA_SHELL_FUNCTION(cmd_e) { (void)argc; - trackingVFO = my_atoi(argv[0]); - if (trackingVFO == -1) - trackingVFO = false; + setting_tracking = my_atoi(argv[0]); + if (setting_tracking == -1) + setting_tracking = false; else - trackingVFO = true; + setting_tracking = true; if (argc >1) frequencyExtra = my_atoi(argv[1]); @@ -2279,11 +2280,12 @@ VNA_SHELL_FUNCTION(cmd_m) pause_sweep(); int32_t f_step = (frequencyStop-frequencyStart)/ points; palClearPad(GPIOC, GPIOC_LED); // disable led and wait for voltage stabilization - update_rbw(f_step); + setting_frequency_step = f_step; + update_rbw(); chThdSleepMilliseconds(10); streamPut(shell_stream, '{'); for (int i = 0; i 31) a=31; - if (settingAttenuate == a) + if (setting_attenuate == a) return; - settingAttenuate = a; + setting_attenuate = a; dirty = true; } @@ -87,49 +131,50 @@ void SetStorage(void) { for (int i=0; i300.0) actualStepDelay = 400; + else if (actual_rbw >100.0) actualStepDelay = 500; + else if (actual_rbw > 30.0) actualStepDelay = 900; + else if (actual_rbw > 10.0) actualStepDelay = 900; + else if (actual_rbw > 3.0) actualStepDelay = 1000; + else actualStepDelay = 1500; + } else { + if (actual_rbw >300.0) actualStepDelay = 900; + else if (actual_rbw >100.0) actualStepDelay = 900; + else if (actual_rbw > 30.0) actualStepDelay = 900; + else if (actual_rbw > 10.0) actualStepDelay = 1800; + else if (actual_rbw > 3.0) actualStepDelay = 6000; + else actualStepDelay = 8000; + } + } else + actualStepDelay = setting_step_delay; + PE4302_Write_Byte(setting_attenuate * 2); + if (setting_modulation == MO_NFM ) { + SI4432_Sel = 1; + SI4432_Write_Byte(0x7A, 1); // Use frequency hopping channel width for FM modulation + } else if (setting_modulation == MO_WFM ) { + SI4432_Sel = 1; + SI4432_Write_Byte(0x7A, 10); // Use frequency hopping channel width for FM modulation + } else { + SI4432_Sel = 1; + SI4432_Write_Byte(0x79, 0); // IF no FM back to channel 0 + } + SetRX(setting_mode); + SI4432_SetReference(setting_refer); + update_rbw(); +} //------------------------------------------ @@ -311,11 +349,6 @@ int peakIndex; float temppeakLevel; int temppeakIndex; -#define BARSTART 24 - - -int vbwSteps = 1; - void setupSA(void) { SI4432_Init(); @@ -346,8 +379,8 @@ void SetSwitchReceive(void) { void SetAGCLNA(void) { unsigned char v = 0x40; - if (settingAGC) v |= 0x20; - if (settingLNA) v |= 0x10; + if (setting_agc) v |= 0x20; + if (setting_lna) v |= 0x10; SI4432_Write_Byte(0x69, v); } @@ -363,8 +396,8 @@ case M_LOW: // Mixed into 0 SI4432_Sel = 1; SetSwitchReceive(); // SI4432_Receive(); For noise testing only - SI4432_Transmit(settingDrive); - // SI4432_SetReference(settingRefer); + SI4432_Transmit(setting_drive); + // SI4432_SetReference(setting_refer); break; case M_HIGH: // Direct into 1 // SI4432_SetReference(-1); // Stop reference output @@ -381,11 +414,11 @@ case M_HIGH: // Direct into 1 case M_GENLOW: // Mixed output from 0 SI4432_Sel = 0; SetSwitchTransmit(); - SI4432_Transmit(settingDrive); + SI4432_Transmit(setting_drive); SI4432_Sel = 1; SetSwitchReceive(); - SI4432_Transmit(settingDrive); + SI4432_Transmit(setting_drive); break; case M_GENHIGH: // Direct output from 1 @@ -395,16 +428,16 @@ case M_GENHIGH: // Direct output from 1 SI4432_Sel = 1; SetSwitchTransmit(); - SI4432_Transmit(settingDrive); + SI4432_Transmit(setting_drive); break; } } -void update_rbw(uint32_t delta_f) +void update_rbw(void) { - setting_vbw = (delta_f)/1000.0; - actual_rbw = settingRBW; + setting_vbw = (setting_frequency_step)/1000.0; + actual_rbw = setting_rbw; // float old_rbw = actual_rbw; if (actual_rbw == 0) actual_rbw = 2*setting_vbw; @@ -412,9 +445,12 @@ void update_rbw(uint32_t delta_f) actual_rbw = 2.6; if (actual_rbw > 600) actual_rbw = 600; - SI4432_Sel = MODE_SELECT(settingMode); + + SI4432_Sel = MODE_SELECT(setting_mode); actual_rbw = SI4432_SET_RBW(actual_rbw); + vbwSteps = ((int)(2 * setting_vbw / actual_rbw)); + if (vbwSteps < 1) vbwSteps = 1; dirty = true; @@ -461,14 +497,8 @@ int avoid_spur(int f) int window = ((int)actual_rbw ) * 1000*2; if (window < 50000) window = 50000; - if (! settingMode == M_LOW) - return false ; - if (frequency_IF != spur_IF) - return false; - if (actual_rbw > 300.0) + if (! setting_mode == M_LOW || frequency_IF != spur_IF || actual_rbw > 300.0) return(false); -// if (spur_old_stepdelay != 0 && actualStepDelay != spur_old_stepdelay) // restore stepdelay -// actualStepDelay = spur_old_stepdelay; for (unsigned int i = 0; i < (sizeof spur_table)/sizeof(int); i++) { if (f/window == spur_table[i]/window) { // spur_old_stepdelay = actualStepDelay; @@ -481,11 +511,11 @@ int avoid_spur(int f) static int modulation_counter = 0; -float perform(bool break_on_operation, int i, int32_t f, int extraV) +float perform(bool break_on_operation, int i, int32_t f, int tracking) { -// long local_IF = (MODE_LOW(settingMode)?frequency_IF + (int)(actual_rbw < 300.0?settingSpur * 1000 * actual_rbw :0):0); +// long local_IF = (MODE_LOW(setting_mode)?frequency_IF + (int)(actual_rbw < 300.0?setting_spur * 1000 * actual_rbw :0):0); long local_IF; - if (MODE_HIGH(settingMode)) + if (MODE_HIGH(setting_mode)) local_IF = 0; else if (avoid_spur(f)) local_IF = spur_alternate_IF; @@ -493,59 +523,22 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) local_IF = frequency_IF; if (i == 0 && dirty) { - if (settingStepDelay == 0){ - if (MODE_LOW(settingMode)) { - if (actual_rbw >300.0) actualStepDelay = 400; - else if (actual_rbw >100.0) actualStepDelay = 500; - else if (actual_rbw > 30.0) actualStepDelay = 900; - else if (actual_rbw > 10.0) actualStepDelay = 900; - else if (actual_rbw > 3.0) actualStepDelay = 1000; - else actualStepDelay = 1500; - } else { - if (actual_rbw >300.0) actualStepDelay = 900; - else if (actual_rbw >100.0) actualStepDelay = 900; - else if (actual_rbw > 30.0) actualStepDelay = 900; - else if (actual_rbw > 10.0) actualStepDelay = 1800; - else if (actual_rbw > 3.0) actualStepDelay = 6000; - else actualStepDelay = 8000; - } - } else - actualStepDelay = settingStepDelay; - -// setupSA(); - - int p = settingAttenuate * 2; - PE4302_Write_Byte(p); - if (settingModulation == MO_NFM ) { - SI4432_Sel = 1; - SI4432_Write_Byte(0x7A, 1); // Use frequency hopping channel width for FM modulation - } else if (settingModulation == MO_WFM ) { - SI4432_Sel = 1; - SI4432_Write_Byte(0x7A, 10); // Use frequency hopping channel width for FM modulation - } else { - SI4432_Sel = 1; - SI4432_Write_Byte(0x79, 0); // IF no FM back to channel 0 - } - SetRX(settingMode); - SI4432_SetReference(settingRefer); - -// if (dirty) { - scandirty = true; - dirty = false; -// } + apply_settings(); + scandirty = true; + dirty = false; } if (local_IF) { setFreq (0, local_IF); } - if (settingModulation == MO_AM) { - int p = settingAttenuate * 2 + modulation_counter; + if (setting_modulation == MO_AM) { + int p = setting_attenuate * 2 + modulation_counter; PE4302_Write_Byte(p); if (modulation_counter == 3) modulation_counter = 0; else modulation_counter++; chThdSleepMicroseconds(250); - } else if (settingModulation == MO_NFM || settingModulation == MO_WFM ) { + } else if (setting_modulation == MO_NFM || setting_modulation == MO_WFM ) { SI4432_Sel = 1; SI4432_Write_Byte(0x79, modulation_counter); // Use frequency hopping channel for FM modulation if (modulation_counter == 3) @@ -554,23 +547,22 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) modulation_counter++; chThdSleepMicroseconds(250); } - volatile int subSteps = ((int)(2 * setting_vbw / actual_rbw)); float RSSI = -150.0; int t = 0; do { int lf = (uint32_t)(f + (int)(t * 500 * actual_rbw)); - if (extraV) - setFreq (0, local_IF + lf - refferFreq[settingRefer]); // Offset so fundamental of reffer is visible + if (tracking) + setFreq (0, local_IF + lf - reffer_freq[setting_refer]); // Offset so fundamental of reffer is visible setFreq (1, local_IF + lf); - if (MODE_OUTPUT(settingMode)) + if (MODE_OUTPUT(setting_mode)) return(0); - float subRSSI = SI4432_RSSI(lf, MODE_SELECT(settingMode))+settingLevelOffset()+settingAttenuate; + float subRSSI = SI4432_RSSI(lf, MODE_SELECT(setting_mode))+settingLevelOffset()+setting_attenuate; if (RSSI < subRSSI) RSSI = subRSSI; t++; - if ((operation_requested && break_on_operation ) || (MODE_OUTPUT(settingMode))) // output modes do not step. - subSteps = 0; // abort - } while (subSteps-- > 0); + if ((operation_requested && break_on_operation ) || (MODE_OUTPUT(setting_mode))) // output modes do not step. + break; // abort + } while (t < vbwSteps); return(RSSI); } @@ -582,28 +574,28 @@ static bool sweep(bool break_on_operation) temppeakLevel = -150; float temp_min_level = 100; // spur_old_stepdelay = 0; -again: +//again: for (int i = 0; i < sweep_points; i++) { - RSSI = perform(break_on_operation, i, frequencies[i], trackingVFO); + RSSI = perform(break_on_operation, i, frequencies[i], setting_tracking); // back to toplevel to handle ui operation if (operation_requested && break_on_operation) return false; - if (settingSpur == 1) { // First pass - temp_t[i] = RSSI; - continue; // Skip all other processing - } - if (settingSpur == -1) // Second pass - RSSI = ( RSSI < temp_t[i] ? RSSI : temp_t[i]); // Minimum of two passes +// if (setting_spur == 1) { // First pass +// temp_t[i] = RSSI; +// continue; // Skip all other processing +// } +// if (setting_spur == -1) // Second pass +// RSSI = ( RSSI < temp_t[i] ? RSSI : temp_t[i]); // Minimum of two passes temp_t[i] = RSSI; - if (settingSubtractStorage) { + if (setting_subtract_stored) { RSSI = RSSI - stored_t[i] ; } // stored_t[i] = (SI4432_Read_Byte(0x69) & 0x0f) * 3.0 - 90.0; // Display the AGC value in thestored trace - if (scandirty || settingAverage == AV_OFF) + if (scandirty || setting_average == AV_OFF) actual_t[i] = RSSI; else { - switch(settingAverage) { + switch(setting_average) { case AV_MIN: if (actual_t[i] > RSSI) actual_t[i] = RSSI; break; case AV_MAX: if (actual_t[i] < RSSI) actual_t[i] = RSSI; break; case AV_2: actual_t[i] = (actual_t[i] + RSSI) / 2.0; break; @@ -620,11 +612,11 @@ again: if (temp_min_level > actual_t[i]) temp_min_level = actual_t[i]; } - if (settingSpur == 1) { - settingSpur = -1; - goto again; - } else if (settingSpur == -1) - settingSpur = 1; +// if (setting_spur == 1) { +// setting_spur = -1; +// goto again; +// } else if (setting_spur == -1) +// setting_spur = 1; if (scandirty) { scandirty = false; @@ -708,7 +700,7 @@ void PeakSearch() peakIndex = temppeakIndex; peakLevel = actual_t[peakIndex]; peakFreq = frequencies[peakIndex]; - settingSpur = -settingSpur; + setting_spur = -setting_spur; int peak_marker = 0; markers[peak_marker].enabled = true; markers[peak_marker].index = peakIndex; @@ -738,7 +730,7 @@ void draw_cal_status(void) ili9341_fill(x, y, OFFSETX, HEIGHT, 0x0000); - if (MODE_OUTPUT(settingMode)) // No cal status during output + if (MODE_OUTPUT(setting_mode)) // No cal status during output return; if (current_menu_is_form() && !in_selftest) return; @@ -759,29 +751,29 @@ void draw_cal_status(void) plot_printf(buf, BLEN, "%ddB/",(int)get_trace_scale(0)); ili9341_drawstring(buf, x, y); - if (settingAttenuate) { + if (setting_attenuate) { ili9341_set_foreground(BRIGHT_COLOR_GREEN); y += YSTEP*2; ili9341_drawstring("Attn:", x, y); y += YSTEP; - plot_printf(buf, BLEN, "-%ddB", settingAttenuate); + plot_printf(buf, BLEN, "-%ddB", setting_attenuate); buf[5]=0; ili9341_drawstring(buf, x, y); } - if (settingAverage>0) { + if (setting_average>0) { ili9341_set_foreground(BRIGHT_COLOR_BLUE); y += YSTEP*2; ili9341_drawstring("Aver:", x, y); y += YSTEP; - plot_printf(buf, BLEN, "%s",averageText[settingAverage]); + plot_printf(buf, BLEN, "%s",averageText[setting_average]); buf[5]=0; ili9341_drawstring(buf, x, y); } - - if (settingSpur) { +#if 0 + if (setting_spur) { ili9341_set_foreground(BRIGHT_COLOR_BLUE); y += YSTEP*2; ili9341_drawstring("Spur:", x, y); @@ -790,8 +782,9 @@ void draw_cal_status(void) plot_printf(buf, BLEN, "ON"); ili9341_drawstring(buf, x, y); } +#endif - if (settingRBW) + if (setting_rbw) color = BRIGHT_COLOR_GREEN; else color = DEFAULT_FG_COLOR; @@ -821,7 +814,7 @@ void draw_cal_status(void) ili9341_drawstring("Scan:", x, y); y += YSTEP; - int32_t t = (int)((2* vbwSteps * sweep_points * ( actualStepDelay / 100) )) /10 * (settingSpur ? 2 : 1); // in mS + int32_t t = (int)((2* vbwSteps * sweep_points * ( actualStepDelay / 100) )) /10 /* * (setting_spur ? 2 : 1) */; // in mS if (t>1000) plot_printf(buf, BLEN, "%dS",(t+500)/1000); else @@ -831,13 +824,13 @@ void draw_cal_status(void) ili9341_drawstring(buf, x, y); - if (settingRefer >= 0) { + if (setting_refer >= 0) { ili9341_set_foreground(BRIGHT_COLOR_RED); y += YSTEP*2; ili9341_drawstring("Ref:", x, y); y += YSTEP; - plot_printf(buf, BLEN, "%dMHz",refMHz[settingRefer]); + plot_printf(buf, BLEN, "%dMHz",reffer_freq[setting_refer]/1000000); buf[5]=0; ili9341_drawstring(buf, x, y); } @@ -911,9 +904,9 @@ static void test_acquire(int i) pause_sweep(); #if 0 if (test_case[i].center < 300) - settingMode = M_LOW; + setting_mode = M_LOW; else - settingMode = M_HIGH; + setting_mode = M_HIGH; #endif set_sweep_frequency(ST_CENTER, (int32_t)(test_case[i].center * 1000000)); set_sweep_frequency(ST_SPAN, (int32_t)(test_case[i].span * 1000000)); @@ -1109,7 +1102,7 @@ int test_validate(int i) void test_prepare(int i) { - trackingVFO = false; //Default test setup + setting_tracking = false; //Default test setup switch(test_case[i].setup) { // Prepare test conditions case TPH_SILENT: // No input signal SetMode(M_HIGH); @@ -1123,7 +1116,7 @@ common_silent: break; case TP_10MHZEXTRA: // Swept receiver SetMode(M_LOW); - trackingVFO = true; //Sweep BPF + setting_tracking = true; //Sweep BPF set_refer_output(2); goto common; case TP_10MHZ: // 10MHz input diff --git a/si4432.c b/si4432.c index 284c267..0f56863 100644 --- a/si4432.c +++ b/si4432.c @@ -240,8 +240,8 @@ float SI4432_RSSI(uint32_t i, int s) SI4432_Sel = s; chThdSleepMicroseconds(actualStepDelay); RSSI_RAW = (unsigned char)SI4432_Read_Byte( 0x26 ) ; - if (settingMode < 2 && RSSI_RAW == 0) - SI4432_Init(); + // if (MODE_INPUT(setting_mode) && RSSI_RAW == 0) + // SI4432_Init(); float dBm = 0.5 * RSSI_RAW - 120.0 ; #ifdef __SIMULATION__ dBm = Simulated_SI4432_RSSI(i,s); diff --git a/ui_sa.c b/ui_sa.c index 0658067..e7b3c0d 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -17,12 +17,12 @@ void SetRBW(int); void SetDrive(int d); void SetIF(int f); void SetStepDelay(int t); -extern int settingRBW; +extern int setting_rbw; void SetSpur(int); int GetSpur(void); void SetAverage(int); int GetAverage(void); -extern int settingAverage; +extern int setting_average; void SetStorage(void); void SetClearStorage(void); void SetSubtractStorage(void); @@ -38,14 +38,14 @@ void ToggleAGC(void); void redrawHisto(void); void self_test(void); extern int32_t frequencyExtra; -extern int trackingVFO; -extern int settingDrive; -extern int settingLNA; -extern int settingAGC; +extern int setting_tracking; +extern int setting_drive; +extern int setting_lna; +extern int setting_agc; void SetModulation(int); -extern int settingModulation; +extern int setting_modulation; // extern int settingSpeed; -extern int settingStepDelay; +extern int setting_step_delay; @@ -324,6 +324,7 @@ static void menu_spur_cb(int item, uint8_t data) { (void)data; (void)item; +#if 0 if (GetSpur()) SetSpur(0); else @@ -331,6 +332,7 @@ static void menu_spur_cb(int item, uint8_t data) // menu_move_back(); ui_mode_normal(); draw_cal_status(); +#endif } static void menu_storage_cb(int item, uint8_t data) @@ -523,7 +525,7 @@ static void menu_settings2_cb(int item, uint8_t data) ToggleLNA();; break; case 2: - ToggleVFO(); + toggle_tracking(); break; } draw_cal_status(); @@ -860,7 +862,7 @@ static void menu_item_modify_attribute( } } else if (menu == menu_lowoutputmode || menu == menu_highoutputmode) { if (item == 3) { - plot_printf(uistat.text, sizeof uistat.text, menu_modulation_text[settingModulation]); + plot_printf(uistat.text, sizeof uistat.text, menu_modulation_text[setting_modulation]); } } else if (menu == menu_reffer) { if (item < 5 && item == get_refer_output() + 1){ @@ -878,10 +880,12 @@ static void menu_item_modify_attribute( *fg = config.menu_normal_color; } } else if (menu == menu_scale) { +#if 0 if (item == 4 /* Spur reduction */ && GetSpur()) { *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } +#endif } else if (menu == menu_average) { if (item == GetAverage()){ *bg = DEFAULT_MENU_TEXT_COLOR; @@ -912,15 +916,15 @@ static void menu_item_modify_attribute( *fg = config.menu_normal_color; } } else if (menu == menu_settings2 || menu == menu_settingshigh2) { - if (item ==0 && settingAGC){ + if (item ==0 && setting_agc){ *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } - if (item == 1 && settingLNA){ + if (item == 1 && setting_lna){ *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } - if (item == 2 && trackingVFO){ // should not happen in high mode + if (item == 2 && setting_tracking){ // should not happen in high mode *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } @@ -948,7 +952,7 @@ static void menu_item_modify_attribute( plot_printf(buf, sizeof buf, "%3.3fMHz", frequency0 / 1000000.0); break; case 1: - plot_printf(buf, sizeof buf, "%ddB", -10 - settingAttenuate); + plot_printf(buf, sizeof buf, "%ddB", -10 - setting_attenuate); break; } } @@ -959,7 +963,7 @@ static void menu_item_modify_attribute( plot_printf(buf, sizeof buf, "%3.3fMHz", frequency0 / 1000000.0); break; case 1: - plot_printf(buf, sizeof buf, "%ddB", -10 - settingDrive); + plot_printf(buf, sizeof buf, "%ddB", -10 - setting_drive); break; } } @@ -1003,7 +1007,7 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value / 1000); break; case KM_ATTENUATION: - uistat.value = settingAttenuate; + uistat.value = setting_attenuate; plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value); break; case KM_ACTUALPOWER: @@ -1015,20 +1019,20 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_SAMPLETIME: - uistat.value = settingStepDelay; + uistat.value = setting_step_delay; plot_printf(uistat.text, sizeof uistat.text, "%3duS", uistat.value); break; case KM_DRIVE: - uistat.value = settingDrive; + uistat.value = setting_drive; plot_printf(uistat.text, sizeof uistat.text, "%3ddB", uistat.value); break; case KM_LOWOUTLEVEL: - uistat.value = settingAttenuate; + uistat.value = setting_attenuate; uistat.value = -5 - uistat.value; // compensation for dB offset during low output mode plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value); break; case KM_HIGHOUTLEVEL: - uistat.value = settingDrive*5 + 5; + uistat.value = setting_drive*5 + 5; plot_printf(uistat.text, sizeof uistat.text, "%3ddB", uistat.value); break; }