diff --git a/changelog.txt b/changelog.txt index f3c0d0b..12bd110 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,10 @@ +V1.4290 2026-11-02 For all tinySA models +- Recalling a preset turns NORMALIZE off: the normalization reference trace is not stored in a preset, so the normalized trace was wrong +- Trace CSV files load with their own start and stop frequency again: with CONFIG > MHz CSV (the default) the frequencies were read as Hz (Ultra only) +- AM output keeps enough attenuator range for the modulation at every level: just above the level where the output switch is used the troughs were cut off without a warning, at some lower levels the peaks (DEPTH ERROR) (Ultra only) +- FM modulation uses more steps: any number up to 12000 per second instead of powers of 2, e.g. 12 steps at 1 kHz (was 4) and 6 steps at 2 kHz (was a square wave) (Ultra only) +- Fixed the "CTCSS + 1 kHz" tone being switched on after an update from a version older than V1.4220 (Ultra only) + V1.4284 2026-11-02 For all tinySA models - Every tinySA has its own USB serial number (from the MCU unique ID, on the tinySA Ultra the same as its DFU serial number), so Windows can tell several tinySAs apart. Windows assigns a new COM port once - The battery stays visible when the sweep is paused with the "pause" console command diff --git a/flash.c b/flash.c index 6d11baf..2a3e289 100644 --- a/flash.c +++ b/flash.c @@ -127,6 +127,10 @@ config_recall(void) if (config.sd_icon_save == 0) config.sd_icon_save = SDIS_DEFAULT; #endif // __USE_SD_CARD__ +#ifdef TINYSA4 + if (config.wfm_1khz_harmonic > 100) // v1.4-220 placed it on the old sd_icon_save byte (always >= 0x80) + config.wfm_1khz_harmonic = 0; +#endif return 0; } @@ -233,6 +237,8 @@ caldata_recall(uint16_t id) /* duplicated saved data onto sram to be able to modify marker/trace */ memcpy(dst, src, sizeof(setting_t)); + memset(setting.normalized, 0, sizeof setting.normalized); // the normalize reference trace is not in a preset + setting.normalized_trace = -1; #ifdef __SD_FILE_BROWSER__ sd_preset_path[0] = 0; // this preset came from flash, not from SD #endif diff --git a/sa_core.c b/sa_core.c index a38f77c..6293f6b 100644 --- a/sa_core.c +++ b/sa_core.c @@ -277,7 +277,9 @@ void set_output_path(freq_t f, float level) switch_atten = 31.0; #endif float a = level - level_max(); // convert to all settings maximum power output equals a = zero - if (a < -switch_atten + BELOW_MAX_DRIVE(0)) { // Switch needed + // Switch needed. AM: switch as soon as possible, else just above the threshold the attenuator is near + // its maximum and has no room left for the modulation troughs + if (a < -switch_atten + (setting.modulation == MO_AM ? 0 : BELOW_MAX_DRIVE(0))) { a = a + switch_atten; setting.atten_step = true; } else @@ -308,7 +310,8 @@ void set_output_path(freq_t f, float level) int ar = 31 - ATTENUATION_RESERVE; if (setting.modulation == MO_AM) // reserve attenuator range for AM modulation ar = 6; - while (a + ar < blw && d > LOWEST_LEVEL) { // reduce till it fits attenuator ((ar+ATTENUATION_RESERVE) .. ATTENUATION_RESERVE) + while (a + ar < blw && d > LOWEST_LEVEL // reduce till it fits attenuator ((ar+ATTENUATION_RESERVE) .. ATTENUATION_RESERVE) + && (setting.modulation != MO_AM || BELOW_MAX_DRIVE(d-1) >= a)) { // AM: a drive step larger than ar must not use the reserve for the peaks d--; blw = BELOW_MAX_DRIVE(d); } @@ -3499,6 +3502,21 @@ static int modulation_steps = 8; // Max = 10000 / 28.8 static const int sine_wave[MAX_MODULATION_STEPS/4+1] = {0, 17, 34, 51, 68, 84, 101, 117, 133, 148, 164, 179, 193, 207, 220, 233, 246, 257, 268, 279, 289, 298, 306, 314, 321, 327, 332, 337, 341, 343, 346, 347, 347 }; + +// sine_wave[] (+-347) at phase p in 1/(MAX_MODULATION_STEPS*256) of a period, linear interpolation +static int sine347(uint32_t p) +{ + p &= MAX_MODULATION_STEPS*256 - 1; + int neg = p >= MAX_MODULATION_STEPS/2*256; + if (neg) p -= MAX_MODULATION_STEPS/2*256; + if (p > MAX_MODULATION_STEPS/4*256) p = MAX_MODULATION_STEPS/2*256 - p; + int i = p >> 8; + int v = sine_wave[i]; + if (i < MAX_MODULATION_STEPS/4) + v += ((sine_wave[i+1] - v) * (int)(p & 255)) >> 8; + return neg ? -v : v; +} +#define MAX_FM_STEP_RATE 12000 // Si4468 offset updates per second for FM, faster makes the output crackle // // Offset is 14.4Hz when below 600MHz and 28.8 when above. // @@ -3745,43 +3763,20 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / } } if (setting.modulation == MO_WFM) { - int sine_wave_index = 1; config.cor_am = INITIAL_MODULATION_CORRECTION; // Initialize with some spare - modulation_steps = MAX_MODULATION_STEPS; // Search modulation steps that fit frequency - //modulation_steps = 8; // <-----------------TEMP!!!!! - while ( ((modulation_delay = ((float)8000000/ modulation_steps ) / setting.modulation_frequency + config.cor_am)) < 900 && modulation_steps >= 4) { - sine_wave_index <<= 1; - modulation_steps >>= 1; - } - if (modulation_steps >= 4) { - int hn = (config.wfm_1khz_harmonic > 0 && setting.modulation_frequency < MAX_CTCSS_FREQ) ? (int)((1000.0 / setting.modulation_frequency) + 0.5) : 0; - int local_deviation = setting.modulation_deviation_div100; + modulation_steps = MAX_FM_STEP_RATE / setting.modulation_frequency; // any count, not only powers of 2 + if (modulation_steps > MAX_MODULATION_STEPS) modulation_steps = MAX_MODULATION_STEPS; + if (modulation_steps < 2) modulation_steps = 2; + int hn = (config.wfm_1khz_harmonic > 0 && setting.modulation_frequency < MAX_CTCSS_FREQ) ? (int)((1000.0 / setting.modulation_frequency) + 0.5) : 0; + int local_deviation = setting.modulation_deviation_div100; + if (hn) + local_deviation /= 7; // 15% CTCSS deviation + for (int i = 0; i < modulation_steps; i++) { + uint32_t p = (2*i+1) * (MAX_MODULATION_STEPS*256/2) / modulation_steps; // middle of the step: 2 steps give +-deviation + int v = local_deviation * sine347(p) / 100; if (hn) - local_deviation /= 7; // 15% CTCSS deviation - for (int i = 0; i < modulation_steps/4+1; i++) { - fm_modulation[i] = local_deviation * sine_wave[i*sine_wave_index]/100; - fm_modulation[modulation_steps/2 - i] = fm_modulation[i]; - fm_modulation[modulation_steps/2 + i] = -fm_modulation[i]; - fm_modulation[modulation_steps - i] = -fm_modulation[i]; - } - if (hn) { - for (int i = 0; i < modulation_steps; i++) { - int table_index = (i*sine_wave_index*hn) % MAX_MODULATION_STEPS; - int mul = 1; - if (table_index > MAX_MODULATION_STEPS/2) { - mul = -1; - table_index = MAX_MODULATION_STEPS - table_index; - } - if (table_index > MAX_MODULATION_STEPS/4) - table_index = MAX_MODULATION_STEPS/2 - table_index; - int v = setting.modulation_deviation_div100 * sine_wave[table_index] * mul / 100; - fm_modulation[i] += v; - } - } - } else { - modulation_steps = 2; - fm_modulation[0] = (setting.modulation_deviation_div100*347)/100; - fm_modulation[1] = -fm_modulation[0]; + v += setting.modulation_deviation_div100 * sine347(p * hn) / 100; // approximate 1 kHz tone + fm_modulation[i] = v; } } #else diff --git a/vna_browser.c b/vna_browser.c index f991d1d..2b4605a 100644 --- a/vna_browser.c +++ b/vna_browser.c @@ -221,6 +221,8 @@ finish3: char *args[16]; int nargs = parse_line(line, args, 16); // Parse line to 16 args if (nargs < 2 || args[0][0] == '#' || args[0][0] == '!') continue; // No data or comment or settings + if (strchr(args[0], '.')) // MHz (CONFIG MHz CSV), Hz has no decimals + args[0][strlen(args[0])] = 'M'; // suffix so my_atoui returns Hz f = my_atoui(args[0]); // Get frequency if (count >= POINTS_COUNT || f > maxFreq) {error = "Format err"; goto finish;} if (count == 0) { @@ -331,6 +333,8 @@ static char cmd_buffer[256+128]; magic == SETTING_MAGIC && f_read(fs_file, src, total, &size) == FR_OK) { // TODO remove code duplication with flash.c + memset(setting.normalized, 0, sizeof setting.normalized); // the normalize reference trace is not in a preset + setting.normalized_trace = -1; update_min_max_freq(); update_frequencies(); set_scale(setting.scale);