From 94659a22ba90955a8eb82657bceaff6daa7a96c6 Mon Sep 17 00:00:00 2001 From: TT Date: Sat, 5 Oct 2019 19:56:38 +0900 Subject: [PATCH] feat: add threshold command --- main.c | 36 +++++++++++++++++++++++++----------- nanovna.h | 1 + si5351.c | 5 +++-- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/main.c b/main.c index 58e4c46..e4f281e 100644 --- a/main.c +++ b/main.c @@ -43,7 +43,8 @@ bool sweep(bool break_on_operation); static MUTEX_DECL(mutex); #define DRIVE_STRENGTH_AUTO (-1) -#define FREQ_HARMONICS 300000000 +//#define FREQ_HARMONICS 300000000 +#define FREQ_HARMONICS (config.harmonic_freq_threshold) int32_t frequency_offset = 5000; int32_t frequency = 10000000; @@ -354,6 +355,18 @@ static void cmd_dac(BaseSequentialStream *chp, int argc, char *argv[]) dacPutChannelX(&DACD2, 0, value); } +static void cmd_threshold(BaseSequentialStream *chp, int argc, char *argv[]) +{ + int value; + if (argc != 1) { + chprintf(chp, "usage: threshold {frequency in harmonic mode}\r\n"); + chprintf(chp, "current: %d\r\n", config.harmonic_freq_threshold); + return; + } + value = atoi(argv[0]); + config.harmonic_freq_threshold = value; +} + static void cmd_saveconfig(BaseSequentialStream *chp, int argc, char *argv[]) { (void)argc; @@ -590,16 +603,16 @@ float cal_data[5][101][2]; #endif config_t config = { - /* magic */ CONFIG_MAGIC, - /* dac_value */ 1922, - /* grid_color */ 0x1084, - /* menu_normal_color */ 0xffff, - /* menu_active_color */ 0x7777, - /* trace_colors[4] */ { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) }, - ///* touch_cal[4] */ { 620, 600, 160, 190 }, - /* touch_cal[4] */ { 693, 605, 124, 171 }, - /* default_loadcal */ 0, - /* checksum */ 0 + .magic = CONFIG_MAGIC, + .dac_value = 1922, + .grid_color = 0x1084, + .menu_normal_color = 0xffff, + .menu_active_color = 0x7777, + .trace_color = { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) }, + .touch_cal = { 693, 605, 124, 171 }, //{ 620, 600, 160, 190 }, + .default_loadcal = 0, + .harmonic_freq_threshold = 300000000, + .checksum = 0 }; properties_t current_props = { @@ -1981,6 +1994,7 @@ static const ShellCommand commands[] = { "capture", cmd_capture }, { "vbat", cmd_vbat }, { "transform", cmd_transform }, + { "threshold", cmd_threshold }, { NULL, NULL } }; diff --git a/nanovna.h b/nanovna.h index ef4425c..19dcc92 100644 --- a/nanovna.h +++ b/nanovna.h @@ -195,6 +195,7 @@ typedef struct { uint16_t trace_color[TRACES_MAX]; int16_t touch_cal[4]; int8_t default_loadcal; + int32_t harmonic_freq_threshold; int32_t checksum; } config_t; diff --git a/si5351.c b/si5351.c index ebd4aa9..9dae5c2 100644 --- a/si5351.c +++ b/si5351.c @@ -18,6 +18,7 @@ * Boston, MA 02110-1301, USA. */ #include "hal.h" +#include "nanovna.h" #include "si5351.h" #define SI5351_I2C_ADDR (0x60<<1) @@ -309,10 +310,10 @@ si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength) int delay = 3; uint32_t ofreq = freq + offset; uint32_t rdiv = SI5351_R_DIV_1; - if (freq > 900000000) { + if (freq > config.harmonic_freq_threshold * 3) { freq /= 5; ofreq /= 7; - } else if (freq > 300000000) { + } else if (freq > config.harmonic_freq_threshold) { freq /= 3; ofreq /= 5; }