From 40d5ceac618e57f9398454a6e253ef85b372c0a3 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 20 May 2020 17:31:14 +0200 Subject: [PATCH] Own_microsecond_delay busy loop --- main.c | 17 +++++++++++++++++ mcuconf.h | 2 +- nanovna.h | 4 ++-- sa_core.c | 8 +++++--- si4432.c | 3 ++- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index a2d4220..25d861c 100644 --- a/main.c +++ b/main.c @@ -2441,6 +2441,17 @@ static DACConfig dac1cfg1 = { }; #endif + +static const GPTConfig gpt4cfg = { + 1000000, // 1 MHz timer clock. + NULL, // No callback + 0, 0 +}; + +void my_microsecond_delay(int t) +{ + gptPolledDelay(&GPTD14, t); // t us delay +} #if 0 /* * UART driver configuration structure. @@ -2578,6 +2589,12 @@ int main(void) */ ili9341_init(); +/* + * Initiate 1 micro second timer + */ + gptStart(&GPTD14, &gpt4cfg); + gptPolledDelay(&GPTD14, 10); // 10 us delay + /* restore config */ config_recall(); if (caldata_recall(0) == -1 || setting.mode == -1) { diff --git a/mcuconf.h b/mcuconf.h index e04096c..241b42d 100644 --- a/mcuconf.h +++ b/mcuconf.h @@ -104,7 +104,7 @@ #define STM32_GPT_USE_TIM1 FALSE #define STM32_GPT_USE_TIM2 FALSE #define STM32_GPT_USE_TIM3 TRUE -#define STM32_GPT_USE_TIM14 FALSE +#define STM32_GPT_USE_TIM14 TRUE #define STM32_GPT_TIM1_IRQ_PRIORITY 2 #define STM32_GPT_TIM2_IRQ_PRIORITY 2 #define STM32_GPT_TIM3_IRQ_PRIORITY 2 diff --git a/nanovna.h b/nanovna.h index dfb87f3..12fea01 100644 --- a/nanovna.h +++ b/nanovna.h @@ -30,7 +30,7 @@ #define __MEASURE__ #define __SELFTEST__ #define __CALIBRATE__ -#define __ULTRA__ // Add harmonics mode on low input. +//#define __ULTRA__ // Add harmonics mode on low input. //#define __ULTRA_SA__ // Adds ADF4351 control for extra high 1st IF stage #define __SPUR__ // Does spur reduction by shifting IF @@ -121,7 +121,7 @@ enum stimulus_type { void update_frequencies(void); void set_sweep_frequency(int type, uint32_t frequency); uint32_t get_sweep_frequency(int type); - +void my_microsecond_delay(int t); double my_atof(const char *p); int shell_printf(const char *fmt, ...); diff --git a/sa_core.c b/sa_core.c index 60519a4..7766af6 100644 --- a/sa_core.c +++ b/sa_core.c @@ -914,7 +914,8 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) } else { modulation_counter++; } - chThdSleepMicroseconds(200); + my_microsecond_delay(200); +// chThdSleepMicroseconds(200); } else if (MODE_OUTPUT(setting.mode) && (setting.modulation == MO_NFM || setting.modulation == MO_WFM )) { //FM modulation SI4432_Sel = 1; @@ -933,6 +934,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) modulation_counter = 0; else modulation_counter++; + my_microsecond_delay(200); // chThdSleepMicroseconds(200); } @@ -2068,7 +2070,7 @@ void self_test(int test) reset_settings(M_LOW); int i = 15; // calibrate low mode power on 30 MHz; test_prepare(i); - setting.step_delay = 6000; + setting.step_delay = 8000; for (int j= 0; j < 57; j++ ) { setting.step_delay = setting.step_delay * 4/3; setting.rbw = SI4432_force_RBW(j); @@ -2083,7 +2085,7 @@ void self_test(int test) } shell_printf("Start level = %f, ",peakLevel); - while (setting.step_delay > 100 && peakLevel > saved_peakLevel - 1) { + while (setting.step_delay > 10 && peakLevel > saved_peakLevel - 1) { setting.step_delay = setting.step_delay * 3 / 4; test_prepare(i); // shell_printf("\n\rRBW = %f",SI4432_force_RBW(j)); diff --git a/si4432.c b/si4432.c index 7a51591..7aa7963 100644 --- a/si4432.c +++ b/si4432.c @@ -377,7 +377,8 @@ float SI4432_RSSI(uint32_t i, int s) #endif //START_PROFILE SI4432_Sel = s; - chThdSleepMicroseconds(actualStepDelay); + my_microsecond_delay(actualStepDelay); + // chThdSleepMicroseconds(actualStepDelay); i = setting.repeat; RSSI_RAW = 0; while (i-->0)