Add VHF XVTR PA calibration; fix TX drive formula and stale FDriveLevel

PA calibration per band (HF and VHF):
- Add VHFBandCal[0..7] in TGlobalSettings (saved as vhf_cal_0..7 in JSON)
- Default HF cal updated to Thetis HERMES defaults (38.8-41.3 dB per band)
- Default VHF cal = 56.2 dB (Thetis HERMES XVTR default)
- SettingsForm: second group in PA tab "VHF Calibration (Transverters)" with
  8 spinboxes VHF0..VHF7; labels dynamically show XVTR slot ButtonText
  when LoadXvtrSettings is called (e.g. "VHF0 (2m):")

TX drive formula (CalcDriveByte) rewritten to match Thetis exactly:
  drive_byte = min(sqrt(10^((10*log10(pwr_W*1000) - Cal)/10) * 0.05) / 0.8, 1.0) * 1.02 * 255
  Cal = PA gain in dB (not a percentage); matches Thetis verified output
  (Cal=63.1 + slider=100% + PAMax=100W → drive_byte=16, verified against Thetis)
  Old formula Pos/100*Cal/100*255 was wrong: treated dB gain as linear percent

Fix stale FDriveLevel not updated on band/XVTR switch:
- Startup: FCurrentBand must be set before CalcDriveByte (was reversed)
- RestoreBand: recalculate FDriveLevel before ApplyVfoA network update
- ActivateXvtrBand: recalculate after FCurrentXvtr changes
- ApplyVfoA: recalculate when VFO crosses HF band boundary
- FreqDispBChanged: same for VFO-B band changes
- ApplyMOX(True): safety recalculate at PTT engage time

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-19 11:49:12 +03:00
co-authored by Claude Sonnet 4.6
parent 203d9d0f05
commit d823106366
4 changed files with 238 additions and 71 deletions
+13 -2
View File
@@ -12,6 +12,11 @@ const
SETTINGS_FILE = 'hpsdr_settings.json';
CFG_BAND_COUNT = 11;
CFG_XVTR_COUNT = 8; // количество XVTR-слотов (трансверторов)
// PA gain defaults (dB) — match Thetis HERMES/HPSDR defaults
// order: 160m,80m,60m,40m,30m,20m,17m,15m,12m,10m,6m
CFG_PA_BAND_CAL_DEFAULT: array[0..CFG_BAND_COUNT-1] of Double = (
41.0, 41.2, 41.3, 41.3, 41.0, 40.5, 39.9, 38.8, 38.8, 38.8, 38.8);
CFG_VHF_CAL_DEFAULT = 56.2; // dB, default for all XVTR slots
CFG_BAND_DEFAULT_FREQ: array[0..CFG_BAND_COUNT-1] of Double = (
1900000, 3750000, 5357000, 7100000, 10125000,
14200000, 18120000, 21200000, 24940000, 28500000, 50150000);
@@ -223,6 +228,7 @@ type
// --- PA (Power Amplifier) settings ---
PAMaxPower: Double; // максимальная выходная мощность, Вт (5..200)
PABandCal: array[0..CFG_BAND_COUNT-1] of Double; // калибровка на диапазон 38.8..100.0
VHFBandCal: array[0..CFG_XVTR_COUNT-1] of Double; // калибровка для XVTR слотов 38.8..100.0
// --- ADC settings ---
DitherEnabled: Boolean; // DDC Specific byte 5 — уменьшает интермодуляцию
RandomEnabled: Boolean; // DDC Specific byte 6 — рандомизация ADC
@@ -362,7 +368,8 @@ begin
G.WfNFEnabled := False;
G.SampleRate := 192000;
G.PAMaxPower := 100.0;
for i := 0 to CFG_BAND_COUNT-1 do G.PABandCal[i] := 100.0;
for i := 0 to CFG_BAND_COUNT-1 do G.PABandCal[i] := CFG_PA_BAND_CAL_DEFAULT[i];
for i := 0 to CFG_XVTR_COUNT-1 do G.VHFBandCal[i] := CFG_VHF_CAL_DEFAULT;
// Display defaults
G.FFTSize := 131072;
G.WindowType := 2; // Hann
@@ -604,7 +611,9 @@ begin
// PA settings
G.PAMaxPower := JD(GObj,'pa_max_power',100.0);
for i := 0 to CFG_BAND_COUNT-1 do
G.PABandCal[i] := JD(GObj,'pa_band_cal_'+IntToStr(i),100.0);
G.PABandCal[i] := JD(GObj,'pa_band_cal_'+IntToStr(i), CFG_PA_BAND_CAL_DEFAULT[i]);
for i := 0 to CFG_XVTR_COUNT-1 do
G.VHFBandCal[i] := JD(GObj,'vhf_cal_'+IntToStr(i), CFG_VHF_CAL_DEFAULT);
// CAT serial settings
for i := 0 to 3 do begin
G.CATSerialEnabled[i] := JB(GObj,'cat_serial_en_'+IntToStr(i), False);
@@ -688,6 +697,8 @@ begin
JW(O,'pa_max_power',G.PAMaxPower);
for i := 0 to CFG_BAND_COUNT-1 do
JW(O,'pa_band_cal_'+IntToStr(i),G.PABandCal[i]);
for i := 0 to CFG_XVTR_COUNT-1 do
JW(O,'vhf_cal_'+IntToStr(i),G.VHFBandCal[i]);
// CAT serial settings
for i := 0 to 3 do begin
JW(O,'cat_serial_en_'+IntToStr(i), G.CATSerialEnabled[i]);