From 84528e8869117e6902b7681ca9e07938418cfb6a Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sat, 20 Feb 2021 08:37:46 +0100 Subject: [PATCH 1/9] Corrected correction table center frequency --- main.c | 4 ++-- sa_cmd.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 42f0b7b..73606b3 100644 --- a/main.c +++ b/main.c @@ -892,13 +892,13 @@ config_t config = { .low_level_offset = 100, // Uncalibrated .high_level_offset = 100, // Uncalibrated #ifdef TINYSA3 - .low_correction_frequency = { 10000, 100000, 200000, 500000, 50000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, + .low_correction_frequency = { 10000, 100000, 200000, 500000, 30000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, .low_correction_value = { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +3.0, +4.0, +8.1 }, .high_correction_frequency = { 240000000, 280000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 960000000 }, .high_correction_value = { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 }, #endif #ifdef TINYSA4 - .low_correction_frequency = { 10000, 100000, 200000, 500000, 50000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, + .low_correction_frequency = { 10000, 100000, 200000, 500000, 30000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, .low_correction_value = { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 }, .high_correction_frequency = { 10000, 100000, 200000, 500000, 50000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, .high_correction_value = { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 }, diff --git a/sa_cmd.c b/sa_cmd.c index d8986cc..083ec73 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -226,6 +226,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) config.high_level_offset = v; else goto usage; + dirty = true; } else { usage: shell_printf("leveloffset [low|high] []\r\n"); From f7790b7fdcede52efe19bbddbc53d8975f970326 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 21 Feb 2021 08:16:43 +0100 Subject: [PATCH 2/9] Sweep DAC on PA4 added --- NANOVNA_STM32_F072/board.h | 6 +++--- main.c | 8 +++----- sa_core.c | 2 ++ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/NANOVNA_STM32_F072/board.h b/NANOVNA_STM32_F072/board.h index b1fa657..6ec8e5e 100644 --- a/NANOVNA_STM32_F072/board.h +++ b/NANOVNA_STM32_F072/board.h @@ -128,7 +128,7 @@ PIN_MODE_INPUT(1U) | \ PIN_MODE_INPUT(2U) | \ PIN_MODE_INPUT(3U) | \ - PIN_MODE_INPUT(4U) | \ + PIN_MODE_ANALOG(4U) | \ PIN_MODE_INPUT(5U) | \ PIN_MODE_ANALOG(GPIOA_XP) | \ PIN_MODE_ANALOG(GPIOA_YP) | \ @@ -160,7 +160,7 @@ PIN_OSPEED_2M(1) | \ PIN_OSPEED_2M(2) | \ PIN_OSPEED_2M(3) | \ - PIN_OSPEED_100M(4) | \ + PIN_OSPEED_2M(4) | \ PIN_OSPEED_100M(5) | \ PIN_OSPEED_2M(6) | \ PIN_OSPEED_2M(7) | \ @@ -176,7 +176,7 @@ PIN_PUPDR_PULLDOWN(1) | \ PIN_PUPDR_PULLDOWN(2) | \ PIN_PUPDR_PULLDOWN(3) | \ - PIN_PUPDR_PULLDOWN(4) | \ + PIN_PUPDR_FLOATING(4) | \ PIN_PUPDR_PULLDOWN(5) | \ PIN_PUPDR_FLOATING(6) | \ PIN_PUPDR_FLOATING(7) | \ diff --git a/main.c b/main.c index 73606b3..0bb96b3 100644 --- a/main.c +++ b/main.c @@ -2710,12 +2710,12 @@ static const I2CConfig i2ccfg = { .cr1 = 0, // CR1 register initialization. .cr2 = 0 // CR2 register initialization. }; +#endif static DACConfig dac1cfg1 = { //init: 2047U, init: 1922U, datamode: DAC_DHRM_12BIT_RIGHT }; -#endif #pragma GCC pop_options @@ -2861,15 +2861,13 @@ int main(void) */ shell_init_connection(); -/* restore frequencies and calibration 0 slot properties from flash memory */ -#ifdef __VNA__ - dac1cfg1.init = config.dac_value; + dac1cfg1.init = 0; + /* * Starting DAC1 driver, setting up the output pin as analog as suggested * by the Reference Manual. */ dacStart(&DACD2, &dac1cfg1); -#endif setupSA(); set_sweep_points(POINTS_COUNT); diff --git a/sa_core.c b/sa_core.c index 3d04abc..f79bdc5 100644 --- a/sa_core.c +++ b/sa_core.c @@ -2171,6 +2171,8 @@ sweep_again: // stay in sweep loop when output mo return false; } + dacPutChannelX(&DACD2, 0, i*14); // Output sweep voltage + // ----------------------- in loop AGC --------------------------------- #ifdef __SI4432__ From add7cb225fa20699a99869712b8e295d9c40f3ce Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 22 Feb 2021 08:09:25 +0100 Subject: [PATCH 3/9] Add low output start burst --- main.c | 2 ++ nanovna.h | 1 + plot.c | 2 +- sa_cmd.c | 11 +++++++++++ sa_core.c | 6 +++++- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 0bb96b3..aff2ec2 100644 --- a/main.c +++ b/main.c @@ -907,6 +907,7 @@ config_t config = { .cor_am = -14, .cor_wfm = -17, .cor_nfm = -17, + .sweep_voltage = 3.3, }; //properties_t current_props; @@ -2348,6 +2349,7 @@ static const VNAShellCommand commands[] = {"time" , cmd_time , 0}, #endif {"dac" , cmd_dac , 0}, + {"sweep_voltage",cmd_sweep_voltage,0}, {"saveconfig" , cmd_saveconfig , 0}, {"clearconfig" , cmd_clearconfig , 0}, {"data" , cmd_data , CMD_WAIT_MUTEX}, diff --git a/nanovna.h b/nanovna.h index 0b94aeb..fbdb3b0 100644 --- a/nanovna.h +++ b/nanovna.h @@ -527,6 +527,7 @@ typedef struct config { int8_t cor_am; int8_t cor_wfm; int8_t cor_nfm; + float sweep_voltage; uint32_t dummy; // uint8_t _reserved[22]; freq_t checksum; diff --git a/plot.c b/plot.c index 9482847..cac69d7 100644 --- a/plot.c +++ b/plot.c @@ -119,7 +119,7 @@ float2int(float v) void update_grid(void) { - freq_t gdigit = 100000000; + freq_t gdigit = 1000000000; freq_t fstart = get_sweep_frequency(ST_START); freq_t fspan = get_sweep_frequency(ST_SPAN); freq_t grid; diff --git a/sa_cmd.c b/sa_cmd.c index 083ec73..da40634 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -246,6 +246,17 @@ VNA_SHELL_FUNCTION(cmd_deviceid) } } +VNA_SHELL_FUNCTION(cmd_sweep_voltage) +{ + float value; + if (argc != 1) { + shell_printf("usage: sweep_voltage {value(0-3.3)}\r\n"\ + "current value: %f\r\n", config.sweep_voltage); + return; + } + value = my_atof(argv[0]); + config.sweep_voltage = value; +} VNA_SHELL_FUNCTION(cmd_rbw) { diff --git a/sa_core.c b/sa_core.c index f79bdc5..a1fc4af 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1698,6 +1698,10 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / } if (setting.mode == M_GENLOW && ( setting.frequency_step != 0 || setting.level_sweep != 0.0 || i == 0)) {// if in low output mode and level sweep or frequency weep is active or at start of sweep + if (i == 0) + set_switch_transmit(); + else + set_switch_off(); float ls=setting.level_sweep; // calculate and set the output level if (ls > 0) ls += 0.5; @@ -2171,7 +2175,7 @@ sweep_again: // stay in sweep loop when output mo return false; } - dacPutChannelX(&DACD2, 0, i*14); // Output sweep voltage + dacPutChannelX(&DACD2, 0, (((float)i)*config.sweep_voltage)*4.279); // Output sweep voltage 4095 -> 3.3 Volt // ----------------------- in loop AGC --------------------------------- From 8fd761d53b4399b1f5fe5f89aa78764fd592aa37 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 22 Feb 2021 08:34:07 +0100 Subject: [PATCH 4/9] Corrected burst error --- sa_core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sa_core.c b/sa_core.c index a1fc4af..87f4889 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1697,11 +1697,15 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / } } - if (setting.mode == M_GENLOW && ( setting.frequency_step != 0 || setting.level_sweep != 0.0 || i == 0)) {// if in low output mode and level sweep or frequency weep is active or at start of sweep + if (setting.mode == M_GENLOW && ( setting.frequency_step != 0 || setting.level_sweep != 0.0)) {// start burst + SI4432_Sel = SI4432_LO ; if (i == 0) set_switch_transmit(); - else + else if (i == 1) set_switch_off(); + } + + if (setting.mode == M_GENLOW && ( setting.frequency_step != 0 || setting.level_sweep != 0.0 || i == 0)) {// if in low output mode and level sweep or frequency weep is active or at start of sweep float ls=setting.level_sweep; // calculate and set the output level if (ls > 0) ls += 0.5; From 6090682d2e84a588749c11206a0a534fa30d290c Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 22 Feb 2021 08:49:11 +0100 Subject: [PATCH 5/9] Added DC pulse --- sa_core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sa_core.c b/sa_core.c index 87f4889..3da0fe7 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1699,10 +1699,13 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / if (setting.mode == M_GENLOW && ( setting.frequency_step != 0 || setting.level_sweep != 0.0)) {// start burst SI4432_Sel = SI4432_LO ; - if (i == 0) + if (i == 0) { set_switch_transmit(); - else if (i == 1) + SI4432_Write_Byte(SI4432_GPIO2_CONF, 0x1D) ; // Set GPIO2 output to ground + } else if (i == 1) { set_switch_off(); + SI4432_Write_Byte(SI4432_GPIO2_CONF, 0x1F) ; // Set GPIO2 output to ground + } } if (setting.mode == M_GENLOW && ( setting.frequency_step != 0 || setting.level_sweep != 0.0 || i == 0)) {// if in low output mode and level sweep or frequency weep is active or at start of sweep From 08a6176b06d027d8887f7b7c46824100c9606d6f Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 22 Feb 2021 14:35:04 +0100 Subject: [PATCH 6/9] Only DC pulse --- sa_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sa_core.c b/sa_core.c index 3da0fe7..0971286 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1700,10 +1700,10 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / if (setting.mode == M_GENLOW && ( setting.frequency_step != 0 || setting.level_sweep != 0.0)) {// start burst SI4432_Sel = SI4432_LO ; if (i == 0) { - set_switch_transmit(); +// set_switch_transmit(); SI4432_Write_Byte(SI4432_GPIO2_CONF, 0x1D) ; // Set GPIO2 output to ground } else if (i == 1) { - set_switch_off(); +// set_switch_off(); SI4432_Write_Byte(SI4432_GPIO2_CONF, 0x1F) ; // Set GPIO2 output to ground } } From 13874964797ee6a4ddace356f3090206e8c39a94 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Thu, 25 Feb 2021 11:41:33 +0100 Subject: [PATCH 7/9] Small bugs and space saving Waterfall colors Attennuation averaging Removed ham bands --- main.c | 15 +++++-- nanovna.h | 7 +-- plot.c | 6 ++- sa_cmd.c | 128 +++++++++++++++++++++++++++++------------------------- sa_core.c | 30 ++++++++----- ui_sa.c | 2 +- 6 files changed, 107 insertions(+), 81 deletions(-) diff --git a/main.c b/main.c index aff2ec2..24d7585 100644 --- a/main.c +++ b/main.c @@ -2423,6 +2423,7 @@ static const VNAShellCommand commands[] = #ifdef ENABLE_THREADS_COMMAND {"threads" , cmd_threads , 0}, #endif +#ifdef __SINGLE_LETTER__ { "y", cmd_y, CMD_WAIT_MUTEX }, { "i", cmd_i, CMD_WAIT_MUTEX }, { "v", cmd_v, CMD_WAIT_MUTEX }, @@ -2437,9 +2438,10 @@ static const VNAShellCommand commands[] = { "o", cmd_o, CMD_WAIT_MUTEX }, { "d", cmd_d, CMD_WAIT_MUTEX }, { "f", cmd_f, CMD_WAIT_MUTEX }, +#endif #ifdef TINYSA4 { "g", cmd_g, CMD_WAIT_MUTEX }, - #endif +#endif #ifdef __ADF4351__ { "x", cmd_x, 0 }, #endif @@ -2452,7 +2454,11 @@ VNA_SHELL_FUNCTION(cmd_help) (void)argv; const VNAShellCommand *scp = commands; shell_printf("Commands:"); - while (scp->sc_name != NULL && scp->sc_function != cmd_y) { + while (scp->sc_name != NULL +#ifdef __SINGLE_LETTER__ + && scp->sc_function != cmd_y +#endif + ) { shell_printf(" %s", scp->sc_name); scp++; } @@ -3018,7 +3024,10 @@ void hard_fault_handler_c(uint32_t *sp) #endif shell_printf("===================================\r\n"); #else - (void)sp; + ili9341_set_background(LCD_BG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); + ili9341_drawstring("FATAL ERROR", OFFSETX, 120); + (void)sp; #endif while (true) { } diff --git a/nanovna.h b/nanovna.h index fbdb3b0..834955c 100644 --- a/nanovna.h +++ b/nanovna.h @@ -46,11 +46,12 @@ #define __SELFTEST__ #define __CALIBRATE__ #define __FAST_SWEEP__ // Pre-fill SI4432 RSSI buffer to get fastest sweep in zero span mode -#define __HAM_BAND__ +//#define __HAM_BAND__ //#define __ULTRA__ // Add harmonics mode on low input. #define __SPUR__ // Does spur reduction by shifting IF //#define __USE_SERIAL_CONSOLE__ // Enable serial I/O connection (need enable HAL_USE_SERIAL as TRUE in halconf.h) - +#define __SINGLE_LETTER__ +#define __NICE_BIG_FONT__ #define __QUASI_PEAK__ #ifdef TINYSA3 @@ -411,7 +412,7 @@ extern const uint8_t numfont16x22[]; #define bFONT_GET_DATA(ch) ( &x7x11b_bits[(ch-bFONT_START_CHAR)*bFONT_GET_HEIGHT]) #define bFONT_GET_WIDTH(ch) (8-(x7x11b_bits[(ch-bFONT_START_CHAR)*bFONT_GET_HEIGHT]&7)) -#if 1 // Set to 0 to save 3kByte and loose nice font +#ifdef __NICE_BIG_FONT__ #define wFONT_START_CHAR 0x17 #define wFONT_MAX_WIDTH 12 #define wFONT_GET_HEIGHT 14 diff --git a/plot.c b/plot.c index cac69d7..8b83805 100644 --- a/plot.c +++ b/plot.c @@ -39,7 +39,9 @@ static void cell_blit_bitmap(int x, int y, uint16_t w, uint16_t h, const uint8_t static void draw_battery_status(void); static void update_waterfall(void); void cell_draw_test_info(int x0, int y0); - +#ifndef wFONT_GET_DATA +static void cell_drawstring_size(char *str, int x, int y, int size); +#endif static int16_t grid_offset; static int16_t grid_width; static freq_t grid_span; @@ -2447,7 +2449,7 @@ static void update_waterfall(void){ gamma_correct(b); color = RGB565(r, g, b); #else - uint16_t y = CELL_Y(index[i])* (graph_bottom == BIG_WATERFALL ? 2 : 1); // should be always in range 0 - graph_bottom *2 depends on height of scroll + uint16_t y = SMALL_WATERFALL - CELL_Y(index[i])* (graph_bottom == BIG_WATERFALL ? 2 : 1); // should be always in range 0 - graph_bottom *2 depends on height of scroll // Calculate gradient palette for range 0 .. 192 // idx r g b // 0 - 127 0 0 diff --git a/sa_cmd.c b/sa_cmd.c index da40634..f2dc797 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -18,7 +18,6 @@ #pragma GCC optimize ("Os") -static int VFO = 0; static int points = 101; // For 's' and 'm' commands VNA_SHELL_FUNCTION(cmd_mode) @@ -324,64 +323,6 @@ usage: } -VNA_SHELL_FUNCTION(cmd_v) -{ - if (argc != 1) { - shell_printf("%d\r\n", VFO); - return; - } - VFO = my_atoi(argv[0]) > 0 ? 1 : 0; - shell_printf("VFO %d\r\n", VFO); -} - -VNA_SHELL_FUNCTION(cmd_y) -{ - int rvalue; - if (argc != 1 && argc != 2) { - shell_printf("usage: y {addr(0-95)} [value(0-0xFF)]\r\n"); - return; - } - rvalue = my_atoui(argv[0]); -#ifdef __SI4432__ - int lvalue = 0; - SI4432_Sel = VFO; - if (argc == 2){ - lvalue = my_atoui(argv[1]); - SI4432_Write_Byte(rvalue, lvalue); - } else { - lvalue = SI4432_Read_Byte(rvalue); - shell_printf("%x\r\n", lvalue); - } -#endif -} -#if 0 // not used -VNA_SHELL_FUNCTION(cmd_z) -{ - static const char cmd_z_list[] = "t|r|i"; - if (argc != 1) { - shell_printf("usage: z %s\r\n", cmd_z_list); - return; - } - if (argc == 1) { -#ifdef __SI4432__ - SI4432_Sel = VFO; - int type = get_str_index(argv[0], cmd_z_list); - switch(type) { - case 0: - SI4432_Transmit(3); - break; - case 1: - SI4432_Receive(); - break; - case 2: - SI4432_Reset(); - break; - } -#endif - } -} -#endif - VNA_SHELL_FUNCTION(cmd_selftest) { if (argc < 1 || argc > 2) { @@ -396,6 +337,10 @@ VNA_SHELL_FUNCTION(cmd_selftest) sweep_mode = SWEEP_SELFTEST; } +#ifdef __SINGLE_LETTER__ + +static int VFO = 0; + #ifdef __ADF4351__ uint32_t xtoi(char *t) @@ -441,7 +386,6 @@ VNA_SHELL_FUNCTION(cmd_x) } #endif - VNA_SHELL_FUNCTION(cmd_i) { int rvalue; @@ -550,6 +494,68 @@ VNA_SHELL_FUNCTION(cmd_s) points = my_atoi(argv[0]); } + +VNA_SHELL_FUNCTION(cmd_v) +{ + if (argc != 1) { + shell_printf("%d\r\n", VFO); + return; + } + VFO = my_atoi(argv[0]) > 0 ? 1 : 0; + shell_printf("VFO %d\r\n", VFO); +} + +VNA_SHELL_FUNCTION(cmd_y) +{ + int rvalue; + if (argc != 1 && argc != 2) { + shell_printf("usage: y {addr(0-95)} [value(0-0xFF)]\r\n"); + return; + } + rvalue = my_atoui(argv[0]); +#ifdef __SI4432__ + int lvalue = 0; + SI4432_Sel = VFO; + if (argc == 2){ + lvalue = my_atoui(argv[1]); + SI4432_Write_Byte(rvalue, lvalue); + } else { + lvalue = SI4432_Read_Byte(rvalue); + shell_printf("%x\r\n", lvalue); + } +#endif +} +#if 0 // not used +VNA_SHELL_FUNCTION(cmd_z) +{ + static const char cmd_z_list[] = "t|r|i"; + if (argc != 1) { + shell_printf("usage: z %s\r\n", cmd_z_list); + return; + } + if (argc == 1) { +#ifdef __SI4432__ + SI4432_Sel = VFO; + int type = get_str_index(argv[0], cmd_z_list); + switch(type) { + case 0: + SI4432_Transmit(3); + break; + case 1: + SI4432_Receive(); + break; + case 2: + SI4432_Reset(); + break; + } +#endif + } +} +#endif + + +#endif + void sweep_remote(void) { uint32_t i; @@ -576,6 +582,7 @@ void sweep_remote(void) sweep_mode = 0; } +#ifdef __SINGLE_LETTER__ VNA_SHELL_FUNCTION(cmd_m) { (void)argc; @@ -627,6 +634,7 @@ VNA_SHELL_FUNCTION(cmd_f) setting.test_argument = my_atoi(argv[0]);; sweep_mode = SWEEP_SELFTEST; } +#endif VNA_SHELL_FUNCTION(cmd_correction) { diff --git a/sa_core.c b/sa_core.c index 0971286..229c4a3 100644 --- a/sa_core.c +++ b/sa_core.c @@ -3084,12 +3084,14 @@ int validate_flatness(int i) { const float atten_step[7] = { 0.0, 0.5, 1.0, 2.0, 4.0, 8.0, 16.0 }; int validate_atten(int i) { + int status = TS_PASS; float reference_peak_level = 0.0; test_fail_cause[i] = "Attenuator "; // for (int j= 0; j < 64; j++ ) { for (int j= 0; j < 7; j++ ) { -// set_attenuation(((float)j)/2.0); - set_attenuation(atten_step[j]); +// float a = ((float)j)/2.0; + float a = atten_step[j]; + set_attenuation(a); float summed_peak_level = 0; #define ATTEN_TEST_SWEEPS 5 for (int k=0; k= ATTEN_TEST_CRITERIA) - return(TS_FAIL); + if (SDU1.config->usbp->state == USB_ACTIVE) shell_printf("Attenuation %.2fdB, measured level %.2fdBm, delta %.2fdB\n\r",a, summed_peak_level, summed_peak_level - reference_peak_level); +#define ATTEN_TEST_CRITERIA 1 + if (summed_peak_level - reference_peak_level <= -ATTEN_TEST_CRITERIA || summed_peak_level - reference_peak_level >= ATTEN_TEST_CRITERIA) { + status = TS_FAIL; + // draw_all(true); + } + } } - test_fail_cause[i] = ""; - return(TS_PASS); + if (status == TS_PASS) + test_fail_cause[i] = ""; + return(status); } int validate_display(int tc) diff --git a/ui_sa.c b/ui_sa.c index 007cb78..6e90237 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1782,7 +1782,7 @@ static const menuitem_t menu_settings[] = { { MT_ADV_CALLBACK | MT_LOW, 0,"LO OUTPUT", menu_lo_output_acb}, { MT_KEYPAD, KM_ACTUALPOWER, "ACTUAL\nPOWER", NULL}, - { MT_KEYPAD | MT_LOW, KM_IF, "IF FREQ", "Set to zero for auto IF"}, + { MT_KEYPAD | MT_LOW, KM_IF, "IF FREQ", "0=auto IF"}, { MT_SUBMENU,0, "SCAN SPEED", menu_scanning_speed}, { MT_KEYPAD, KM_REPEAT, "SAMPLE\nREPEAT", "1..100"}, { MT_SUBMENU | MT_LOW,0, "MIXER\nDRIVE", menu_lo_drive}, From a95ec1d8cc72c73b6c27476189cd6e44a49b57db Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Fri, 26 Feb 2021 13:00:30 +0100 Subject: [PATCH 8/9] Remote desktop --- ili9341.c | 15 +++++++ main.c | 62 ++++++++++++++++++++++++++- nanovna.h | 17 +++++++- sa_core.c | 15 +++++-- si4432.c | 122 ++++++++++++++---------------------------------------- ui.c | 34 +++++++++++++-- ui_sa.c | 20 +++++++++ 7 files changed, 184 insertions(+), 101 deletions(-) diff --git a/ili9341.c b/ili9341.c index c0fff3b..a22bee6 100644 --- a/ili9341.c +++ b/ili9341.c @@ -451,6 +451,14 @@ void ili9341_fill(int x, int y, int w, int h) dmaStreamSetMemory0(dmatx, &background_color); dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD); dmaStreamFlush(w * h); +#ifdef __REMOTE_DESKTOP__ + if (auto_capture) { + send_region("fill", x,y,w,h); + spi_buffer[0] = background_color; + send_buffer((uint8_t *)spi_buffer, 2); + osalThreadSleepMilliseconds(2); + } +#endif } // Copy spi_buffer to region @@ -464,6 +472,13 @@ void ili9341_bulk(int x, int y, int w, int h) dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_MINC); dmaStreamFlush(w * h); +#ifdef __REMOTE_DESKTOP__ + if (auto_capture) { + send_region("bulk", x,y,w,h); + send_buffer((uint8_t *)spi_buffer, w*h*2); + osalThreadSleepMilliseconds(2); + } +#endif } #endif diff --git a/main.c b/main.c index 24d7585..b0903f0 100644 --- a/main.c +++ b/main.c @@ -107,7 +107,7 @@ static int8_t drive_strength = DRIVE_STRENGTH_AUTO; #endif uint8_t sweep_mode = SWEEP_ENABLE; volatile uint8_t redraw_request = 0; // contains REDRAW_XXX flags - +volatile int auto_capture = false; // Version text, displayed in Config->Version menu, also send by info command const char *info_about[]={ BOARD_NAME, @@ -808,6 +808,41 @@ VNA_SHELL_FUNCTION(cmd_dump) } #endif +#ifdef __REMOTE_DESKTOP__ +VNA_SHELL_FUNCTION(cmd_refresh) +{ +// read pixel count at one time (PART*2 bytes required for read buffer) + int m = generic_option_cmd("refresh", "off|on", argc, argv[0]); + if (m>=0) { + auto_capture = m; + } +} + +volatile int mouse_x = 0; +volatile int mouse_y = 0; +volatile int mouse_down = false; + +VNA_SHELL_FUNCTION(cmd_touch) +{ + if (argc == 2){ + mouse_x = (uint32_t)my_atoi(argv[0]); + mouse_y = (uint32_t)my_atoi(argv[1]); + mouse_down = true; + handle_touch_interrupt(); + } +} + +VNA_SHELL_FUNCTION(cmd_release) +{ + if (argc==2) { + mouse_x = (uint32_t)my_atoi(argv[0]); + mouse_y = (uint32_t)my_atoi(argv[1]); + } + mouse_down = false; + handle_touch_interrupt(); +} +#endif + VNA_SHELL_FUNCTION(cmd_capture) { // read pixel count at one time (PART*2 bytes required for read buffer) @@ -828,6 +863,26 @@ VNA_SHELL_FUNCTION(cmd_capture) } } +void send_region(const char *t, int x, int y, int w, int h) +{ + shell_printf("%s\r\n", t); + streamPut(shell_stream, (((uint16_t) x) & 0xff)); + streamPut(shell_stream, (((uint16_t)x>>8) & 0xff)); + streamPut(shell_stream, (((uint16_t) y) & 0xff)); + streamPut(shell_stream, (((uint16_t)y>>8) & 0xff)); + streamPut(shell_stream, (((uint16_t) w) & 0xff)); + streamPut(shell_stream, (((uint16_t)w>>8) & 0xff)); + streamPut(shell_stream, (((uint16_t) h) & 0xff)); + streamPut(shell_stream, (((uint16_t)h>>8) & 0xff)); +} + +void send_buffer(uint8_t * buf, int s) +{ + for (int i = 0; i < s; i++) { + streamPut(shell_stream, *buf++); + } + shell_printf("ch> \r\n"); +} #if 0 VNA_SHELL_FUNCTION(cmd_gamma) { @@ -2389,6 +2444,11 @@ static const VNAShellCommand commands[] = {"edelay" , cmd_edelay , 0}, #endif {"capture" , cmd_capture , CMD_WAIT_MUTEX}, +#ifdef __REMOTE_DESKTOP__ + {"refresh" , cmd_refresh , 0}, + {"touch" , cmd_touch , 0}, + {"release" , cmd_release , 0}, +#endif {"vbat" , cmd_vbat , CMD_WAIT_MUTEX}, // Uses same adc as touch!!!!! #ifdef ENABLE_VBAT_OFFSET_COMMAND {"vbat_offset" , cmd_vbat_offset , 0}, diff --git a/nanovna.h b/nanovna.h index 834955c..63a6118 100644 --- a/nanovna.h +++ b/nanovna.h @@ -51,8 +51,9 @@ #define __SPUR__ // Does spur reduction by shifting IF //#define __USE_SERIAL_CONSOLE__ // Enable serial I/O connection (need enable HAL_USE_SERIAL as TRUE in halconf.h) #define __SINGLE_LETTER__ -#define __NICE_BIG_FONT__ +//#define __NICE_BIG_FONT__ #define __QUASI_PEAK__ +#define __REMOTE_DESKTOP__ #ifdef TINYSA3 #define DEFAULT_IF 433800000 @@ -92,6 +93,13 @@ typedef float measurement_t[TRACES_MAX][POINTS_COUNT]; extern measurement_t measured; #endif +#ifdef __REMOTE_DESKTOP__ +extern volatile int auto_capture; +extern volatile int mouse_x; +extern volatile int mouse_y; +extern volatile int mouse_down; +#endif + #ifdef __VNA__ // Minimum frequency set #define START_MIN 50000 @@ -161,7 +169,10 @@ freq_t get_sweep_frequency(int type); void my_microsecond_delay(int t); float my_atof(const char *p); int shell_printf(const char *fmt, ...); - +#ifdef __REMOTE_DESKTOP__ +void send_region(const char *t, int x, int y, int w, int h); +void send_buffer(uint8_t * buf, int s); +#endif void set_marker_frequency(int m, freq_t f); void toggle_sweep(void); void toggle_mute(void); @@ -282,6 +293,8 @@ void set_measurement(int); // extern int settingSpeed; //extern int setting.step_delay; void sweep_remote(void); +extern int generic_option_cmd( const char *cmd, const char *cmd_list, int argc, char *argv); + #ifdef __AUDIO__ /* * dsp.c diff --git a/sa_core.c b/sa_core.c index 229c4a3..165912b 100644 --- a/sa_core.c +++ b/sa_core.c @@ -3028,8 +3028,12 @@ int validate_signal_within(int i, float margin) if (fabsf(peakLevel-test_case[i].pass) > margin) { return TS_CRITICAL; } + if (setting.measurement == M_PASS_BAND) { + peakFreq = (markers[2].frequency + markers[1].frequency)/2; + markers[0].frequency = peakFreq; + } test_fail_cause[i] = "Frequency "; - if (peakFreq < test_case[i].center * 1000000 - 600000 || test_case[i].center * 1000000 + 600000 < peakFreq ) + if (peakFreq < test_case[i].center * 1000000 - 100000 || test_case[i].center * 1000000 + 100000 < peakFreq ) return TS_FAIL; test_fail_cause[i] = ""; return TS_PASS; @@ -3233,8 +3237,13 @@ common_silent: set_mode(M_LOW); setting.tracking = true; //Sweep BPF setting.auto_IF = false; - setting.frequency_IF = DEFAULT_IF+200000; // Center on SAW filters + setting.frequency_IF = DEFAULT_IF+210000; // Center on SAW filters set_refer_output(2); + markers[1].enabled = M_ENABLED; + markers[1].mtype = M_DELTA; + markers[2].enabled = M_ENABLED; + markers[2].mtype = M_DELTA; + setting.measurement = M_PASS_BAND; goto common; case TP_10MHZ: // 10MHz input set_mode(M_LOW); @@ -3253,7 +3262,7 @@ common_silent: for (int j = 0; j < setting._sweep_points/2 - W2P(test_case[i].width); j++) stored_t[j] = test_case[i].stop; for (int j = setting._sweep_points/2 + W2P(test_case[i].width); j < setting._sweep_points; j++) - stored_t[j] = test_case[i].stop; + stored_t[j] = test_case[i].stop - (i == 6?5:0); for (int j = setting._sweep_points/2 - W2P(test_case[i].width); j < setting._sweep_points/2 + W2P(test_case[i].width); j++) stored_t[j] = test_case[i].pass; break; diff --git a/si4432.c b/si4432.c index ef3ed0f..6cea287 100644 --- a/si4432.c +++ b/si4432.c @@ -223,7 +223,7 @@ void SI4432_Drive(int d) void SI4432_Transmit(int d) { int count = 0; - SI4432_Write_Byte(SI4432_TX_POWER, (uint8_t) (0x18+(d & 7))); + SI4432_Drive(d); if (( SI4432_Read_Byte(SI4432_DEV_STATUS) & 0x03 ) == 2) return; // Already in transmit mode chThdSleepMilliseconds(3); @@ -625,84 +625,40 @@ pureRSSI_t SI4432_RSSI(uint32_t i, int s) return RSSI_RAW; } +static uint8_t SI4432_init_script[] = +{ + SI4432_INT_ENABLE1, 0x0, + SI4432_INT_ENABLE2, 0x0, + SI4432_CLOCK_RECOVERY_GEARSHIFT, 0x00, + SI4432_AGC_OVERRIDE, 0x60, + SI4432_AFC_LOOP_GEARSHIFT_OVERRIDE, 0x00, + SI4432_AFC_TIMING_CONTROL, 0x02, + SI4432_CLOCK_RECOVERY_GEARSHIFT, 0x03, + SI4432_CLOCK_RECOVERY_OFFSET2, 0x01, + SI4432_CLOCK_RECOVERY_OFFSET1, 0x11, + SI4432_CLOCK_RECOVERY_OFFSET0, 0x11, + SI4432_CLOCK_RECOVERY_TIMING_GAIN1, 0x01, + SI4432_CLOCK_RECOVERY_TIMING_GAIN0, 0x13, + SI4432_AFC_LIMITER, 0xFF, + SI4432_DATAACCESS_CONTROL, 0x61, // Disable all packet handling + SI4432_AGC_OVERRIDE, 0x60, // AGC, no LNA, fast gain increment + SI4432_GPIO0_CONF, 0x12, // Normal + SI4432_GPIO1_CONF, 0x15, + SI4432_GPIO2_CONF, 0x1F +}; + void SI4432_Sub_Init(void) { SI4432_Reset(); - - - SI4432_Write_Byte(SI4432_AGC_OVERRIDE, 0x60); //AGC override according to WBS3 - - -#if 0 // Not sure if these add any value - //set VCO and PLL Only for SI4432 V2 - SI4432_Write_Byte(SI4432_FREQ_DEVIATION, 0x1F); //write 0x1F to the Frequency Deviation register - // VCO tuning registers - SI4432_Write_Byte(SI4432_VCO_CURRENT_TRIM, 0x7F); //write 0x7F to the VCO Current Trimming register - SI4432_Write_Byte(SI4432_CHARGEPUMP_OVERRIDE, 0x80); //write 0xD7 to the ChargepumpCurrentTrimmingOverride register - SI4432_Write_Byte(SI4432_DIVIDER_CURRENT_TRIM, 0x40); //write 0x40 to the Divider Current Trimming register -#endif -#if 0 - //set the AGC, BAD FOR PERFORMANCE!!!!!! - SI4432_Write_Byte(0x6A, 0x0B); //write 0x0B to the AGC Override 2 register - //set ADC reference voltage to 0.9V, BAD FOR PERFORMANCE!!!!!! - SI4432_Write_Byte(0x68, 0x04); //write 0x04 to the Deltasigma ADC Tuning 2 register - - SI4432_Write_Byte(0x1F, 0x03); //write 0x03 to the Clock Recovery Gearshift Override register - -#endif - - - SI4432_Write_Byte(SI4432_INT_ENABLE1, 0x0); - SI4432_Write_Byte(SI4432_INT_ENABLE2, 0x0); - // Enable receiver chain -// SI4432_Write_Byte(SI4432_STATE, 0x05); - // Clock Recovery Gearshift Value - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_GEARSHIFT, 0x00); + uint8_t *p = SI4432_init_script; + while (*p) { + uint8_t r = *p++; + uint8_t v = *p++; + SI4432_Write_Byte (r,v); + } // IF Filter Bandwidth - set_rbw(100) ; -// // Register 0x75 Frequency Band Select -// uint8_t sbsel = 1 ; // recommended setting -// uint8_t hbsel = 0 ; // low bands -// uint8_t fb = 19 ; // 430�439.9 MHz -// uint8_t FBS = (sbsel << 6 ) | (hbsel << 5 ) | fb ; -// SI4432_Write_Byte(SI4432_FREQBAND, FBS) ; -// SI4432_Write_Byte(SI4432_FREQBAND, 0x46) ; - // Register 0x76 Nominal Carrier Frequency - // WE USE 433.92 MHz - // Si443x-Register-Settings_RevB1.xls -// SI4432_Write_Byte(SI4432_FREQCARRIER_H, 0x62) ; -// SI4432_Write_Byte(SI4432_FREQCARRIER_H, 0x00) ; - // Register 0x77 Nominal Carrier Frequency -// SI4432_Write_Byte(SI4432_FREQCARRIER_L, 0x00) ; - // RX MODEM SETTINGS -// SI4432_Write_3_Byte(SI4432_IF_FILTER_BW, 0x81, 0x3C, 0x02) ; // <---------- -// SI4432_Write_Byte(SI4432_IF_FILTER_BW, 0x81) ; // <---------- - SI4432_Write_Byte(SI4432_AFC_LOOP_GEARSHIFT_OVERRIDE, 0x00) ; - SI4432_Write_Byte(SI4432_AFC_TIMING_CONTROL, 0x02) ; - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_GEARSHIFT, 0x03) ; -// SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_OVERSAMPLING, 0x78) ; // <---------- -// SI4432_Write_3_Byte(SI4432_CLOCK_RECOVERY_OFFSET2, 0x01, 0x11, 0x11) ; // <---------- - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_OFFSET2, 0x01) ; - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_OFFSET1, 0x11) ; - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_OFFSET0, 0x11) ; - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_TIMING_GAIN1, 0x01) ; - SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_TIMING_GAIN0, 0x13) ; - SI4432_Write_Byte(SI4432_AFC_LIMITER, 0xFF) ; - -// SI4432_Write_3_Byte(0x2C, 0x28, 0x0c, 0x28) ; // <---------- -// SI4432_Write_Byte(Si4432_OOK_COUNTER_VALUE_1, 0x28) ; -// SI4432_Write_Byte(Si4432_OOK_COUNTER_VALUE_2, 0x0C) ; -// SI4432_Write_Byte(Si4432_SLICER_PEAK_HOLD, 0x28) ; - - SI4432_Write_Byte(SI4432_DATAACCESS_CONTROL, 0x61); // Disable all packet handling - - SI4432_Write_Byte(SI4432_AGC_OVERRIDE, 0x60); // AGC, no LNA, fast gain increment - - -// GPIO automatic antenna switching - SI4432_Write_Byte(SI4432_GPIO0_CONF, 0x12) ; // Normal - SI4432_Write_Byte(SI4432_GPIO1_CONF, 0x15) ; +// set_rbw(100) ; // SI4432_Receive(); @@ -738,24 +694,6 @@ void SI4432_Init() SI4432_Sel = SI4432_LO; SI4432_Sub_Init(); //DebugLine("1 init done"); - - SI4432_Sel = SI4432_RX; -// SI4432_Receive();// Enable receiver chain -// SI4432_Write_Byte(Si4432_CRYSTAL_OSC_LOAD_CAP, V0_XTAL_CAPACITANCE);// Tune the crystal -// SI4432_Set_Frequency(433800000); - SI4432_Write_Byte(SI4432_GPIO2_CONF, 0x1F) ; // Set GPIO2 output to ground - - - SI4432_Sel = SI4432_LO; -// SI4432_Write_Byte(Si4432_CRYSTAL_OSC_LOAD_CAP, V1_XTAL_CAPACITANCE);// Tune the crystal -// SI4432_Set_Frequency(443800000); - SI4432_Write_Byte(SI4432_GPIO2_CONF, 0x1F) ; // Set GPIO2 output to ground - - // SI4432_Write_Byte(SI4432_TX_POWER, 0x1C);//Set low power -// SI4432_Transmit(0); - -// SI4432_Write_Byte(SI4432_GPIO2_CONF, 0xC0) ; // Set GPIO2 maximumdrive and clock output -// SI4432_Write_Byte(Si4432_UC_OUTPUT_CLOCK, 0x02) ; // Set 10MHz output } void set_calibration_freq(int freq) diff --git a/ui.c b/ui.c index 3feff6f..a8e9fee 100644 --- a/ui.c +++ b/ui.c @@ -311,8 +311,20 @@ touch_check(void) last_touch_x = x; last_touch_y = y; } +#ifdef __REMOTE_DESKTOP__ + mouse_down = false; + } + if (!stat) { + stat = mouse_down; + if (mouse_down) { + last_touch_x = mouse_x; + last_touch_y = mouse_y; + } + } +#else } -#if 0 // Long press detection +#endif + #if 0 // Long press detection systime_t ticks = chVTGetSystemTimeX(); if (stat && !last_touch_status) { // new button, initialize @@ -435,8 +447,13 @@ touch_draw_test(void) void touch_position(int *x, int *y) { +#ifdef __REMOTE_DESKTOP__ + *x = (mouse_down ? mouse_x : (last_touch_x - config.touch_cal[0]) * 16 / config.touch_cal[2]); + *y = (mouse_down ? mouse_y : (last_touch_y - config.touch_cal[1]) * 16 / config.touch_cal[3]); +#else *x = (last_touch_x - config.touch_cal[0]) * 16 / config.touch_cal[2]; *y = (last_touch_y - config.touch_cal[1]) * 16 / config.touch_cal[3]; +#endif } void @@ -2913,6 +2930,11 @@ void ui_process_touch(void) } static int previous_button_state = 0; +#ifdef __REMOTE_DESKTOP__ +static int previous_mouse_state = 0; +static int previous_mouse_x = 0; +static int previous_mouse_y = 0; +#endif void ui_process(void) @@ -2925,10 +2947,16 @@ ui_process(void) if (operation_requested&OP_LEVER || previous_button_state != button_state) { ui_process_lever(); previous_button_state = button_state; + operation_requested = OP_NONE; } - if (operation_requested&OP_TOUCH) + if (operation_requested&OP_TOUCH +#ifdef __REMOTE_DESKTOP__ + || previous_mouse_state != mouse_down || previous_mouse_x != mouse_x || previous_mouse_y != mouse_y +#endif + ) { ui_process_touch(); - operation_requested = OP_NONE; + operation_requested = OP_NONE; + } } /* Triggered when the button is pressed or released. The LED4 is set to ON.*/ diff --git a/ui_sa.c b/ui_sa.c index 6e90237..0d59fd4 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1327,6 +1327,23 @@ static UI_FUNCTION_ADV_CALLBACK(menu_pause_acb) // draw_cal_status(); } +#ifdef __REMOTE_DESKTOP__ +static UI_FUNCTION_ADV_CALLBACK(menu_send_display_acb) +{ + (void) data; + (void) item; + if (b){ + b->icon = auto_capture ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK; + return; + } + auto_capture = ! auto_capture; +// menu_move_back(); +// ui_mode_normal(); + draw_menu(); +// draw_cal_status(); +} +#endif + static UI_FUNCTION_ADV_CALLBACK(menu_outputmode_acb) { (void) data; @@ -1899,6 +1916,9 @@ static const menuitem_t menu_display[] = { { MT_ADV_CALLBACK,3, "NORMALIZE", menu_storage_acb}, { MT_ADV_CALLBACK,4, "WATER\nFALL", menu_waterfall_acb}, { MT_SUBMENU, 0, "SWEEP\nSETTINGS", menu_sweep_speed}, +#ifdef __REMOTE_DESKTOP__ + { MT_ADV_CALLBACK,0, "SEND\nDISPLAY", menu_send_display_acb}, +#endif // { MT_KEYPAD, KM_SWEEP_TIME, "SWEEP\nTIME", NULL}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, From 232494b66b51d638f870f7f0fef5839e4c074e5a Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Fri, 26 Feb 2021 17:47:30 +0100 Subject: [PATCH 9/9] Removed some floats --- ili9341.c | 2 ++ main.c | 8 +++++--- nanovna.h | 4 ++-- sa_cmd.c | 3 ++- sa_core.c | 55 ++++++++++++++++++++++++++----------------------------- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/ili9341.c b/ili9341.c index a22bee6..d2c1a95 100644 --- a/ili9341.c +++ b/ili9341.c @@ -23,6 +23,8 @@ #include "spi.h" + + // Allow enable DMA for read display data //#define __USE_DISPLAY_DMA_RX__ diff --git a/main.c b/main.c index b0903f0..e1eeaac 100644 --- a/main.c +++ b/main.c @@ -146,9 +146,11 @@ static THD_FUNCTION(Thread1, arg) // call from lowest level to save stack space self_test(setting.test); // sweep_mode = SWEEP_ENABLE; - } else if (sweep_mode & SWEEP_REMOTE) { +#ifdef __SINGLE_LETTER__ + } else if (sweep_mode & SWEEP_REMOTE) { sweep_remote(); - } else if (sweep_mode & SWEEP_CALIBRATE) { +#endif + } else if (sweep_mode & SWEEP_CALIBRATE) { // call from lowest level to save stack space calibrate(); sweep_mode = SWEEP_ENABLE; @@ -3021,7 +3023,7 @@ void HardFault_Handler(void) void hard_fault_handler_c(uint32_t *sp) { -#if 1 +#if 0 uint32_t r0 = sp[0]; uint32_t r1 = sp[1]; uint32_t r2 = sp[2]; diff --git a/nanovna.h b/nanovna.h index 63a6118..31dca08 100644 --- a/nanovna.h +++ b/nanovna.h @@ -51,9 +51,9 @@ #define __SPUR__ // Does spur reduction by shifting IF //#define __USE_SERIAL_CONSOLE__ // Enable serial I/O connection (need enable HAL_USE_SERIAL as TRUE in halconf.h) #define __SINGLE_LETTER__ -//#define __NICE_BIG_FONT__ +#define __NICE_BIG_FONT__ #define __QUASI_PEAK__ -#define __REMOTE_DESKTOP__ +//#define __REMOTE_DESKTOP__ #ifdef TINYSA3 #define DEFAULT_IF 433800000 diff --git a/sa_cmd.c b/sa_cmd.c index f2dc797..e17e06b 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -556,6 +556,8 @@ VNA_SHELL_FUNCTION(cmd_z) #endif +#ifdef __SINGLE_LETTER__ + void sweep_remote(void) { uint32_t i; @@ -582,7 +584,6 @@ void sweep_remote(void) sweep_mode = 0; } -#ifdef __SINGLE_LETTER__ VNA_SHELL_FUNCTION(cmd_m) { (void)argc; diff --git a/sa_core.c b/sa_core.c index 165912b..674a40f 100644 --- a/sa_core.c +++ b/sa_core.c @@ -2240,7 +2240,7 @@ sweep_again: // stay in sweep loop when output mo #endif if (check_for_AM) { - int AGC_value = (SI4432_Read_Byte(0x69) & 0x01f) * 3.0 - 90.0; + int AGC_value = (SI4432_Read_Byte(0x69) & 0x01f) * 3 - 90; if (AGC_value < last_AGC_value && last_AGC_direction_up ) { AGC_flip_count++; } else if (AGC_value > last_AGC_value && !last_AGC_direction_up ) { @@ -2496,7 +2496,7 @@ sweep_again: // stay in sweep loop when output mo if (!in_selftest && MODE_INPUT(setting.mode)) { #ifdef __SI4432__ if (S_IS_AUTO(setting.agc)) { - float actual_max_level = actual_t[max_index[0]] - get_attenuation(); + int actual_max_level = actual_t[max_index[0]] - get_attenuation(); // No need to use float if (UNIT_IS_LINEAR(setting.unit)) { // Auto AGC in linear mode if (actual_max_level > - 45) auto_set_AGC_LNA(false, 0); // Strong signal, no AGC and no LNA @@ -2674,10 +2674,11 @@ sweep_again: // stay in sweep loop when output mo } } else if (setting.measurement == M_AM) { // ----------------AM measurement if (S_IS_AUTO(setting.agc )) { - if (actual_t[max_index[0]] - get_attenuation() > -20 ) { + int actual_level = actual_t[max_index[0]] - get_attenuation(); // no need for float + if (actual_level > -20 ) { setting.agc = S_AUTO_OFF; setting.lna = S_AUTO_OFF; - } else if (actual_t[max_index[0]] - get_attenuation() < -45 ) { + } else if (actual_level < -45 ) { setting.agc = S_AUTO_ON; setting.lna = S_AUTO_ON; } else { @@ -2832,7 +2833,7 @@ int marker_search_max(void) return found; } -#define MINMAX_DELTA 10 +#define MINMAX_DELTA_X10 100 int @@ -2843,22 +2844,22 @@ marker_search_left_min(int from) if (uistat.current_trace == -1) return -1; - float value = actual_t[from]; + int value_x10 = actual_t[from]*10; for (i = from - 1; i >= 0; i--) { - float new_value = actual_t[i]; - if (new_value > value) { - value = new_value; // follow up + int new_value_x10 = actual_t[i]*10; + if (new_value_x10 > value_x10) { + value_x10 = new_value_x10; // follow up // found = i; - } else if (new_value < value - MINMAX_DELTA ) + } else if (new_value_x10 < value_x10 - MINMAX_DELTA_X10 ) break; // past the maximum } for (; i >= 0; i--) { - float new_value = actual_t[i]; - if (new_value < value) { - value = new_value; // follow down + int new_value_x10 = actual_t[i]*10; + if (new_value_x10 < value_x10) { + value_x10 = new_value_x10; // follow down found = i; - } else if (new_value > value + MINMAX_DELTA ) + } else if (new_value_x10 > value_x10 + MINMAX_DELTA_X10 ) break; } return found; @@ -2872,21 +2873,21 @@ marker_search_right_min(int from) if (uistat.current_trace == -1) return -1; - float value = actual_t[from]; + int value_x10 = actual_t[from]*10; for (i = from + 1; i < sweep_points; i++) { - float new_value = actual_t[i]; - if (new_value > value) { // follow up - value = new_value; + int new_value_x10 = actual_t[i]*10; + if (new_value_x10 > value_x10) { // follow up + value_x10 = new_value_x10; // found = i; - } else if (new_value < value - MINMAX_DELTA) // less then largest value - noise + } else if (new_value_x10 < value_x10 - MINMAX_DELTA_X10) // less then largest value_x10 - noise break; // past the maximum } for (; i < sweep_points; i++) { - float new_value = actual_t[i]; - if (new_value < value) { // follow down - value = new_value; + int new_value_x10 = actual_t[i]*10; + if (new_value_x10 < value_x10) { // follow down + value_x10 = new_value_x10; found = i; - } else if (new_value > value + MINMAX_DELTA) // larger then smallest value + noise + } else if (new_value_x10 > value_x10 + MINMAX_DELTA_X10) // larger then smallest value_x10 + noise break; } return found; @@ -3112,8 +3113,7 @@ int validate_atten(int i) { if (j == 0) reference_peak_level = summed_peak_level; else { -// shell_printf("Attenuation %.2fdB, measured level %.2fdBm, delta %.2fdB\n\r",((float)j)/2.0, summed_peak_level, summed_peak_level - reference_peak_level); - if (SDU1.config->usbp->state == USB_ACTIVE) shell_printf("Attenuation %.2fdB, measured level %.2fdBm, delta %.2fdB\n\r",a, summed_peak_level, summed_peak_level - reference_peak_level); +// if (SDU1.config->usbp->state == USB_ACTIVE) shell_printf("Attenuation %.2fdB, measured level %.2fdBm, delta %.2fdB\n\r",a, summed_peak_level, summed_peak_level - reference_peak_level); #define ATTEN_TEST_CRITERIA 1 if (summed_peak_level - reference_peak_level <= -ATTEN_TEST_CRITERIA || summed_peak_level - reference_peak_level >= ATTEN_TEST_CRITERIA) { status = TS_FAIL; @@ -3582,8 +3582,6 @@ void self_test(int test) set_sweep_frequency(ST_SPAN, 0); break; } - } -#endif } else if (test == 6) { in_selftest = true; // Spur search reset_settings(M_LOW); @@ -3598,9 +3596,8 @@ void self_test(int test) test_acquire(TEST_SPUR); // Acquire test shell_printf("%d: %9.3q\n\r",i, peakFreq); test_validate(TEST_SPUR); // Validate test - } - +#endif } show_test_info = FALSE;