From 5ce643921138e6629bb94cce06a70a1f88076443 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 1 Jun 2020 15:43:44 +0200 Subject: [PATCH] Command levelsweep added --- main.c | 1 + nanovna.h | 5 +++++ sa_cmd.c | 17 +++++++++++++++-- sa_core.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ si4432.c | 5 +++++ ui_sa.c | 17 +++++++++++++---- 6 files changed, 88 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index 2aa4b6d..696298c 100644 --- a/main.c +++ b/main.c @@ -2268,6 +2268,7 @@ static const VNAShellCommand commands[] = { "if", cmd_if, 0 }, { "attenuate", cmd_attenuate, 0 }, { "level", cmd_level, 0 }, + { "levelsweep", cmd_levelsweep, 0 }, { "modulation", cmd_modulation, 0 }, { "reflevel", cmd_reflevel, 0 }, { "rbw", cmd_rbw, 0 }, diff --git a/nanovna.h b/nanovna.h index d04e66f..d400d1d 100644 --- a/nanovna.h +++ b/nanovna.h @@ -183,6 +183,8 @@ void set_drive(int d); void set_IF(int f); void set_step_delay(int t); void set_repeat(int); +void set_level_sweep(float); +void set_level(float); //extern int setting.repeat; //extern int setting.rbw; #ifdef __SPUR__ @@ -571,6 +573,8 @@ typedef struct setting float trigger_level; int trigger; int linearity_step; + float level; + float level_sweep; int test_argument; uint32_t checksum; }setting_t; @@ -775,6 +779,7 @@ void SI4432_Write_Byte(byte ADR, byte DATA ); byte SI4432_Read_Byte( byte ADR ); void SI4432_Init(void); +void SI4432_Drive(int); float SI4432_RSSI(uint32_t i, int s); void SI4432_Set_Frequency ( long Freq ); float SI4432_SET_RBW(float WISH); diff --git a/sa_cmd.c b/sa_cmd.c index c7f74b2..c5bacbe 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -92,10 +92,23 @@ VNA_SHELL_FUNCTION(cmd_level) shell_printf("usage: level -76..20\r\n"); return; } - int a = my_atoi(argv[0]); - set_attenuation(a); + float f = my_atof(argv[0]); + set_level(f); } +VNA_SHELL_FUNCTION(cmd_levelsweep) +{ + if (argc != 1) { + usage: + shell_printf("usage: levelsweep -76..+76\r\n"); + return; + } + float f = my_atof(argv[0]); + set_level_sweep(f); +} + + + VNA_SHELL_FUNCTION(cmd_reflevel) { if (argc != 1) { diff --git a/sa_core.c b/sa_core.c index 85f9f47..49b7956 100644 --- a/sa_core.c +++ b/sa_core.c @@ -48,6 +48,8 @@ void reset_settings(int m) setting.frequency_IF = 433800000; setting.offset = 0.0; setting.trigger = T_AUTO; + setting.level_sweep = 0.0; + setting.level = -15.0; setting.trigger_level = -150.0; setting.linearity_step = 0; trace[TRACE_STORED].enabled = false; @@ -155,6 +157,12 @@ void set_drive(int d) dirty = true; } +void set_level_sweep(float l) +{ + setting.level_sweep = l; +} + + void set_tracking_output(int t) { setting.tracking_output = t; @@ -235,6 +243,13 @@ int get_attenuation(void) return(setting.attenuate); } +void set_level(float v) +{ + setting.level = v; + set_attenuation((int)v); + dirty = true; +} + void set_attenuation(int a) { if (setting.mode == M_GENLOW) { @@ -951,6 +966,40 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) dirty = false; } + if (setting.level_sweep != 0.0) { + static int old_a = -150; + int a = setting.level + (i / 290.0) * setting.level_sweep; + if (a != old_a) { + old_a = a; + int d = 0; // Start at lowest drive level; + a = a + POWER_OFFSET; + if (a > 0) { + d++; + a = a - 3; + } + if (a > 0) { + d++; + a = a - 3; + } + if (a > 0) { + d++; + a = a - 3; + } + SI4432_Sel = 0; + SI4432_Drive(d); + if (a > 0) + a = 0; + if( a > - SWITCH_ATTENUATION) { + set_switch_transmit(); + } else { + a = a + SWITCH_ATTENUATION; + set_switch_receive(); + } + a = -a; + PE4302_Write_Byte(a * 2 ); + } + } + if (MODE_OUTPUT(setting.mode) && setting.modulation == MO_AM) { // AM modulation int p = setting.attenuate * 2 + am_modulation[modulation_counter]; PE4302_Write_Byte(p); diff --git a/si4432.c b/si4432.c index f58651d..731ca3c 100644 --- a/si4432.c +++ b/si4432.c @@ -145,6 +145,11 @@ void SI4432_Reset(void) } } +void SI4432_Drive(int d) +{ + SI4432_Write_Byte(0x6D, (byte) (0x18+(d & 7))); +} + void SI4432_Transmit(int d) { int count = 0; diff --git a/ui_sa.c b/ui_sa.c index 412b9e3..223e8af 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -279,7 +279,7 @@ const uint16_t right_icons [] = 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_10MHZ, KM_REPEAT, KM_OFFSET, KM_TRIGGER, + KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE, KM_LOWOUTLEVEL, KM_DECAY, KM_NOISE, KM_10MHZ, KM_REPEAT, KM_OFFSET, KM_TRIGGER, KM_LEVELSWEEP, }; @@ -391,6 +391,7 @@ static const keypads_t * const keypads_mode_tbl[] = { keypads_level, // KM_REPEA keypads_level, // KM_OFFSET keypads_level, // KM_TRIGGER + keypads_level, // KM_LEVELSWEEP }; #ifdef __VNA__ @@ -402,7 +403,7 @@ static const char * const keypad_mode_label[] = { 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"// 16- + "OFFSET" , "REPEATS", "OFFSET", "TRIGGER", "LEVELSWEEP"// 16- }; #endif @@ -1059,6 +1060,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, KM_10MHZ, "10MHZ: %s", NULL}, { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel @@ -1718,7 +1720,11 @@ static void fetch_numeric_target(void) break; case KM_OFFSET: uistat.value = setting.offset; - plot_printf(uistat.text, sizeof uistat.text, "%fdB", uistat.value); + plot_printf(uistat.text, sizeof uistat.text, "%.1fdB", uistat.value); + break; + case KM_LEVELSWEEP: + uistat.value = setting.level_sweep; + plot_printf(uistat.text, sizeof uistat.text, "%.1fdB", uistat.value); break; case KM_TRIGGER: uistat.value = setting.trigger_level; @@ -1785,7 +1791,7 @@ set_numeric_value(void) set_drive(uistat.value); break; case KM_LOWOUTLEVEL: - set_attenuation(uistat.value); + set_level(uistat.value); break; case KM_DECAY: set_decay(uistat.value); @@ -1803,6 +1809,9 @@ set_numeric_value(void) case KM_OFFSET: set_offset(uistat.value); break; + case KM_LEVELSWEEP: + set_level_sweep(uistat.value); + break; case KM_TRIGGER: set_trigger_level(uistat.value); break;