From 94fd6e083d624494f695a2cf292d2015cea3379a Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Fri, 5 Feb 2021 08:36:33 +0100 Subject: [PATCH] Power levels multiple SPI speeds --- nanovna.h | 11 +++++++++-- sa_cmd.c | 2 +- sa_core.c | 39 +++++++++++++++++++++------------------ si4432.c | 10 ++++++++-- ui.c | 10 +++++----- ui_sa.c | 11 +++++++---- 6 files changed, 51 insertions(+), 32 deletions(-) diff --git a/nanovna.h b/nanovna.h index fdaff7b..e6a959d 100644 --- a/nanovna.h +++ b/nanovna.h @@ -220,10 +220,16 @@ extern const char *info_about[]; #ifdef TINYSA4 #define SI_DRIVE_STEP 0.5 // Power step per step in drive level #define SWITCH_ATTENUATION 34 -#define POWER_OFFSET -18 // Max level with all enabled -#define POWER_RANGE 70 +//#define POWER_OFFSET -18 // Max level with all enabled +//#define POWER_RANGE 70 #define MAX_DRIVE 16 #define MIN_DRIVE 8 +#define SL_GENHIGH_LEVEL_MIN -15 +#define SL_GENHIGH_LEVEL_RANGE 9 +#define SL_GENLOW_LEVEL_MIN -88 +#define SL_GENLOW_LEVEL_RANGE 70 + + #else #define SI_DRIVE_STEP 3 #define SWITCH_ATTENUATION 30 @@ -1192,6 +1198,7 @@ extern void SI4463_do_api(void* data, uint8_t len, void* out, uint8_t outLen); extern void SI4463_set_gpio(int i, int s); extern void si_set_offset(int16_t offset); extern int SI4463_offset_changed; +extern void si_fm_offset(int16_t offset); /*EOF*/ diff --git a/sa_cmd.c b/sa_cmd.c index 82251c3..e4c2020 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -331,7 +331,7 @@ VNA_SHELL_FUNCTION(cmd_if1) return; } else { uint32_t a = (uint32_t)my_atoi(argv[0]); - if (a!= 0 &&( a < (DEFAULT_IF - (uint32_t)2000000) || a>(DEFAULT_IF + (uint32_t)2000000))) + if (a!= 0 &&( a < (DEFAULT_IF - (uint32_t)80000000) || a>(DEFAULT_IF + (uint32_t)80000000))) goto usage; config.frequency_IF1 = a; config_save(); diff --git a/sa_core.c b/sa_core.c index 49c4d6c..46b2a7f 100644 --- a/sa_core.c +++ b/sa_core.c @@ -116,7 +116,7 @@ void reset_settings(int m) setting.level_sweep = 0.0; // And this setting.rx_drive=MAX_DRIVE; // And this setting.atten_step = 0; // And this, only used in low output mode - setting.level = POWER_OFFSET; // This is the level with above settings. + setting.level = SL_GENLOW_LEVEL_MIN + SL_GENLOW_LEVEL_RANGE; // This is the level with above settings. setting.rbw_x10 = 0; setting.average = 0; setting.harmonic = 0; @@ -520,10 +520,7 @@ float get_attenuation(void) { float actual_attenuation = setting.attenuate_x2 / 2.0; if (setting.mode == M_GENLOW) { - if (setting.atten_step) - return (float)( POWER_OFFSET - actual_attenuation - (MAX_DRIVE - setting.rx_drive) * SI_DRIVE_STEP - SWITCH_ATTENUATION); - else - return (float)( POWER_OFFSET - actual_attenuation - (MAX_DRIVE - setting.rx_drive) * SI_DRIVE_STEP); + return (float)( SL_GENLOW_LEVEL_MIN + SL_GENLOW_LEVEL_RANGE - actual_attenuation - (MAX_DRIVE - setting.rx_drive) * SI_DRIVE_STEP - ( setting.atten_step ? SWITCH_ATTENUATION : 0) ); } else if (setting.atten_step) { if (setting.mode == M_LOW) return actual_attenuation + RECEIVE_SWITCH_ATTENUATION; @@ -543,17 +540,18 @@ static pureRSSI_t get_signal_path_loss(void){ return float_TO_PURE_RSSI(+19); // Loss in dB (+ is gain) } -static const int drive_dBm [16] = {-38,-35,-33,-30,-27,-24,-21,-19,-7,-4,-2, 1, 4, 7, 10, 13}; +static const int drive_dBm [] = {-15,-12,-9,-6}; + void set_level(float v) // Set the output level in dB in high/low output { if (setting.mode == M_GENHIGH) { -// int d = 0; -// while (drive_dBm[d] < v - 1 && d < 16) -// d++; + int d = 0; + while (drive_dBm[d] < v - 1 && (unsigned int)d < (sizeof(drive_dBm)/sizeof(int))-1 ) + d++; // if (d == 8 && v < -12) // Round towards closest level // d = 7; - set_lo_drive(v); + set_lo_drive(d); } else { setting.level = v; set_attenuation((int)v); @@ -572,7 +570,7 @@ float get_level(void) void set_attenuation(float a) // Is used both in low output mode and high/low input mode { if (setting.mode == M_GENLOW) { - a = a - POWER_OFFSET; // Move to zero for max power + a = a - (SL_GENLOW_LEVEL_MIN + SL_GENLOW_LEVEL_RANGE); // Move to zero for max power if (a > 0) a = 0; if( a < - SWITCH_ATTENUATION) { @@ -1011,9 +1009,9 @@ void set_offset(float offset) setting.offset = offset; int min,max; if (setting.mode == M_GENLOW) { - min = POWER_OFFSET - POWER_RANGE; max = POWER_OFFSET; + min = SL_GENLOW_LEVEL_MIN; max = SL_GENLOW_LEVEL_MIN + SL_GENLOW_LEVEL_RANGE; } else { - min = -38; max = +13; + min = SL_GENHIGH_LEVEL_MIN; max = SL_GENHIGH_LEVEL_MIN + SL_GENHIGH_LEVEL_RANGE; } plot_printf(low_level_help_text, sizeof low_level_help_text, "%+d..%+d", min + (int)offset, max + (int)offset); force_set_markmap(); @@ -1562,7 +1560,7 @@ case M_GENHIGH: // Direct output from 1 if (high_out_adf4350) { #ifdef __SI4468__ SI4463_init_rx(); - enable_rx_output(true); // to protext the SI + enable_rx_output(true); // to protect the SI #endif ADF4351_enable(true); #ifndef TINYSA4_PROTO @@ -1979,7 +1977,7 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) a += PURE_TO_float(get_frequency_correction(f)); if (a != old_a) { old_a = a; - a = a - POWER_OFFSET; // convert to all settings maximum power output equals a = zero + a = a - (SL_GENLOW_LEVEL_MIN + SL_GENLOW_LEVEL_RANGE); // convert to all settings maximum power output equals a = zero if (a < -SWITCH_ATTENUATION) { a = a + SWITCH_ATTENUATION; @@ -2138,8 +2136,8 @@ modulation_again: local_IF = lf; lf = 0; #else - local_IF += lf - reffer_freq[setting.refer]; // Offset so fundamental of reffer is visible - lf = reffer_freq[setting.refer]; + local_IF += lf - (setting.refer == -1 ? 0 : reffer_freq[setting.refer]); // Offset so fundamental of reffer is visible + lf = (setting.refer == -1 ? 0 : reffer_freq[setting.refer]); #endif } else { #ifdef __SI4468__ @@ -3104,7 +3102,7 @@ sweep_again: // stay in sweep loop when output mo markers[2].frequency = frequencies[markers[2].index]; } else if ((setting.measurement == M_PASS_BAND || setting.measurement == M_FM) && markers[0].index > 10) { // ----------------Pass band measurement int t = 0; - float v = actual_t[markers[0].index] - 3.0; + float v = actual_t[markers[0].index] - (in_selftest ? 6.0 : 3.0); while (t < markers[0].index && actual_t[t+1] < v) // Find left -3dB point t++; if (t< markers[0].index) { @@ -3681,6 +3679,11 @@ common_silent: setting.auto_IF = false; setting.frequency_IF = config.frequency_IF1+1000000; // Center on SAW filters set_refer_output(0); + 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); diff --git a/si4432.c b/si4432.c index 2caca9a..85b5c55 100644 --- a/si4432.c +++ b/si4432.c @@ -51,6 +51,8 @@ //#define ADF_SPI_SPEED SPI_BR_DIV32 #define ADF_SPI_SPEED SPI_BR_DIV4 +#define PE_SPI_SPEED SPI_BR_DIV32 + static uint32_t old_spi_settings; #else static uint32_t old_port_moder; @@ -902,12 +904,16 @@ bool PE4302_Write_Byte(unsigned char DATA ) // my_microsecond_delay(PE4302_DELAY); // PE4302_shiftOut(DATA); + set_SPI_mode(SPI_MODE_SI); + SPI_BR_SET(SI4432_SPI, PE_SPI_SPEED); + shiftOut(DATA); // my_microsecond_delay(PE4302_DELAY); CS_PE_HIGH; // my_microsecond_delay(PE4302_DELAY); CS_PE_LOW; // my_microsecond_delay(PE4302_DELAY); + SPI_BR_SET(SI4432_SPI, SI4432_SPI_SPEED); return true; } @@ -1390,7 +1396,7 @@ static int SI4463_wait_for_cts(void) return 1; } - +#if 0 // not used static void SI4463_write_byte(uint8_t ADR, uint8_t DATA) { set_SPI_mode(SPI_MODE_SI); @@ -1411,7 +1417,7 @@ static void SI4463_write_buffer(uint8_t ADR, uint8_t *DATA, int len) shiftOut( *(DATA++) ); SI_CS_HIGH; } - +#endif static uint8_t SI4463_read_byte( uint8_t ADR ) { diff --git a/ui.c b/ui.c index 7b43276..2768698 100644 --- a/ui.c +++ b/ui.c @@ -1883,7 +1883,7 @@ draw_menu_buttons(const menuitem_t *menu) } goto draw_divider; } else if (menu[i].data == KM_LOWOUTLEVEL) { - local_slider_positions = ((get_attenuation() - POWER_OFFSET + POWER_RANGE ) * (MENU_FORM_WIDTH-8)) / POWER_RANGE + OFFSETX+4; + local_slider_positions = ((get_level() - SL_GENLOW_LEVEL_MIN ) * (MENU_FORM_WIDTH-8)) / SL_GENLOW_LEVEL_RANGE + OFFSETX+4; for (int i=0; i <= 4; i++) { ili9341_drawstring(step_text[i], button_start+12 + i * MENU_FORM_WIDTH/5, y+button_height-9); } @@ -1894,7 +1894,7 @@ draw_menu_buttons(const menuitem_t *menu) draw_slider: blit8BitWidthBitmap(local_slider_positions - 4, y, 7, 5, slider_bitmap); } else if (menu[i].data == KM_HIGHOUTLEVEL) { - local_slider_positions = ((menu_drive_value[setting.lo_drive] + 38 ) * (MENU_FORM_WIDTH-8)) / 51 + OFFSETX+4; + local_slider_positions = ((get_level() - SL_GENHIGH_LEVEL_MIN ) * (MENU_FORM_WIDTH-8)) / SL_GENHIGH_LEVEL_RANGE + OFFSETX+4; goto draw_slider; } } @@ -2060,7 +2060,7 @@ menu_select_touch(int i, int pos) check_frequency_slider(slider_freq); } } else if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD && keypad == KM_LOWOUTLEVEL) { - uistat.value = setting.offset + (touch_x - OFFSETX+4) *( POWER_RANGE) / (MENU_FORM_WIDTH-8) + POWER_OFFSET - POWER_RANGE; + uistat.value = setting.offset + ((touch_x - OFFSETX+4) * SL_GENLOW_LEVEL_RANGE ) / (MENU_FORM_WIDTH-8) + SL_GENLOW_LEVEL_MIN; apply_step: set_keypad_value(keypad); apply: @@ -2069,7 +2069,7 @@ menu_select_touch(int i, int pos) // } // } else if (MT_MASK(menu[i].type) == MT_ADV_CALLBACK && menu[i].reference == menu_sdrive_acb) { } else if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD && keypad == KM_HIGHOUTLEVEL) { - set_level( (touch_x - OFFSETX+4) *( 13 - -38) / (MENU_FORM_WIDTH-8) + -38 ); + set_level( (touch_x - OFFSETX+4) *(SL_GENHIGH_LEVEL_RANGE) / (MENU_FORM_WIDTH-8) + SL_GENHIGH_LEVEL_MIN ); goto apply; } keypad_mode = old_keypad_mode; @@ -2119,7 +2119,7 @@ menu_select_touch(int i, int pos) step = setting.slider_span; break; } - if (step < 0 && get_sweep_frequency(ST_CENTER) < -step) + if (step < 0 && get_sweep_frequency(ST_CENTER) < (unsigned int)-step) uistat.value = 0; else uistat.value = get_sweep_frequency(ST_CENTER) + step; diff --git a/ui_sa.c b/ui_sa.c index 302ba75..2d36ea2 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -461,6 +461,9 @@ static const struct { {keypads_freq , "ULTRA\nSTART"}, // KM_LPF }; #if 0 // Not used + +enum { SL_GENLOW_FREQ, SL_GENHIGH_FREQ, SL_GENLOW_LEVEL, SL_GENHIGH_LEVEL }; + ui_slider_t ui_sliders [] = { { KM_CENTER, true, 0, 1000000, 0, 350000000, M_GENLOW}, @@ -2251,10 +2254,10 @@ static void fetch_numeric_target(void) case KM_LOWOUTLEVEL: uistat.value = get_level(); // compensation for dB offset during low output mode int end_level = ((int32_t)uistat.value)+setting.level_sweep; - if (end_level < POWER_OFFSET - 70) - end_level = POWER_OFFSET - 70; - if (end_level > POWER_OFFSET) - end_level = POWER_OFFSET; + if (end_level < SL_GENLOW_LEVEL_MIN) + end_level = SL_GENLOW_LEVEL_MIN; + if (end_level > SL_GENLOW_LEVEL_MIN + SL_GENLOW_LEVEL_RANGE) + end_level = SL_GENLOW_LEVEL_MIN + SL_GENLOW_LEVEL_RANGE; uistat.value += setting.offset; end_level += setting.offset; if (setting.level_sweep != 0)