From 528895b6e8e7c6c70bbb9aea18f5101fcdcdf0bf Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 2 Jun 2020 10:12:48 +0200 Subject: [PATCH] Sweep time in seconds and auto AGC disabling --- sa_core.c | 39 +++++++++++++++++++++++++++++++-------- ui_sa.c | 16 ++++++++-------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/sa_core.c b/sa_core.c index 00516a5..84d0d79 100644 --- a/sa_core.c +++ b/sa_core.c @@ -52,7 +52,7 @@ void reset_settings(int m) setting.level = -15.0; setting.trigger_level = -150.0; setting.linearity_step = 0; - setting.sweep_time = 1000; + setting.sweep_time = 100; trace[TRACE_STORED].enabled = false; trace[TRACE_TEMP].enabled = false; setting.refer = -1; @@ -166,6 +166,10 @@ void set_level_sweep(float l) void set_sweep_time(int32_t t) { + if (t < 5) + t = 5; + if (t > 6000) + t = 6000; setting.sweep_time = t; dirty = true; } @@ -973,7 +977,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) dirty = false; } - if (setting.level_sweep != 0.0) { + if (setting.mode == M_GENLOW && setting.level_sweep != 0.0) { static int old_a = -150; int a = setting.level + (i / 290.0) * setting.level_sweep; if (a != old_a) { @@ -1007,6 +1011,18 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) } } + if (setting.mode == M_LOW && setting.auto_attenuation) { + unsigned char v; + static unsigned char old_v; + if (f < 1500000) + v = 0x50; // Disable AGC and enable LNA + else + v = 0x60; // Disable AGC and enable LNA + if (old_v != v) { + SI4432_Write_Byte(0x69, v); + old_v = v; + } + } if (MODE_OUTPUT(setting.mode) && setting.modulation == MO_AM) { // AM modulation int p = setting.attenuate * 2 + am_modulation[modulation_counter]; PE4302_Write_Byte(p); @@ -1216,8 +1232,11 @@ again: return false; if (MODE_OUTPUT(setting.mode)) { if (setting.modulation == MO_NONE) { -// osalThreadSleepMilliseconds(10); // Slow down sweep in output mode - my_microsecond_delay(setting.sweep_time * 1000 / 290); + int32_t s = setting.sweep_time * (100000 / 290); + if (s < 30000) + my_microsecond_delay(s); + else + osalThreadSleepMilliseconds(s/1000); } continue; // Skip all other processing } @@ -1330,12 +1349,16 @@ again: } if (!in_selftest && setting.mode == M_LOW && setting.auto_attenuation && max_index[0] > 0) { // Auto attenuate - if (actual_t[max_index[0]] - setting.attenuate < - 30 && setting.attenuate >= 10) { + int old_attenuate = setting.attenuate; + float actual_max_level = actual_t[max_index[0]] - setting.attenuate; + if (actual_max_level < - 31 && setting.attenuate >= 10) { setting.attenuate -= 10; - redraw_request |= REDRAW_CAL_STATUS; - dirty = true; // Must be above if(scandirty!!!!!) - } else if (actual_t[max_index[0]] - setting.attenuate > - 15 && setting.attenuate <= 20) { + } else if (actual_max_level < - 26 && setting.attenuate >= 5) { + setting.attenuate -= 5; + } else if (actual_max_level > - 19 && setting.attenuate <= 20) { setting.attenuate += 10; + } + if (old_attenuate != setting.attenuate) { redraw_request |= REDRAW_CAL_STATUS; dirty = true; // Must be above if(scandirty!!!!!) } diff --git a/ui_sa.c b/ui_sa.c index 0a62b12..f056d18 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -411,7 +411,7 @@ static const keypads_t * const keypads_mode_tbl[] = { keypads_level, // KM_OFFSET keypads_level, // KM_TRIGGER keypads_level, // KM_LEVELSWEEP - keypads_time, // KM_SWEEP_TIME + keypads_level, // KM_SWEEP_TIME }; #ifdef __VNA__ @@ -422,8 +422,8 @@ static const char * const keypad_mode_label[] = { #ifdef __SA__ static const char * const keypad_mode_label[] = { "error", "START", "STOP", "CENTER", "SPAN", "FREQ", "REFPOS", "SCALE", // 0-7 - "\2ATTENUATE\0 0-31dB", "ACTUALPOWER", "IF", "SAMPLE TIME", "DRIVE", "LEVEL", "LEVEL", "LEVEL", // 8-15 - "OFFSET" , "REPEATS", "OFFSET", "TRIGGER", "LEVEL SWEEP", "SWEEP TIME"// 16- + "\2ATTENUATE\0 0-31dB", "ACTUALPOWER", "IF", "\2SAMPLE\0TIME", "DRIVE", "LEVEL", "LEVEL", "LEVEL", // 8-15 + "OFFSET" , "REPEATS", "OFFSET", "TRIGGER", "\2LEVEL\0SWEEP", "SWEEP mS"// 16- }; #endif @@ -1080,7 +1080,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_LEVELSWEEP, "LEVELSWEEP: %s", NULL}, + { MT_FORM | MT_KEYPAD | MT_LOW, KM_LEVELSWEEP, "LEVELSWEEP: %s", NULL}, { MT_FORM | MT_KEYPAD, KM_SWEEP_TIME, "SWEEP TIME: %s", NULL}, // { MT_FORM | MT_KEYPAD, KM_10MHZ, "10MHZ: %s", NULL}, { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, @@ -1748,12 +1748,12 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%.1fdB", uistat.value); break; case KM_SWEEP_TIME: - uistat.value = setting.sweep_time; - plot_printf(uistat.text, sizeof uistat.text, "%.0fmS", uistat.value); + uistat.value = ((float)setting.sweep_time)/10.0; + plot_printf(uistat.text, sizeof uistat.text, "%.1fS", uistat.value); break; case KM_TRIGGER: uistat.value = setting.trigger_level; - plot_printf(uistat.text, sizeof uistat.text, "%fdB", uistat.value); + plot_printf(uistat.text, sizeof uistat.text, "%.1fdB", uistat.value); break; } @@ -1838,7 +1838,7 @@ set_numeric_value(void) set_level_sweep(uistat.value); break; case KM_SWEEP_TIME: - set_sweep_time(uistat.value); + set_sweep_time(uistat.value*10.0); break; case KM_TRIGGER: set_trigger_level(uistat.value);