From e626c581eef1c237012d8e93523c47a6348ab440 Mon Sep 17 00:00:00 2001 From: TT Date: Mon, 12 Aug 2019 20:53:33 +0900 Subject: [PATCH] feat: add sample command to evalutate dynamic range --- dsp.c | 14 ++++++++++++++ main.c | 25 +++++++++++++++++++++++-- nanovna.h | 2 ++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/dsp.c b/dsp.c index 484dfac..0e1239b 100644 --- a/dsp.c +++ b/dsp.c @@ -95,6 +95,20 @@ calculate_gamma(float gamma[2]) gamma[1] = (ss * rc - sc * rs) / rr; } +void +fetch_amplitude(float gamma[2]) +{ + gamma[0] = acc_samp_s * 1e-9; + gamma[1] = acc_samp_c * 1e-9; +} + +void +fetch_amplitude_ref(float gamma[2]) +{ + gamma[0] = acc_ref_s * 1e-9; + gamma[1] = acc_ref_c * 1e-9; +} + void reset_dsp_accumerator(void) { diff --git a/main.c b/main.c index 97ff800..2ffa905 100644 --- a/main.c +++ b/main.c @@ -378,6 +378,26 @@ static void cmd_gamma(BaseSequentialStream *chp, int argc, char *argv[]) } #endif +static void (*sample_func)(float *gamma) = calculate_gamma; + +static void cmd_sample(BaseSequentialStream *chp, int argc, char *argv[]) +{ + if (argc == 1) { + if (strcmp(argv[0], "ref") == 0) { + sample_func = fetch_amplitude_ref; + return; + } else if (strcmp(argv[0], "ampl") == 0) { + sample_func = fetch_amplitude; + return; + } else if (strcmp(argv[0], "gamma") == 0) { + sample_func = calculate_gamma; + return; + } + } + chprintf(chp, "usage: sample {gamma|ampl|ref}\r\n"); +} + + #if 0 int32_t frequency0 = 1000000; int32_t frequency1 = 300000000; @@ -485,13 +505,13 @@ void sweep(void) palClearPad(GPIOC, GPIOC_LED); /* calculate reflection coeficient */ - calculate_gamma(measured[0][i]); + (*sample_func)(measured[0][i]); tlv320aic3204_select_in1(); // CH1:TRANSMISSION wait_dsp(delay); /* calculate transmission coeficient */ - calculate_gamma(measured[1][i]); + (*sample_func)(measured[1][i]); // blink LED while scanning palSetPad(GPIOC, GPIOC_LED); @@ -1653,6 +1673,7 @@ static const ShellCommand commands[] = { "stat", cmd_stat }, { "gain", cmd_gain }, { "power", cmd_power }, + { "sample", cmd_sample }, //{ "gamma", cmd_gamma }, //{ "scan", cmd_scan }, { "sweep", cmd_sweep }, diff --git a/nanovna.h b/nanovna.h index a68633c..dc36f25 100644 --- a/nanovna.h +++ b/nanovna.h @@ -88,6 +88,8 @@ extern int16_t samp_buf[]; void dsp_process(int16_t *src, size_t len); void reset_dsp_accumerator(void); void calculate_gamma(float *gamma); +void fetch_amplitude(float *gamma); +void fetch_amplitude_ref(float *gamma); int si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength);