From 77b5d0bcc87ade5d4e76bf108880cfb82c10f841 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 8 Mar 2020 22:48:36 +0300 Subject: [PATCH] Select CH0 reflect channel before set freq (in some rare cases dsp started but CH not ready) Little code optimization Add commented 600kHz I2C bus timings (work, give x1.5 speed, but need change DSP ready timings not by wait_count, need use chVTGetSystemTimeX() its better) --- main.c | 43 +++++++++++++++---------------------------- plot.c | 32 +++++++++++--------------------- si5351.c | 2 +- 3 files changed, 27 insertions(+), 50 deletions(-) diff --git a/main.c b/main.c index c6c5a96..5bc5603 100644 --- a/main.c +++ b/main.c @@ -787,8 +787,8 @@ bool sweep(bool break_on_operation) // Also touch made some DSP_START(1); DSP_WAIT_READY; for (i = 0; i < sweep_points; i++) { // 5300 - delay = set_frequency(frequencies[i]); // 700 tlv320aic3204_select(0); // 60 CH0:REFLECT + delay = set_frequency(frequencies[i]); // 700 DSP_START(delay); // 1900 //================================================ // Place some code thats need execute while delay @@ -1296,35 +1296,18 @@ void cal_collect(int type) { ensure_edit_config(); - + int dst, src; switch (type) { - case CAL_LOAD: - cal_status |= CALSTAT_LOAD; - memcpy(cal_data[CAL_LOAD], measured[0], sizeof measured[0]); - break; - - case CAL_OPEN: - cal_status |= CALSTAT_OPEN; - cal_status &= ~(CALSTAT_ES|CALSTAT_APPLY); - memcpy(cal_data[CAL_OPEN], measured[0], sizeof measured[0]); - break; - - case CAL_SHORT: - cal_status |= CALSTAT_SHORT; - cal_status &= ~(CALSTAT_ER|CALSTAT_APPLY); - memcpy(cal_data[CAL_SHORT], measured[0], sizeof measured[0]); - break; - - case CAL_THRU: - cal_status |= CALSTAT_THRU; - memcpy(cal_data[CAL_THRU], measured[1], sizeof measured[0]); - break; - - case CAL_ISOLN: - cal_status |= CALSTAT_ISOLN; - memcpy(cal_data[CAL_ISOLN], measured[1], sizeof measured[0]); - break; + case CAL_LOAD: cal_status|= CALSTAT_LOAD; dst = CAL_LOAD; src = 0; break; + case CAL_OPEN: cal_status|= CALSTAT_OPEN; dst = CAL_OPEN; src = 0; cal_status&= ~(CALSTAT_ES|CALSTAT_APPLY); break; + case CAL_SHORT: cal_status|= CALSTAT_SHORT; dst = CAL_SHORT; src = 0; cal_status&= ~(CALSTAT_ER|CALSTAT_APPLY); break; + case CAL_THRU: cal_status|= CALSTAT_THRU; dst = CAL_THRU; src = 1; break; + case CAL_ISOLN: cal_status|= CALSTAT_ISOLN; dst = CAL_ISOLN; src = 1; break; + default: + return; } + // Copy calibration data + memcpy(cal_data[dst], measured[src], sizeof measured[0]); redraw_request |= REDRAW_CAL_STATUS; } @@ -2209,6 +2192,10 @@ static const I2CConfig i2ccfg = { STM32_TIMINGR_PRESC(5U) | STM32_TIMINGR_SCLDEL(3U) | STM32_TIMINGR_SDADEL(3U) | STM32_TIMINGR_SCLH(3U) | STM32_TIMINGR_SCLL(9U), + // 600kHz @ SYSCLK 48MHz, manually get values, x1.5 I2C speed, but need calc timings +// STM32_TIMINGR_PRESC(3U) | +// STM32_TIMINGR_SCLDEL(2U) | STM32_TIMINGR_SDADEL(2U) | +// STM32_TIMINGR_SCLH(4U) | STM32_TIMINGR_SCLL(4U), #else #error "Need Define STM32_I2C1SW and set correct TIMINGR settings" #endif diff --git a/plot.c b/plot.c index 5d712a6..498aa88 100644 --- a/plot.c +++ b/plot.c @@ -1636,27 +1636,17 @@ draw_cal_status(void) ili9341_drawstring(c, x, y); y += YSTEP; } - - if (cal_status & CALSTAT_ED) { - ili9341_drawstring("D", x, y); - y += YSTEP; - } - if (cal_status & CALSTAT_ER) { - ili9341_drawstring("R", x, y); - y += YSTEP; - } - if (cal_status & CALSTAT_ES) { - ili9341_drawstring("S", x, y); - y += YSTEP; - } - if (cal_status & CALSTAT_ET) { - ili9341_drawstring("T", x, y); - y += YSTEP; - } - if (cal_status & CALSTAT_EX) { - ili9341_drawstring("X", x, y); - y += YSTEP; - } + int i; + static const struct {char text, zero, mask;} calibration_text[]={ + {'D', 0, CALSTAT_ED}, + {'R', 0, CALSTAT_ER}, + {'S', 0, CALSTAT_ES}, + {'T', 0, CALSTAT_ET}, + {'X', 0, CALSTAT_EX} + }; + for (i = 0; i < 5; i++, y+= YSTEP) + if (cal_status & calibration_text[i].mask) + ili9341_drawstring(&calibration_text[i].text, x, y); } // Draw battery level diff --git a/si5351.c b/si5351.c index 92eeb8a..9b3511b 100644 --- a/si5351.c +++ b/si5351.c @@ -338,7 +338,7 @@ static inline uint8_t si5351_getBand(uint32_t freq){ // Minimum value is 2, freq change apply at next dsp measure, and need skip it #define DELAY_NORMAL 2 // Additional delay for band 1 (remove unstable generation at begin) -#define DELAY_BAND_1 1 +#define DELAY_BAND_1 1 // Band changes need additional delay after reset PLL #define DELAY_BANDCHANGE_1 2 #define DELAY_BANDCHANGE_2 2