mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
support electrical delay
This commit is contained in:
parent
5a441edc6b
commit
5d1934d85f
45
main.c
45
main.c
|
|
@ -387,12 +387,13 @@ config_t config = {
|
||||||
|
|
||||||
properties_t current_props = {
|
properties_t current_props = {
|
||||||
/* magic */ CONFIG_MAGIC,
|
/* magic */ CONFIG_MAGIC,
|
||||||
/* frequency0 */ 1000000,
|
/* frequency0 */ 50000, // start = 50kHz
|
||||||
/* frequency1 */ 300000000,
|
/* frequency1 */ 300000000, // end = 300MHz
|
||||||
/* sweep_points */ 101,
|
/* sweep_points */ 101,
|
||||||
/* cal_status */ 0,
|
/* cal_status */ 0,
|
||||||
/* frequencies */ {},
|
/* frequencies */ {},
|
||||||
/* cal_data */ {},
|
/* cal_data */ {},
|
||||||
|
/* electrical_delay */ 0,
|
||||||
/* trace[4] */
|
/* trace[4] */
|
||||||
{/*enable, type, channel, polar, scale*/
|
{/*enable, type, channel, polar, scale*/
|
||||||
{ 1, TRC_LOGMAG, 0, 0, 1.0, 7.0 },
|
{ 1, TRC_LOGMAG, 0, 0, 1.0, 7.0 },
|
||||||
|
|
@ -482,6 +483,9 @@ void sweep(void)
|
||||||
if (cal_status & CALSTAT_APPLY)
|
if (cal_status & CALSTAT_APPLY)
|
||||||
apply_error_term_at(i);
|
apply_error_term_at(i);
|
||||||
|
|
||||||
|
if (electrical_delay != 0)
|
||||||
|
apply_edelay_at(i);
|
||||||
|
|
||||||
redraw_requested = FALSE;
|
redraw_requested = FALSE;
|
||||||
ui_process();
|
ui_process();
|
||||||
if (redraw_requested)
|
if (redraw_requested)
|
||||||
|
|
@ -903,6 +907,21 @@ void apply_error_term_at(int i)
|
||||||
measured[1][i][1] = s21ai;
|
measured[1][i][1] = s21ai;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void apply_edelay_at(int i)
|
||||||
|
{
|
||||||
|
float w = 2 * M_PI * electrical_delay * frequencies[i] * 1E-12;
|
||||||
|
float s = sin(w);
|
||||||
|
float c = cos(w);
|
||||||
|
float real = measured[0][i][0];
|
||||||
|
float imag = measured[0][i][1];
|
||||||
|
measured[0][i][0] = real * c - imag * s;
|
||||||
|
measured[0][i][1] = imag * c + real * s;
|
||||||
|
real = measured[1][i][0];
|
||||||
|
imag = measured[1][i][1];
|
||||||
|
measured[1][i][0] = real * c - imag * s;
|
||||||
|
measured[1][i][1] = imag * c + real * s;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cal_collect(int type)
|
cal_collect(int type)
|
||||||
{
|
{
|
||||||
|
|
@ -1315,6 +1334,27 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
chprintf(chp, "trace {0|1|2|3|all} [logmag|phase|smith|linear|delay|swr|off] [src]\r\n");
|
chprintf(chp, "trace {0|1|2|3|all} [logmag|phase|smith|linear|delay|swr|off] [src]\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void set_electrical_delay(float picoseconds)
|
||||||
|
{
|
||||||
|
if (electrical_delay != picoseconds) {
|
||||||
|
electrical_delay = picoseconds;
|
||||||
|
force_set_markmap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cmd_edelay(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if (argc == 0) {
|
||||||
|
chprintf(chp, "%f\r\n", electrical_delay);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (argc > 0) {
|
||||||
|
set_electrical_delay(my_atof(argv[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cmd_marker(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_marker(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int t;
|
int t;
|
||||||
|
|
@ -1563,6 +1603,7 @@ static const ShellCommand commands[] =
|
||||||
{ "recall", cmd_recall },
|
{ "recall", cmd_recall },
|
||||||
{ "trace", cmd_trace },
|
{ "trace", cmd_trace },
|
||||||
{ "marker", cmd_marker },
|
{ "marker", cmd_marker },
|
||||||
|
{ "edelay", cmd_edelay },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -192,6 +192,8 @@ void set_trace_channel(int t, int channel);
|
||||||
void set_trace_scale(int t, float scale);
|
void set_trace_scale(int t, float scale);
|
||||||
void set_trace_refpos(int t, float refpos);
|
void set_trace_refpos(int t, float refpos);
|
||||||
|
|
||||||
|
void set_electrical_delay(float picoseconds);
|
||||||
|
|
||||||
// marker
|
// marker
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
@ -264,7 +266,8 @@ typedef struct {
|
||||||
|
|
||||||
uint32_t _frequencies[101];
|
uint32_t _frequencies[101];
|
||||||
float _cal_data[5][101][2];
|
float _cal_data[5][101][2];
|
||||||
|
float _electrical_delay; // picoseconds
|
||||||
|
|
||||||
trace_t _trace[TRACES_MAX];
|
trace_t _trace[TRACES_MAX];
|
||||||
marker_t _markers[4];
|
marker_t _markers[4];
|
||||||
int _active_marker;
|
int _active_marker;
|
||||||
|
|
@ -272,7 +275,7 @@ typedef struct {
|
||||||
int32_t checksum;
|
int32_t checksum;
|
||||||
} properties_t;
|
} properties_t;
|
||||||
|
|
||||||
#define CONFIG_MAGIC 0x436f4e45 /* 'CoNF' */
|
#define CONFIG_MAGIC 0x434f4e45 /* 'CONF' */
|
||||||
|
|
||||||
extern int16_t lastsaveid;
|
extern int16_t lastsaveid;
|
||||||
extern properties_t *active_props;
|
extern properties_t *active_props;
|
||||||
|
|
@ -286,6 +289,7 @@ extern uint8_t previous_marker;
|
||||||
#define cal_status current_props._cal_status
|
#define cal_status current_props._cal_status
|
||||||
#define frequencies current_props._frequencies
|
#define frequencies current_props._frequencies
|
||||||
#define cal_data active_props->_cal_data
|
#define cal_data active_props->_cal_data
|
||||||
|
#define electrical_delay active_props->_electrical_delay
|
||||||
|
|
||||||
#define trace current_props._trace
|
#define trace current_props._trace
|
||||||
#define markers current_props._markers
|
#define markers current_props._markers
|
||||||
|
|
|
||||||
4
ui.c
4
ui.c
|
|
@ -627,6 +627,8 @@ menu_marker_op_cb(int item)
|
||||||
break;
|
break;
|
||||||
case 4: /* MARKERS->SPAN */
|
case 4: /* MARKERS->SPAN */
|
||||||
{
|
{
|
||||||
|
if (previous_marker == active_marker)
|
||||||
|
return;
|
||||||
int32_t freq2 = get_marker_frequency(previous_marker);
|
int32_t freq2 = get_marker_frequency(previous_marker);
|
||||||
if (freq2 < 0)
|
if (freq2 < 0)
|
||||||
return;
|
return;
|
||||||
|
|
@ -1259,7 +1261,7 @@ keypad_click(int key)
|
||||||
set_trace_refpos(uistat.current_trace, value);
|
set_trace_refpos(uistat.current_trace, value);
|
||||||
break;
|
break;
|
||||||
case KM_EDELAY:
|
case KM_EDELAY:
|
||||||
//set_trace_edelay(uistat.current_trace, value);
|
set_electrical_delay(value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue