mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
Add flag in config for sweep mode
#define FREQ_MODE_START_STOP 0x0 #define FREQ_MODE_CENTER_SPAN 0x1 Now sweep mode not defined from frequency0 > frequency1 or frequency0 < frequency1 frequency0 always < frequency1 All freq must get by use get_sweep_frequency(mode) Revert Select CH0 reflect channel before set freq, add additional delay on 0 sweep point
This commit is contained in:
parent
f9074149bb
commit
04fb661b1a
96
main.c
96
main.c
|
|
@ -718,6 +718,7 @@ config_t config = {
|
||||||
.trace_color = { DEFAULT_TRACE_1_COLOR, DEFAULT_TRACE_2_COLOR, DEFAULT_TRACE_3_COLOR, DEFAULT_TRACE_4_COLOR },
|
.trace_color = { DEFAULT_TRACE_1_COLOR, DEFAULT_TRACE_2_COLOR, DEFAULT_TRACE_3_COLOR, DEFAULT_TRACE_4_COLOR },
|
||||||
// .touch_cal = { 693, 605, 124, 171 }, // 2.4 inch LCD panel
|
// .touch_cal = { 693, 605, 124, 171 }, // 2.4 inch LCD panel
|
||||||
.touch_cal = { 338, 522, 153, 192 }, // 2.8 inch LCD panel
|
.touch_cal = { 338, 522, 153, 192 }, // 2.8 inch LCD panel
|
||||||
|
.freq_mode = FREQ_MODE_START_STOP,
|
||||||
.harmonic_freq_threshold = 300000000,
|
.harmonic_freq_threshold = 300000000,
|
||||||
.vbat_offset = 500
|
.vbat_offset = 500
|
||||||
};
|
};
|
||||||
|
|
@ -783,13 +784,11 @@ bool sweep(bool break_on_operation)
|
||||||
int i, delay;
|
int i, delay;
|
||||||
// blink LED while scanning
|
// blink LED while scanning
|
||||||
palClearPad(GPIOC, GPIOC_LED);
|
palClearPad(GPIOC, GPIOC_LED);
|
||||||
// Power stabilization after LED off, also align timings
|
// Power stabilization after LED off, also align timings on i == 0
|
||||||
// Also touch made some
|
|
||||||
DSP_START(1); DSP_WAIT_READY;
|
|
||||||
for (i = 0; i < sweep_points; i++) { // 5300
|
for (i = 0; i < sweep_points; i++) { // 5300
|
||||||
tlv320aic3204_select(0); // 60 CH0:REFLECT
|
|
||||||
delay = set_frequency(frequencies[i]); // 700
|
delay = set_frequency(frequencies[i]); // 700
|
||||||
DSP_START(delay); // 1900
|
tlv320aic3204_select(0); // 60 CH0:REFLECT, reset and begin measure
|
||||||
|
DSP_START(delay+((i==0)?1:0)); // 1900
|
||||||
//================================================
|
//================================================
|
||||||
// Place some code thats need execute while delay
|
// Place some code thats need execute while delay
|
||||||
//================================================
|
//================================================
|
||||||
|
|
@ -797,7 +796,7 @@ bool sweep(bool break_on_operation)
|
||||||
// calculate reflection coefficient
|
// calculate reflection coefficient
|
||||||
(*sample_func)(measured[0][i]); // 60
|
(*sample_func)(measured[0][i]); // 60
|
||||||
|
|
||||||
tlv320aic3204_select(1); // 60 CH1:TRANSMISSION
|
tlv320aic3204_select(1); // 60 CH1:TRANSMISSION, reset and begin measure
|
||||||
DSP_START(DELAY_CHANNEL_CHANGE); // 1700
|
DSP_START(DELAY_CHANNEL_CHANGE); // 1700
|
||||||
//================================================
|
//================================================
|
||||||
// Place some code thats need execute while delay
|
// Place some code thats need execute while delay
|
||||||
|
|
@ -913,13 +912,8 @@ void
|
||||||
update_frequencies(void)
|
update_frequencies(void)
|
||||||
{
|
{
|
||||||
uint32_t start, stop;
|
uint32_t start, stop;
|
||||||
if (frequency0 < frequency1) {
|
start = get_sweep_frequency(ST_START);
|
||||||
start = frequency0;
|
stop = get_sweep_frequency(ST_STOP);
|
||||||
stop = frequency1;
|
|
||||||
} else {
|
|
||||||
start = frequency1;
|
|
||||||
stop = frequency0;
|
|
||||||
}
|
|
||||||
|
|
||||||
set_frequencies(start, stop, sweep_points);
|
set_frequencies(start, stop, sweep_points);
|
||||||
// operation_requested|= OP_FREQCHANGE;
|
// operation_requested|= OP_FREQCHANGE;
|
||||||
|
|
@ -930,28 +924,6 @@ update_frequencies(void)
|
||||||
update_grid();
|
update_grid();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
freq_mode_startstop(void)
|
|
||||||
{
|
|
||||||
if (frequency0 > frequency1) {
|
|
||||||
ensure_edit_config();
|
|
||||||
uint32_t f = frequency1;
|
|
||||||
frequency1 = frequency0;
|
|
||||||
frequency0 = f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
freq_mode_centerspan(void)
|
|
||||||
{
|
|
||||||
if (frequency0 <= frequency1) {
|
|
||||||
ensure_edit_config();
|
|
||||||
uint32_t f = frequency1;
|
|
||||||
frequency1 = frequency0;
|
|
||||||
frequency0 = f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
set_sweep_frequency(int type, uint32_t freq)
|
set_sweep_frequency(int type, uint32_t freq)
|
||||||
{
|
{
|
||||||
|
|
@ -963,11 +935,11 @@ set_sweep_frequency(int type, uint32_t freq)
|
||||||
if (freq > STOP_MAX)
|
if (freq > STOP_MAX)
|
||||||
freq = STOP_MAX;
|
freq = STOP_MAX;
|
||||||
|
|
||||||
|
ensure_edit_config();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ST_START:
|
case ST_START:
|
||||||
freq_mode_startstop();
|
config.freq_mode&=~FREQ_MODE_CENTER_SPAN;
|
||||||
if (frequency0 != freq) {
|
if (frequency0 != freq) {
|
||||||
ensure_edit_config();
|
|
||||||
frequency0 = freq;
|
frequency0 = freq;
|
||||||
// if start > stop then make start = stop
|
// if start > stop then make start = stop
|
||||||
if (frequency1 < freq)
|
if (frequency1 < freq)
|
||||||
|
|
@ -975,9 +947,8 @@ set_sweep_frequency(int type, uint32_t freq)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ST_STOP:
|
case ST_STOP:
|
||||||
freq_mode_startstop();
|
config.freq_mode&=~FREQ_MODE_CENTER_SPAN;
|
||||||
if (frequency1 != freq) {
|
if (frequency1 != freq) {
|
||||||
ensure_edit_config();
|
|
||||||
frequency1 = freq;
|
frequency1 = freq;
|
||||||
// if start > stop then make start = stop
|
// if start > stop then make start = stop
|
||||||
if (frequency0 > freq)
|
if (frequency0 > freq)
|
||||||
|
|
@ -985,25 +956,23 @@ set_sweep_frequency(int type, uint32_t freq)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ST_CENTER:
|
case ST_CENTER:
|
||||||
freq_mode_centerspan();
|
config.freq_mode|=FREQ_MODE_CENTER_SPAN;
|
||||||
uint32_t center = FREQ_CENTER();
|
uint32_t center = frequency0/2 + frequency1/2;
|
||||||
if (center != freq) {
|
if (center != freq) {
|
||||||
uint32_t span = FREQ_SPAN();
|
uint32_t span = frequency1 - frequency0;
|
||||||
ensure_edit_config();
|
|
||||||
if (freq < START_MIN + span/2) {
|
if (freq < START_MIN + span/2) {
|
||||||
span = (freq - START_MIN) * 2;
|
span = (freq - START_MIN) * 2;
|
||||||
}
|
}
|
||||||
if (freq > STOP_MAX - span/2) {
|
if (freq > STOP_MAX - span/2) {
|
||||||
span = (STOP_MAX - freq) * 2;
|
span = (STOP_MAX - freq) * 2;
|
||||||
}
|
}
|
||||||
frequency0 = freq + span/2;
|
frequency0 = freq - span/2;
|
||||||
frequency1 = freq - span/2;
|
frequency1 = freq + span/2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ST_SPAN:
|
case ST_SPAN:
|
||||||
freq_mode_centerspan();
|
config.freq_mode|=FREQ_MODE_CENTER_SPAN;
|
||||||
if (frequency0 - frequency1 != freq) {
|
if (frequency1 - frequency0 != freq) {
|
||||||
ensure_edit_config();
|
|
||||||
uint32_t center = frequency0/2 + frequency1/2;
|
uint32_t center = frequency0/2 + frequency1/2;
|
||||||
if (center < START_MIN + freq/2) {
|
if (center < START_MIN + freq/2) {
|
||||||
center = START_MIN + freq/2;
|
center = START_MIN + freq/2;
|
||||||
|
|
@ -1011,14 +980,13 @@ set_sweep_frequency(int type, uint32_t freq)
|
||||||
if (center > STOP_MAX - freq/2) {
|
if (center > STOP_MAX - freq/2) {
|
||||||
center = STOP_MAX - freq/2;
|
center = STOP_MAX - freq/2;
|
||||||
}
|
}
|
||||||
frequency1 = center - freq/2;
|
frequency0 = center - freq/2;
|
||||||
frequency0 = center + freq/2;
|
frequency1 = center + freq/2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ST_CW:
|
case ST_CW:
|
||||||
freq_mode_centerspan();
|
config.freq_mode|=FREQ_MODE_CENTER_SPAN;
|
||||||
if (frequency0 != freq || frequency1 != freq) {
|
if (frequency0 != freq || frequency1 != freq) {
|
||||||
ensure_edit_config();
|
|
||||||
frequency0 = freq;
|
frequency0 = freq;
|
||||||
frequency1 = freq;
|
frequency1 = freq;
|
||||||
}
|
}
|
||||||
|
|
@ -1032,22 +1000,14 @@ set_sweep_frequency(int type, uint32_t freq)
|
||||||
uint32_t
|
uint32_t
|
||||||
get_sweep_frequency(int type)
|
get_sweep_frequency(int type)
|
||||||
{
|
{
|
||||||
if (frequency0 <= frequency1) {
|
// Obsolete, ensure correct start/stop, start always must be < stop
|
||||||
switch (type) {
|
if (frequency0>frequency1) {uint32_t t=frequency0; frequency0=frequency1; frequency1=t;}
|
||||||
case ST_START: return frequency0;
|
switch (type) {
|
||||||
case ST_STOP: return frequency1;
|
case ST_START: return frequency0;
|
||||||
|
case ST_STOP: return frequency1;
|
||||||
case ST_CENTER: return frequency0/2 + frequency1/2;
|
case ST_CENTER: return frequency0/2 + frequency1/2;
|
||||||
case ST_SPAN: return frequency1 - frequency0;
|
case ST_SPAN: return frequency1 - frequency0;
|
||||||
case ST_CW: return frequency0/2 + frequency1/2;
|
case ST_CW: return frequency0;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
switch (type) {
|
|
||||||
case ST_START: return frequency1;
|
|
||||||
case ST_STOP: return frequency0;
|
|
||||||
case ST_CENTER: return frequency0/2 + frequency1/2;
|
|
||||||
case ST_SPAN: return frequency0 - frequency1;
|
|
||||||
case ST_CW: return frequency0/2 + frequency1/2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1055,7 +1015,7 @@ get_sweep_frequency(int type)
|
||||||
VNA_SHELL_FUNCTION(cmd_sweep)
|
VNA_SHELL_FUNCTION(cmd_sweep)
|
||||||
{
|
{
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
shell_printf("%d %d %d\r\n", frequency0, frequency1, sweep_points);
|
shell_printf("%d %d %d\r\n", get_sweep_frequency(ST_START), get_sweep_frequency(ST_STOP), sweep_points);
|
||||||
return;
|
return;
|
||||||
} else if (argc > 3) {
|
} else if (argc > 3) {
|
||||||
goto usage;
|
goto usage;
|
||||||
|
|
|
||||||
15
nanovna.h
15
nanovna.h
|
|
@ -209,6 +209,9 @@ typedef struct trace {
|
||||||
float refpos;
|
float refpos;
|
||||||
} trace_t;
|
} trace_t;
|
||||||
|
|
||||||
|
#define FREQ_MODE_START_STOP 0x0
|
||||||
|
#define FREQ_MODE_CENTER_SPAN 0x1
|
||||||
|
|
||||||
typedef struct config {
|
typedef struct config {
|
||||||
int32_t magic;
|
int32_t magic;
|
||||||
uint16_t dac_value;
|
uint16_t dac_value;
|
||||||
|
|
@ -217,7 +220,7 @@ typedef struct config {
|
||||||
uint16_t menu_active_color;
|
uint16_t menu_active_color;
|
||||||
uint16_t trace_color[TRACES_MAX];
|
uint16_t trace_color[TRACES_MAX];
|
||||||
int16_t touch_cal[4];
|
int16_t touch_cal[4];
|
||||||
int8_t reserved_1;
|
int8_t freq_mode;
|
||||||
uint32_t harmonic_freq_threshold;
|
uint32_t harmonic_freq_threshold;
|
||||||
uint16_t vbat_offset;
|
uint16_t vbat_offset;
|
||||||
uint8_t _reserved[22];
|
uint8_t _reserved[22];
|
||||||
|
|
@ -226,8 +229,6 @@ typedef struct config {
|
||||||
|
|
||||||
extern config_t config;
|
extern config_t config;
|
||||||
|
|
||||||
//extern trace_t trace[TRACES_MAX];
|
|
||||||
|
|
||||||
void set_trace_type(int t, int type);
|
void set_trace_type(int t, int type);
|
||||||
void set_trace_channel(int t, int channel);
|
void set_trace_channel(int t, int channel);
|
||||||
void set_trace_scale(int t, float scale);
|
void set_trace_scale(int t, float scale);
|
||||||
|
|
@ -396,13 +397,9 @@ extern properties_t current_props;
|
||||||
#define velocity_factor current_props._velocity_factor
|
#define velocity_factor current_props._velocity_factor
|
||||||
#define marker_smith_format current_props._marker_smith_format
|
#define marker_smith_format current_props._marker_smith_format
|
||||||
|
|
||||||
#define FREQ_IS_STARTSTOP() (frequency0 < frequency1)
|
#define FREQ_IS_STARTSTOP() (!(config.freq_mode&FREQ_MODE_CENTER_SPAN))
|
||||||
#define FREQ_IS_CENTERSPAN() (frequency0 > frequency1)
|
#define FREQ_IS_CENTERSPAN() (config.freq_mode&FREQ_MODE_CENTER_SPAN)
|
||||||
#define FREQ_IS_CW() (frequency0 == frequency1)
|
#define FREQ_IS_CW() (frequency0 == frequency1)
|
||||||
#define FREQ_START() (frequency0)
|
|
||||||
#define FREQ_STOP() (frequency1)
|
|
||||||
#define FREQ_CENTER() (frequency0/2 + frequency1/2)
|
|
||||||
#define FREQ_SPAN() (frequency0 - frequency1)
|
|
||||||
|
|
||||||
int caldata_save(int id);
|
int caldata_save(int id);
|
||||||
int caldata_recall(int id);
|
int caldata_recall(int id);
|
||||||
|
|
|
||||||
22
plot.c
22
plot.c
|
|
@ -1585,18 +1585,18 @@ draw_frequencies(void)
|
||||||
char buf1[32];
|
char buf1[32];
|
||||||
char buf2[32];buf2[0]=0;
|
char buf2[32];buf2[0]=0;
|
||||||
if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) {
|
if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) {
|
||||||
if (FREQ_IS_STARTSTOP()) {
|
if (FREQ_IS_CW()){
|
||||||
plot_printf(buf1, sizeof(buf1), " START %qHz", frequency0);
|
plot_printf(buf1, sizeof(buf1), " CW %qHz", get_sweep_frequency(ST_CW));
|
||||||
plot_printf(buf2, sizeof(buf2), " STOP %qHz", frequency1);
|
} else if (FREQ_IS_STARTSTOP()) {
|
||||||
} else if (FREQ_IS_CENTERSPAN()) {
|
plot_printf(buf1, sizeof(buf1), " START %qHz", get_sweep_frequency(ST_START));
|
||||||
plot_printf(buf1, sizeof(buf1), " CENTER %qHz", FREQ_CENTER());
|
plot_printf(buf2, sizeof(buf2), " STOP %qHz", get_sweep_frequency(ST_STOP));
|
||||||
plot_printf(buf2, sizeof(buf2), " SPAN %qHz", FREQ_SPAN());
|
} else if (FREQ_IS_CENTERSPAN()) {
|
||||||
} else {
|
plot_printf(buf1, sizeof(buf1), " CENTER %qHz", get_sweep_frequency(ST_CENTER));
|
||||||
plot_printf(buf1, sizeof(buf1), " CW %qHz", frequency0);
|
plot_printf(buf2, sizeof(buf2), " SPAN %qHz", get_sweep_frequency(ST_SPAN));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
plot_printf(buf1, sizeof(buf1), " START 0s");
|
plot_printf(buf1, sizeof(buf1), " START 0s");
|
||||||
plot_printf(buf2, sizeof(buf2), "STOP %Fs (%Fm)", time_of_index(POINTS_COUNT-1), distance_of_index(POINTS_COUNT-1));
|
plot_printf(buf2, sizeof(buf2), "STOP %Fs (%Fm)", time_of_index(POINTS_COUNT-1), distance_of_index(POINTS_COUNT-1));
|
||||||
}
|
}
|
||||||
setForegroundColor(DEFAULT_FG_COLOR);
|
setForegroundColor(DEFAULT_FG_COLOR);
|
||||||
setBackgroundColor(DEFAULT_BG_COLOR);
|
setBackgroundColor(DEFAULT_BG_COLOR);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue