From 979f369724e77bb70f59a6790944f397b5f8eb65 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 1 Jun 2020 10:08:55 +0200 Subject: [PATCH] Added modulation and level commands --- main.c | 2 ++ sa_cmd.c | 33 +++++++++++++++++++++++++++++++++ sa_core.c | 19 +++++++++++++++---- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 4322aeb..2aa4b6d 100644 --- a/main.c +++ b/main.c @@ -2267,6 +2267,8 @@ static const VNAShellCommand commands[] = #endif { "if", cmd_if, 0 }, { "attenuate", cmd_attenuate, 0 }, + { "level", cmd_level, 0 }, + { "modulation", cmd_modulation, 0 }, { "reflevel", cmd_reflevel, 0 }, { "rbw", cmd_rbw, 0 }, { "mode", cmd_mode, 0 }, diff --git a/sa_cmd.c b/sa_cmd.c index 2746b60..c7f74b2 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -31,6 +31,28 @@ VNA_SHELL_FUNCTION(cmd_mode) goto usage; } +VNA_SHELL_FUNCTION(cmd_modulation ) +{ + if (argc != 1) { + usage: + shell_printf("usage: modulation off|AM|NFM|WFM|extern\r\n"); + return; + } + int m = MO_NONE; + if (strcmp(argv[0],"off") == 0) { + } else if (strcmp(argv[0],"AM") == 0) { + m = MO_AM; + } else if (strcmp(argv[0],"NFM") == 0) { + m = MO_NFM; + } else if (strcmp(argv[0],"WFM") == 0) { + m = MO_WFM; + } else if (strcmp(argv[0],"extern") == 0) { + m = MO_EXTERNAL; + } else + goto usage; + set_modulation(m); +} + VNA_SHELL_FUNCTION(cmd_spur) { if (argc != 1) { @@ -63,6 +85,17 @@ VNA_SHELL_FUNCTION(cmd_attenuate) } } +VNA_SHELL_FUNCTION(cmd_level) +{ + if (argc != 1) { + usage: + shell_printf("usage: level -76..20\r\n"); + return; + } + int a = my_atoi(argv[0]); + set_attenuation(a); +} + VNA_SHELL_FUNCTION(cmd_reflevel) { if (argc != 1) { diff --git a/sa_core.c b/sa_core.c index 3e61097..85f9f47 100644 --- a/sa_core.c +++ b/sa_core.c @@ -732,7 +732,10 @@ void update_rbw(void) SI4432_Sel = MODE_SELECT(setting.mode); actual_rbw = SI4432_SET_RBW(actual_rbw); - vbwSteps = ((int)(2 * setting.vbw / actual_rbw)); + if (setting.step_delay==1) // Precise + vbwSteps = ((int)(2 * (setting.vbw + (actual_rbw/2)) / (actual_rbw / 2))); + else + vbwSteps = ((int)(2 * (setting.vbw + (actual_rbw/2)) / actual_rbw)); if (vbwSteps < 1) vbwSteps = 1; @@ -983,11 +986,15 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) float RSSI = -150.0; int t = 0; do { // ------------- Acquisition loop ---------- - int offs; + int offs,sm; + if (setting.step_delay == 1) + sm = 250; // steps of a quarter rbw + else + sm = 500; // steps of half the rbw if (vbwSteps & 1) { // Uneven steps, center - offs = (t - (vbwSteps >> 1)) * 500; + offs = (t - (vbwSteps >> 1)) * sm; } else { // Even, shift half step - offs = (t - (vbwSteps >> 1)) * 500 + 250; + offs = (t - (vbwSteps >> 1)) * sm + sm/2; } offs = (int)(offs * actual_rbw); uint32_t lf = (uint32_t)(f + offs); @@ -1086,6 +1093,9 @@ again: float correct_RSSI = get_level_offset()+ setting.attenuate - signal_path_loss - setting.offset + get_frequency_correction(f); wait: subRSSI = SI4432_RSSI(lf, MODE_SELECT(setting.mode)) + correct_RSSI ; +// if ( i < 3) +// shell_printf("%d %.3f %.3f %.1f\r\n", i, local_IF/1000000.0, lf/1000000.0, subRSSI); + if (wait_for_trigger) { // wait for trigger to happen if (operation_requested && break_on_operation) break; // abort @@ -1135,6 +1145,7 @@ again: float temp_min_level = 100; // spur_old_stepdelay = 0; int repeats = 1; +// shell_printf("\r\n"); if (MODE_OUTPUT(setting.mode) && setting.modulation != MO_NONE) { repeats = 1000; // to avoid interrupting the tone during UI processing modulation_counter = 0;