diff --git a/NANOVNA_STM32_F303/board.h b/NANOVNA_STM32_F303/board.h index 1962485..6c1432b 100644 --- a/NANOVNA_STM32_F303/board.h +++ b/NANOVNA_STM32_F303/board.h @@ -226,7 +226,7 @@ PIN_ODR_HIGH(1) | \ PIN_ODR_HIGH(2) | \ PIN_ODR_HIGH(3) | \ - PIN_ODR_HIGH(GPIO_SD_DAT2) | \ + PIN_ODR_LOW(GPIO_SD_DAT2) | \ PIN_ODR_LOW(5) | \ PIN_ODR_HIGH(6) | \ PIN_ODR_HIGH(7) | \ diff --git a/main.c b/main.c index 04c4058..25591b5 100644 --- a/main.c +++ b/main.c @@ -2582,6 +2582,22 @@ void pwm_stop(void) #endif +static uint16_t audio_mode = A_DAC; + +void set_audio_mode(uint16_t new_mode) +{ + if (new_mode == audio_mode) + return; + if (new_mode == A_PWM) { + DAC->CR&= ~DAC_CR_EN1; // Disable DAC CH1 + pwm_init(); + } else { + palSetPadMode(GPIOA, 4, PAL_MODE_INPUT); // Back to DAC mode + DAC->CR|= DAC_CR_EN1 | DAC_CR_EN2; // Use DAC: CH1 and CH2 + } + audio_mode = new_mode; +} + static const GPTConfig gpt4cfg = { 8000000, // 8 MHz timer clock. NULL, // No callback @@ -2699,19 +2715,18 @@ int main(void) spi_init(); PULSE -#ifdef __PWM__ - pwm_init(); - pwm_start(2000); - pwm_stop(); -#endif +//#ifdef __PWM__ +// pwm_init(); +// pwm_start(2000); +// pwm_stop(); +//#endif /* * Set LCD display brightness (use DAC2 for control) * Starting DAC1 driver, setting up the output pin as analog as suggested by the Reference Manual. */ dac_init(); PULSE -// DAC->CR|= DAC_CR_EN1 | DAC_CR_EN2; // Use DAC: CH1 and CH2 - DAC->CR|= DAC_CR_EN2; // Use DAC: CH1 and CH2 + DAC->CR|= DAC_CR_EN1 | DAC_CR_EN2; // Use DAC: CH1 and CH2 #ifdef __LCD_BRIGHTNESS__ lcd_setBrightness(DEFAULT_BRIGHTNESS); #endif diff --git a/nanovna.h b/nanovna.h index 1959ce0..c30bc4e 100644 --- a/nanovna.h +++ b/nanovna.h @@ -344,6 +344,14 @@ extern const char * const info_about[]; #ifdef TINYSA4 void toggle_extra_lna(void); void set_extra_lna(int t); + +enum { A_DAC, A_PWM }; +void set_audio_mode(uint16_t new_mode); +void pwm_start(int f); +void pwm_stop(void); +#ifdef __GUARD__ +void reset_guard(void); +#endif #endif // ------------------------------- sa_core.c ---------------------------------- @@ -1747,8 +1755,9 @@ void interpolate_maximum(int m); void calibrate_modulation(int modulation, int8_t *correction); enum { - M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_SNR, M_PASS_BAND, M_LINEARITY, M_AM, M_FM, M_THD, M_CP, M_NF_TINYSA, M_NF_STORE, M_NF_VALIDATE, M_NF_AMPLIFIER, M_GUARD, M_DECONV + M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_SNR, M_PASS_BAND, M_LINEARITY, M_AM, M_FM, M_THD, M_CP, M_NF_TINYSA, M_NF_STORE, M_NF_VALIDATE, M_NF_AMPLIFIER, M_GUARD, M_DECONV,M_MAX }; +#define MEASUREMENT_TEXT "OFF","IMD","OIP3","PN","SNR","PASS","LIN","AM","FM","THD","CP","NF T","NF S","NF V","NF A","GUARD","DECONF" enum { T_AUTO, T_NORMAL, T_SINGLE, T_DONE, T_UP, T_DOWN, T_MODE, T_PRE, T_POST, T_MID diff --git a/sa_core.c b/sa_core.c index c0c972f..4456562 100644 --- a/sa_core.c +++ b/sa_core.c @@ -4787,6 +4787,13 @@ again: // Spur redu static uint8_t low_count = 0; static uint8_t sweep_counter = 0; // Only used for HW refresh +#ifdef __GUARD__ +static int last_guard = -1; + +void reset_guard(void) { + last_guard = -1; +} +#endif // main loop for measurement static bool sweep(bool break_on_operation) @@ -4873,17 +4880,19 @@ static bool sweep(bool break_on_operation) current_guard = 0; } while(!(setting.guards[current_guard].enabled)); - if (setting.guards[current_guard].end > setting.guards[current_guard].start) { + if (setting.guards[current_guard].end > setting.guards[current_guard].start && last_guard != current_guard) { + last_guard = current_guard; set_sweep_frequency(ST_START, setting.guards[current_guard].start); set_sweep_frequency(ST_STOP, setting.guards[current_guard].end); set_rbw(8000); set_sweep_points((setting.guards[current_guard].end - setting.guards[current_guard].start) / 800000); } - pwm_init(); + set_audio_mode(A_PWM); pwm_stop(); + } else { + last_guard = -1; + set_audio_mode(A_DAC); } - else - palSetPadMode(GPIOA, 4, PAL_MODE_INPUT); // Back to DAC mode #endif setting.measure_sweep_time_us = 0; // start measure sweep time diff --git a/ui.c b/ui.c index 0bf17fe..6e1bb98 100644 --- a/ui.c +++ b/ui.c @@ -1497,6 +1497,9 @@ static const menuitem_t menu_settings2[]; static const menuitem_t menu_lowoutput_settings[]; extern bool dirty; char range_text[20]; +#ifdef TINYSA4 +const char * const measurement_text[] = {MEASUREMENT_TEXT}; +#endif #ifdef TINYSA4 int input_is_calibrated(void) @@ -3190,6 +3193,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_guard_select_acb) if (count == 0) setting.guards[0].enabled = true; b->icon = (setting.guards[data].enabled?BUTTON_ICON_CHECK:BUTTON_ICON_NOCHECK) ; plot_printf(b->text, sizeof(b->text), "%.6FHz\n%.6FHz", (float)setting.guards[data].start, (float)setting.guards[data].end); + reset_guard(); return; } active_guard = data; @@ -5540,6 +5544,14 @@ redraw_cal_status: quick_menu_y[max_quick_menu] = y; quick_menu[max_quick_menu++] = (menuitem_t *)NULL; +#ifdef TINYSA4 + if (setting.measurement != M_OFF){ + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); + lcd_printf(x, y, measurement_text[setting.measurement]); + y += 2*YSTEP + YSTEP/2; + } + +#endif // if (setting.mode == M_LOW) { // Attenuation ili9341_set_foreground(setting.auto_attenuation ? LCD_FG_COLOR : LCD_BRIGHT_COLOR_GREEN);