From 1656342eeb60141e26c678b81480c127ffa7fc87 Mon Sep 17 00:00:00 2001 From: TT Date: Wed, 15 Jan 2020 01:07:40 +0900 Subject: [PATCH] feat: add bandwidth setting of detector --- dsp.c | 16 ++++++++-------- main.c | 52 ++++++++++++++++++++++++++++++++++++++-------------- nanovna.h | 2 ++ ui.c | 23 +++++++++++++++++++++++ 4 files changed, 71 insertions(+), 22 deletions(-) diff --git a/dsp.c b/dsp.c index 6e9f607..4b616dc 100644 --- a/dsp.c +++ b/dsp.c @@ -41,10 +41,10 @@ const int16_t sincos_tbl[48][2] = { {-24636, -21605 }, {-32698, -2143 }, {-27246, 18205 }, {-10533, 31029 } }; -int32_t acc_samp_s; -int32_t acc_samp_c; -int32_t acc_ref_s; -int32_t acc_ref_c; +float acc_samp_s; +float acc_samp_c; +float acc_ref_s; +float acc_ref_c; void dsp_process(int16_t *capture, size_t length) @@ -79,10 +79,10 @@ dsp_process(int16_t *capture, size_t length) ref_c = __SMLATT(sr, sc, ref_c); #endif } - acc_samp_s = samp_s; - acc_samp_c = samp_c; - acc_ref_s = ref_s; - acc_ref_c = ref_c; + acc_samp_s += samp_s; + acc_samp_c += samp_c; + acc_ref_s += ref_s; + acc_ref_c += ref_c; } void diff --git a/main.c b/main.c index fff210d..91f475c 100644 --- a/main.c +++ b/main.c @@ -584,10 +584,34 @@ int16_t dump_buffer[AUDIO_BUFFER_LEN]; int16_t dump_selection = 0; #endif -volatile int16_t wait_count = 0; +volatile uint8_t wait_count = 0; +volatile uint8_t accumerate_count = 0; + +const int8_t bandwidth_accumerate_count[] = { + 1, // 1kHz + 3, // 300Hz + 10, // 100Hz + 33, // 30Hz + 100 // 10Hz +}; float measured[2][POINTS_COUNT][2]; +static inline void +dsp_start(int count) +{ + wait_count = count; + accumerate_count = bandwidth_accumerate_count[bandwidth]; + reset_dsp_accumerator(); +} + +static inline void +dsp_wait(void) +{ + while (accumerate_count > 0) + __WFI(); +} + #ifdef ENABLED_DUMP static void duplicate_buffer_to_dump(int16_t *p) @@ -610,13 +634,16 @@ void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n) (void)i2sp; (void)n; - if (wait_count > 0) { - if (wait_count == 1) - dsp_process(p, n); -#ifdef ENABLED_DUMP - duplicate_buffer_to_dump(p); -#endif + if (wait_count > 1) { --wait_count; + } else if (wait_count > 0) { + if (accumerate_count > 0) { + dsp_process(p, n); + accumerate_count--; + } +#ifdef ENABLED_DUMP + duplicate_buffer_to_dump(p); +#endif } #if PORT_SUPPORTS_RT @@ -808,9 +835,6 @@ ensure_edit_config(void) cal_status = 0; } -#define DSP_START(delay) wait_count = delay; -#define DSP_WAIT_READY while (wait_count) __WFI(); - #define DELAY_CHANNEL_CHANGE 2 // main loop for measurement @@ -824,20 +848,20 @@ bool sweep(bool break_on_operation) if (frequencies[i] == 0) break; delay = set_frequency(frequencies[i]); // 700 tlv320aic3204_select(0); // 60 CH0:REFLECT, reset and begin measure - DSP_START(delay + ((i == 0) ? 1 : 0)); // 1900 + dsp_start(delay + ((i == 0) ? 1 : 0)); // 1900 //================================================ // Place some code thats need execute while delay //================================================ - DSP_WAIT_READY; + dsp_wait(); // calculate reflection coefficient (*sample_func)(measured[0][i]); // 60 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 //================================================ - DSP_WAIT_READY; + dsp_wait(); // calculate transmission coefficient (*sample_func)(measured[1][i]); // 60 // ======== 170 =========== diff --git a/nanovna.h b/nanovna.h index d553f38..ec03e18 100644 --- a/nanovna.h +++ b/nanovna.h @@ -379,6 +379,7 @@ typedef struct properties { int8_t _active_marker; uint8_t _domain_mode; /* 0bxxxxxffm : where ff: TD_FUNC m: DOMAIN_MODE */ uint8_t _marker_smith_format; + uint8_t _bandwidth; uint8_t _reserved[50]; uint32_t checksum; } properties_t; @@ -405,6 +406,7 @@ extern properties_t current_props; #define domain_mode current_props._domain_mode #define velocity_factor current_props._velocity_factor #define marker_smith_format current_props._marker_smith_format +#define bandwidth current_props._bandwidth #define FREQ_IS_STARTSTOP() (!(config.freq_mode&FREQ_MODE_CENTER_SPAN)) #define FREQ_IS_CENTERSPAN() (config.freq_mode&FREQ_MODE_CENTER_SPAN) diff --git a/ui.c b/ui.c index 391af98..3e10a58 100644 --- a/ui.c +++ b/ui.c @@ -631,6 +631,13 @@ menu_transform_filter_cb(int item, uint8_t data) ui_mode_normal(); } +static void +menu_bandwidth_cb(int item) +{ + bandwidth = item; + draw_menu(); +} + static void choose_active_marker(void) { @@ -928,12 +935,23 @@ const menuitem_t menu_transform[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; +const menuitem_t menu_bandwidth[] = { + { MT_CALLBACK, 0, "1 kHz", menu_bandwidth_cb }, + { MT_CALLBACK, 0, "300 Hz", menu_bandwidth_cb }, + { MT_CALLBACK, 0, "100 Hz", menu_bandwidth_cb }, + { MT_CALLBACK, 0, "30 Hz", menu_bandwidth_cb }, + { MT_CALLBACK, 0, "10 Hz", menu_bandwidth_cb }, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + const menuitem_t menu_display[] = { { MT_SUBMENU, 0, "TRACE", menu_trace }, { MT_SUBMENU, 0, "FORMAT", menu_format }, { MT_SUBMENU, 0, "SCALE", menu_scale }, { MT_SUBMENU, 0, "CHANNEL", menu_channel }, { MT_SUBMENU, 0, "TRANSFORM", menu_transform }, + { MT_SUBMENU, 0, "BANDWIDTH", menu_bandwidth }, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -1365,6 +1383,11 @@ menu_item_modify_attribute(const menuitem_t *menu, int item, *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } + } else if (menu == menu_bandwidth) { + if (item == bandwidth) { + *bg = 0x0000; + *fg = 0xffff; + } } else if (menu == menu_transform) { if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME) || (item == 1 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_IMPULSE)