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 = {
|
||||
/* magic */ CONFIG_MAGIC,
|
||||
/* frequency0 */ 1000000,
|
||||
/* frequency1 */ 300000000,
|
||||
/* frequency0 */ 50000, // start = 50kHz
|
||||
/* frequency1 */ 300000000, // end = 300MHz
|
||||
/* sweep_points */ 101,
|
||||
/* cal_status */ 0,
|
||||
/* frequencies */ {},
|
||||
/* cal_data */ {},
|
||||
/* electrical_delay */ 0,
|
||||
/* trace[4] */
|
||||
{/*enable, type, channel, polar, scale*/
|
||||
{ 1, TRC_LOGMAG, 0, 0, 1.0, 7.0 },
|
||||
|
|
@ -482,6 +483,9 @@ void sweep(void)
|
|||
if (cal_status & CALSTAT_APPLY)
|
||||
apply_error_term_at(i);
|
||||
|
||||
if (electrical_delay != 0)
|
||||
apply_edelay_at(i);
|
||||
|
||||
redraw_requested = FALSE;
|
||||
ui_process();
|
||||
if (redraw_requested)
|
||||
|
|
@ -903,6 +907,21 @@ void apply_error_term_at(int i)
|
|||
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
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
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[])
|
||||
{
|
||||
int t;
|
||||
|
|
@ -1563,6 +1603,7 @@ static const ShellCommand commands[] =
|
|||
{ "recall", cmd_recall },
|
||||
{ "trace", cmd_trace },
|
||||
{ "marker", cmd_marker },
|
||||
{ "edelay", cmd_edelay },
|
||||
{ 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_refpos(int t, float refpos);
|
||||
|
||||
void set_electrical_delay(float picoseconds);
|
||||
|
||||
// marker
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -264,6 +266,7 @@ typedef struct {
|
|||
|
||||
uint32_t _frequencies[101];
|
||||
float _cal_data[5][101][2];
|
||||
float _electrical_delay; // picoseconds
|
||||
|
||||
trace_t _trace[TRACES_MAX];
|
||||
marker_t _markers[4];
|
||||
|
|
@ -272,7 +275,7 @@ typedef struct {
|
|||
int32_t checksum;
|
||||
} properties_t;
|
||||
|
||||
#define CONFIG_MAGIC 0x436f4e45 /* 'CoNF' */
|
||||
#define CONFIG_MAGIC 0x434f4e45 /* 'CONF' */
|
||||
|
||||
extern int16_t lastsaveid;
|
||||
extern properties_t *active_props;
|
||||
|
|
@ -286,6 +289,7 @@ extern uint8_t previous_marker;
|
|||
#define cal_status current_props._cal_status
|
||||
#define frequencies current_props._frequencies
|
||||
#define cal_data active_props->_cal_data
|
||||
#define electrical_delay active_props->_electrical_delay
|
||||
|
||||
#define trace current_props._trace
|
||||
#define markers current_props._markers
|
||||
|
|
|
|||
4
ui.c
4
ui.c
|
|
@ -627,6 +627,8 @@ menu_marker_op_cb(int item)
|
|||
break;
|
||||
case 4: /* MARKERS->SPAN */
|
||||
{
|
||||
if (previous_marker == active_marker)
|
||||
return;
|
||||
int32_t freq2 = get_marker_frequency(previous_marker);
|
||||
if (freq2 < 0)
|
||||
return;
|
||||
|
|
@ -1259,7 +1261,7 @@ keypad_click(int key)
|
|||
set_trace_refpos(uistat.current_trace, value);
|
||||
break;
|
||||
case KM_EDELAY:
|
||||
//set_trace_edelay(uistat.current_trace, value);
|
||||
set_electrical_delay(value);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue