From 4e38aa6516314700efecce6911700412085b9908 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Tue, 29 Oct 2024 20:07:25 +0300 Subject: [PATCH] Ass SWC5351 generator support Restore I2C read command Fix 'measure' command Little faster interpolation --- main.c | 38 +++++++++++++++++++++++--------------- nanovna.h | 2 +- si5351.c | 45 +++++++++++++++++++++++++++++++++++++-------- si5351.h | 1 + ui.c | 9 +++++++-- 5 files changed, 69 insertions(+), 26 deletions(-) diff --git a/main.c b/main.c index 31108834..55a28dcf 100644 --- a/main.c +++ b/main.c @@ -125,7 +125,7 @@ static uint16_t p_sweep = 0; float measured[2][SWEEP_POINTS_MAX][2]; #undef VERSION -#define VERSION "1.2.40" +#define VERSION "1.2.42" // Version text, displayed in Config->Version menu, also send by info command const char *info_about[]={ @@ -590,6 +590,7 @@ VNA_SHELL_FUNCTION(cmd_config) { "|lcshunt" // Enable LC shunt measure option "|lcseries" // Enable LC series measure option "|xtal" // Enable XTAL measure option + "|filter" // Enable filter measure option #endif #ifdef __S11_CABLE_MEASURE__ "|cable" // Enable S11 cable measure option @@ -990,9 +991,10 @@ static void load_settings(void) { lever_mode = bk.leveler; config._vna_mode = get_backup_data32(4) | (1<= src_points) goto copy_point; // point limit idx++; - k1-= 1.0f; + k-= 1.0f; } } - // Interpolate by k1 - float k0 = 1.0f - k1; + // Interpolate by k for (eterm = 0; eterm < CAL_TYPE_COUNT; eterm++) { - data[eterm][0] = cal_data[eterm][idx][0] * k0 + cal_data[eterm][idx+1][0] * k1; - data[eterm][1] = cal_data[eterm][idx][1] * k0 + cal_data[eterm][idx+1][1] * k1; + data[eterm][0] = cal_data[eterm][idx][0] + k * (cal_data[eterm][idx+1][0] - cal_data[eterm][idx][0]); + data[eterm][1] = cal_data[eterm][idx][1] + k * (cal_data[eterm][idx+1][1] - cal_data[eterm][idx][0]); } return; // Direct point copy @@ -2589,6 +2590,13 @@ VNA_SHELL_FUNCTION(cmd_si5351time) #ifdef ENABLE_SI5351_REG_WRITE VNA_SHELL_FUNCTION(cmd_si5351reg) { +#if 0 + (void) argc; + uint32_t reg = my_atoui(argv[0]); + uint8_t buf[1] = {0xAA}; + if (si5351_bulk_read(reg, buf, 1)) + shell_printf("si reg[%d] = 0x%02x" VNA_SHELL_NEWLINE_STR, reg, buf[0]); +#else if (argc != 2) { shell_printf("usage: si reg data" VNA_SHELL_NEWLINE_STR); return; @@ -2597,6 +2605,7 @@ VNA_SHELL_FUNCTION(cmd_si5351reg) uint8_t dat = my_atoui(argv[1]); uint8_t buf[] = { reg, dat }; si5351_bulk_write(buf, 2); +#endif } #endif @@ -3450,8 +3459,7 @@ void hard_fault_handler_c(uint32_t *sp) uint32_t psr = sp[7]; int y = 0; int x = 20; - lcd_set_background(LCD_BG_COLOR); - lcd_set_foreground(LCD_FG_COLOR); + lcd_set_colors(LCD_FG_COLOR, LCD_BG_COLOR); lcd_printf(x, y+=FONT_STR_HEIGHT, "SP 0x%08x", (uint32_t)sp); lcd_printf(x, y+=FONT_STR_HEIGHT, "R0 0x%08x", r0); lcd_printf(x, y+=FONT_STR_HEIGHT, "R1 0x%08x", r1); diff --git a/nanovna.h b/nanovna.h index aab04eb9..c1efc398 100644 --- a/nanovna.h +++ b/nanovna.h @@ -171,7 +171,7 @@ * main.c */ // Minimum frequency set -#define FREQUENCY_MIN 800 +#define FREQUENCY_MIN 600 // Maximum frequency set #define FREQUENCY_MAX 2700000000U // Frequency threshold (max frequency for si5351, harmonic mode after) diff --git a/si5351.c b/si5351.c index 53e49259..a02176c7 100644 --- a/si5351.c +++ b/si5351.c @@ -98,14 +98,12 @@ void si5351_bulk_write(const uint8_t *buf, int len) } #if 0 -static bool si5351_bulk_read(uint8_t reg, uint8_t* buf, int len) -{ - i2cAcquireBus(&I2CD1); - msg_t mr = i2cMasterTransmitTimeout(&I2CD1, SI5351_I2C_ADDR, ®, 1, buf, len, 1000); - i2cReleaseBus(&I2CD1); - return mr == MSG_OK; +bool si5351_bulk_read(uint8_t reg, uint8_t* buf, int len) { + return i2c_receive(SI5351_I2C_ADDR, ®, 1, buf, len); } +#endif +#if 0 static void si5351_wait_pll_lock(void) { uint8_t status; @@ -491,12 +489,43 @@ CONST_BAND band_strategy_t band_strategy_36H_MS5351[] = { { 11, SI5351_FIXED_MULT,{ 4},11,13, SI5351_CLK_DRIVE_STRENGTH_8MA, SI5351_CLK_DRIVE_STRENGTH_8MA, 95, 95, 11*12*4} // 10}; }; +// Mode for board v3.6+ and SWC5351 installed +CONST_BAND band_strategy_t band_strategy_SWC5351[] = { + { 0U, 0, { 0}, 0, 0, -1, -1, -1, -1, 1}, // 0 + { 26000U, SI5351_FIXED_PLL, { 6}, 1, 1, SI5351_CLK_DRIVE_STRENGTH_2MA, SI5351_CLK_DRIVE_STRENGTH_2MA, 0, 0, 1}, // 1 + { 120000000U, SI5351_FIXED_PLL, {32}, 1, 1, SI5351_CLK_DRIVE_STRENGTH_4MA, SI5351_CLK_DRIVE_STRENGTH_2MA, 0, 0, 1}, // 2 + + { 150000000U, SI5351_FIXED_MULT,{ 8}, 1, 1, SI5351_CLK_DRIVE_STRENGTH_6MA, SI5351_CLK_DRIVE_STRENGTH_4MA, 0, 0, 1}, // 3 + + { 200000000U, SI5351_FIXED_MULT,{ 6}, 1, 1, SI5351_CLK_DRIVE_STRENGTH_6MA, SI5351_CLK_DRIVE_STRENGTH_4MA, 0, 0, 1}, // 4 + { 1, SI5351_FIXED_MULT,{ 4}, 1, 1, SI5351_CLK_DRIVE_STRENGTH_6MA, SI5351_CLK_DRIVE_STRENGTH_4MA, 0, 0, 1}, // 5 + + { 460000000U, SI5351_FIXED_MULT,{ 8}, 3, 5, SI5351_CLK_DRIVE_STRENGTH_6MA, SI5351_CLK_DRIVE_STRENGTH_4MA, 40, 40, 3*5*8}, // 6 + { 600000000U, SI5351_FIXED_MULT,{ 6}, 3, 5, SI5351_CLK_DRIVE_STRENGTH_8MA, SI5351_CLK_DRIVE_STRENGTH_4MA, 40, 40, 3*5*6}, // 7 + { 3, SI5351_FIXED_MULT,{ 4}, 3, 5, SI5351_CLK_DRIVE_STRENGTH_8MA, SI5351_CLK_DRIVE_STRENGTH_4MA, 50, 50, 3*5*4}, // 8 + + { 1000000000U, SI5351_FIXED_MULT,{ 6}, 5, 7, SI5351_CLK_DRIVE_STRENGTH_8MA, SI5351_CLK_DRIVE_STRENGTH_6MA, 70, 70, 5*7*6}, // 9 + { 5, SI5351_FIXED_MULT,{ 4}, 5, 7, SI5351_CLK_DRIVE_STRENGTH_8MA, SI5351_CLK_DRIVE_STRENGTH_6MA, 70, 70, 5*7*4}, //10 + + { 1800000000U, SI5351_FIXED_MULT,{ 4}, 7, 9, SI5351_CLK_DRIVE_STRENGTH_8MA, SI5351_CLK_DRIVE_STRENGTH_8MA, 70, 70, 7*9*4}, //11 + { 7, SI5351_FIXED_MULT,{ 4}, 7, 9, SI5351_CLK_DRIVE_STRENGTH_8MA, SI5351_CLK_DRIVE_STRENGTH_8MA, 70, 70, 7*9*4}, //12 + + { 2400000000U, SI5351_FIXED_MULT,{ 4}, 9,11, SI5351_CLK_DRIVE_STRENGTH_8MA, SI5351_CLK_DRIVE_STRENGTH_8MA, 85, 85, 9*11*4}, //13 + { 9, SI5351_FIXED_MULT,{ 4}, 9,11, SI5351_CLK_DRIVE_STRENGTH_8MA, SI5351_CLK_DRIVE_STRENGTH_8MA, 95, 95, 9*11*4}, //14 + + { 11, SI5351_FIXED_MULT,{ 4},11,12, SI5351_CLK_DRIVE_STRENGTH_8MA, SI5351_CLK_DRIVE_STRENGTH_8MA, 95, 95, 11*12*4} //15 + +}; + void si5351_set_band_mode(uint16_t t) { + static const band_strategy_t *bs[] = { #if defined(NANOVNA_F303) - band_s = t ? band_strategy_36H_MS5351 : band_strategy_H4_SI5351; // !!!! no test MS5351 on H4 board + band_strategy_H4_SI5351, band_strategy_36H_MS5351, band_strategy_SWC5351 #else - band_s = t ? band_strategy_36H_MS5351 : band_strategy_33H_SI5351; + band_strategy_33H_SI5351, band_strategy_36H_MS5351, band_strategy_SWC5351 #endif + }; + band_s = bs[t]; } uint32_t diff --git a/si5351.h b/si5351.h index 8758d352..4a62c1f7 100644 --- a/si5351.h +++ b/si5351.h @@ -83,6 +83,7 @@ void si5351_set_band_mode(uint16_t t); // Defug use functions void si5351_bulk_write(const uint8_t *buf, int len); +bool si5351_bulk_read(uint8_t reg, uint8_t* buf, int len); void si5351_set_timing(int i, int v); void si5351_update_band_config(int idx, uint32_t pidx, uint32_t v); void si5351_set_tcxo(uint32_t xtal); diff --git a/ui.c b/ui.c index 1db4cb95..9a71fbab 100644 --- a/ui.c +++ b/ui.c @@ -1892,11 +1892,16 @@ static UI_FUNCTION_CALLBACK(menu_sdcard_cb) { static UI_FUNCTION_ADV_CALLBACK(menu_band_sel_acb) { (void)data; + static const char* gen_names[] = { + "Si5351", + "MS5351", + "SWC5351" + }; if (b) { - b->p1.text = config._band_mode == 0 ? "Si5351" : "MS5351"; + b->p1.text = gen_names[config._band_mode]; return; } - config._band_mode = config._band_mode == 0 ? 1 : 0; + if (++config._band_mode >= ARRAY_COUNT(gen_names)) config._band_mode = 0; si5351_set_band_mode(config._band_mode); }