Iterate through RBW

Need to save results, and get value back when RBW changes and use
This commit is contained in:
M0WID 2020-10-08 23:08:59 +01:00
parent f36f478363
commit 1e34a6ae95
7 changed files with 94 additions and 16 deletions

View File

@ -1,7 +1,7 @@
/*
* RX sweep fixes the LO and sweeps the receiver from a start value to an stop value to
* measure the RX FIR bandpass pass filter response. This eleimates any effect from the SAW
* measure the RX FIR bandpass pass filter response. This eliminates any effect from the SAW
* and low pass filters before the receiver.
* It requires a fixed strength and frequency signal, and this is provided
* by setting the reference output to say 15MHz. Avoid 30Mhz due to some stray clock signal
@ -50,6 +50,9 @@ static uint32_t nextPointFreq = 0; // Frequency for the next display point. Us
static unsigned long setFreqMicros;
static unsigned long nowMicros;
static uint16_t currentRBW10;
static uint16_t bpFilterIndex; // used to loop through the SI4432 bandpass filters when calibrating
static uint32_t sweepStep; // Step count
static uint32_t sweepFreqStep;
@ -72,6 +75,8 @@ static uint16_t lastMinRSSI; // Minimum level for the previous sweep
static bool jsonDocInitialised = false;
static uint16_t chunkIndex;
static double bpfCalibrations[MAX_SI4432_FILTERS]; // temporary storage for calibration values
static uint16_t bpfCalFirstSweepDone;
/*
* If paused and at the start of a sweep then do nothing
*/
@ -81,9 +86,47 @@ static uint16_t chunkIndex;
if (( !sweepStartDone || initSweep || changedSetting ) )
{
if ( initSweep || changedSetting ) // Something has changed, or a first start, so need to work out some basic things
if ( initSweep || changedSetting || (bpfCalibrate && !sweepStartDone) ) // Something has changed, or a first start, so need to work out some basic things
{
Serial.println("Init RXSweep or changedSetting");
//Serial.println("Init RXSweep or changedSetting");
if (bpfCalibrate)
{
if (bpfCalFirstSweepDone)
{
// max value for this bpFilter index (pervious sweep) is in peaks[0].Level
bpfCalibrations[bpFilterIndex] = CAL_POWER - rssiTodBm ( peaks[0].Level);
Serial.printf("bpfCalibration: filter: %i, rbw10=%i , cal=%f \n", bpFilterIndex, currentRBW10, bpfCalibrations[bpFilterIndex]);
bpFilterIndex ++;
if (bpFilterIndex >= bpfCount) // end of calibration
{
bpfCalibrate = false;
currentRBW10 = setting.Bandwidth10;
// savebpfCal();
Serial.println("bpfCalibration done");
}
else // not reached end of filters
{
currentRBW10 = rcvr.GetBandpassFilter10(bpFilterIndex);
}
}
else // first sweep not done
{
bpfCalFirstSweepDone = true;
currentRBW10 = rcvr.GetBandpassFilter10(bpFilterIndex);
}
}
else // not in calibrate
{
currentRBW10 = setting.Bandwidth10;
bpFilterIndex = 0;
bpfCalFirstSweepDone = false;
}
SetRXsweepSpan (currentRBW10 * 1000); // 10 * bandwidth - sets up stopFreq_RX and startFreq_RX
autoSweepFreqStep = ( stopFreq_RX - startFreq_RX ) / displayPoints;
vbw = autoSweepFreqStep / 1000.0; // Set the video resolution
@ -91,7 +134,7 @@ static uint16_t chunkIndex;
/*
* Use the RBW setting. If zero then it is meaningless, use smallest instead
*/
bandwidth = rcvr.SetRBW ( setting.Bandwidth10, &delaytime ); // Set it in the receiver Si4432. delaytime is returned
bandwidth = rcvr.SetRBW ( currentRBW10, &delaytime ); // Set it in the receiver Si4432. delaytime is returned
sweepPoints = displayPoints;
@ -100,9 +143,8 @@ static uint16_t chunkIndex;
att.SetAtten ( 0 ); // Set the internal attenuator
// pre-calculate adjustment for RSSI values
dBadjust = -120.0 + setting.LevelOffset - setting.ExternalGain;
Serial.printf("RXSweep dBadjust = %f; leveloffset = %f; attenuate = %i, ext gain = %f\n",
dBadjust, setting.LevelOffset, setting.Attenuate, setting.ExternalGain);
dBadjust = -120.0 - setting.ExternalGain; // No correction applied for this mode
//Serial.printf("RXSweep dBadjust = %f; ext gain = %f\n", dBadjust, setting.ExternalGain);
xmit.SetPowerReference ( setting.ReferenceOut ); // Set the GPIO reference output
@ -326,7 +368,7 @@ static uint16_t chunkIndex;
if ( rxRSSI > pointMaxRSSI ) // RSSI > maximum value for this point so far?
{
myActual[autoSweepStep] = rxRSSI; // Yes, save it
pointMaxRSSI = rxRSSI; // Added by G3ZQC - Remember new maximim
pointMaxRSSI = rxRSSI; // Added by G3ZQC - Remember new maximum
pointMaxFreq = oldSweepFreq;
}

26
cmd.cpp
View File

@ -44,6 +44,7 @@ extern bandpassFilter_t bandpassFilters[]; // RBW Setting data
extern int bpfCount; // Number of entries in "bandpassFilters"
extern int changedSetting; // Something in "setting" changed
extern uint16_t bpfCalibrate; // set true if a SI4432 bandpass filter calibration run is taking place
extern uint16_t tinySA_mode;
@ -94,9 +95,9 @@ extern uint32_t startFreq_IF; // Last value of the IF sweep start frequency
extern uint32_t stopFreq_IF; // Last value of the IF sweep end frequency
extern uint32_t sigFreq_IF; // Last value of the IF sweep end frequency
extern uint32_t startFreq_RX; // Last value of the IF sweep start frequency
extern uint32_t stopFreq_RX; // Last value of the IF sweep end frequency
extern uint32_t sigFreq_RX; // Last value of the IF sweep end frequency
extern uint32_t startFreq_RX; // Last value of the RX sweep start frequency
extern uint32_t stopFreq_RX; // Last value of the RX sweep end frequency
extern uint32_t sigFreq_RX; // Last value of the RX sweep end frequency
extern uint8_t showRSSI; // When true, RSSI readings are displayed
extern int initSweep; // Set by the "RSSI" command to restart the sweep
@ -191,6 +192,7 @@ extern uint8_t dBmToRSSI ( double dBm );
{ "TRACKOFF", MSG_TGOFF }, // turn off tracking generator output
{ "TRACKSIG", MSG_TGSIG }, // turn off tracking generator output
{ "TGFREQ", MSG_TGFREQ }, // Set Track gen freq for sig gen mode
{ "BPFCAL", MSG_BPFCAL }, // Start bandpass filter calibration
{ "", MSG_NONE } // Unrecognized command
};
@ -359,6 +361,8 @@ void ShowMenu ()
Serial.println ( " IFSIGNAL......Frequency of signal injected for IF Sweep (External or Ref)" );
Serial.println ( " BPFCAL........Start SI4432 bandpass filter calibration - RXSweep mode only");
Serial.println ();
}
@ -1779,10 +1783,21 @@ uint8_t reg69; // Ditto
SetExtGain( tempFloat );
DisplayInfo (); // Re display the scan
}
Serial.printf ( "External gain: %4.1f\n", setting.ExternalGain );
return true;
/*
* Start calibration of the SI4432 bandpass filters (ie different RBW)
* Valid only if already in RX Sweep mode
*/
case MSG_BPFCAL:
if ( setting.Mode == RX_SWEEP )
{
bpfCalibrate = true;
Serial.println("Starting bpf calibration");
return true;
}
return false;
default:
@ -2431,7 +2446,6 @@ int16_t tempBw;
if ( setting.Bandwidth10 != oldRBW )
{
changedSetting = true;
SetRXsweepSpan (setting.Bandwidth10 * 1000); // 10 * bandwidth
WriteSettings ();
}
}

1
cmd.h
View File

@ -85,6 +85,7 @@
#define MSG_TGOFF 56 // Turn Tracking Generator output off
#define MSG_TGFREQ 57 // Set Track Gen frequency for sig gen mode
#define MSG_TGSIG 58 // Set Track Gen sig gen mode
#define MSG_BPFCAL 59 // Start bandpass filter calibration
#define MSG_COLOURTEST 99 // test of waterfall colours - remove this when done!

View File

@ -1023,6 +1023,7 @@ function handleSettings (settings)
setTrackGen.disabled = true;
setTGFreq.disabled = true;
setTrackGenPower.disabled = true;
setActPower.disabled = true;
sigDiv.style.display = "none";
chartDiv.style.display = "block";
} else if (settings.mode == 4 ) { // IF Sweep (SAW test)
@ -1040,6 +1041,7 @@ function handleSettings (settings)
setTrackGen.disabled = true;
setTGFreq.disabled = true;
setTrackGenPower.disabled = true;
setActPower.disabled = true;
sigDiv.style.display = "none";
chartDiv.style.display = "block";
} else if (settings.mode == 7 ) { // BANDSCOPE
@ -1056,6 +1058,7 @@ function handleSettings (settings)
setSpur.disabled = true;
setTrackGen.disabled = true;
setTrackGenPower.disabled = true;
setActPower.disabled = true;
sigDiv.style.display = "none";
chartDiv.style.display = "block";
} else if (settings.mode == 2 ) { // Signal Generator
@ -1073,6 +1076,7 @@ function handleSettings (settings)
setTrackGen.disabled = true;
setTGFreq.disabled = true;
setTrackGenPower.disabled = true;
setActPower.disabled = true;
sigDiv.style.display = "block";
chartDiv.style.display = "none";
} else {
@ -1090,6 +1094,7 @@ function handleSettings (settings)
setTrackGen.disabled = false;
setTGFreq.disabled = false;
setTrackGenPower.disabled = false;
setActPower.disabled = false;
sigDiv.style.display = "none";
chartDiv.style.display = "block";
}

View File

@ -170,6 +170,10 @@
#define MIN_DRIVE 0
#define MAX_DRIVE 7
/*
* SI4432 MAx no of bandpass filters
*/
#define MAX_SI4432_FILTERS 57
/*
* The various operating modes:

View File

@ -141,6 +141,12 @@
* Output range of signal generator increased by also reducing SI4432 output power as well as uing attenuator
* Storage feature - temporary only not to disk - added to web page traces
* X grid lines added to web chart
*
* Version 0.11 (pending)
* Fix scaling for track gen frequency on web
* Axis Y2 on web chart is hidden if relevant traces not enabled
* Add self-calibrate
*
*/
@ -403,8 +409,11 @@ uint32_t stopFreq = 100000000; // Default stop frequency is 100MHz
uint32_t tempIF; // IF used for this sweep. Changes if Spur reduction is on
double dBadjust; // Sum of attenuation, external gain, calibration offset and RBW correction
uint16_t bpfCalibrate; // set true if a SI4432 bandpass filter calibration run is taking place
uint16_t bpfCount; // no of bandpass filters available
/*
* Variables for offset frequency tuning
* Variables for offset frequency tuning (used in Bandscope mode)
*/
int32_t offsetFreq; // Frequency offset from nominal setting
int16_t offsetStep; // increments by one at each reading
@ -677,6 +686,7 @@ bool fsStatus = false; // True if SPIFFS loads ok
bandwidth = rcvr.SetRBW ( setting.Bandwidth10, &delaytime ); // Set initial bandwidth and delaytime
SetRX ( 0 ); // RX in receive, LO in transmit
rcvr.SetPreampGain ( setting.PreampGain );
bpfCount = rcvr.GetBandpassFilterCount(); // no of RBW filters available
// If the tracking generator IF SI4432 is defined, then check to see if it is connected
@ -1224,6 +1234,8 @@ void doSigGenHigh ()
/*
* "SetRX" - Mode 3 is sig gen, 0 is normal (RX as receive, LO on), 1 is both
* receiving 2 not used

View File

@ -792,7 +792,7 @@ static DynamicJsonDocument jsonDocument ( capacity ); // buffer for json data to
jsonDocument["IF"] = setting.IF_Freq / 1000000.0;
jsonDocument["attenuation"] = setting.Attenuate;
jsonDocument["extGain"] = setting.ExternalGain;
jsonDocument["levelOffset"] = setting.LevelOffset;
jsonDocument["levelOffset"] = 0;
jsonDocument["setRBW"] = setting.Bandwidth10;
jsonDocument["bandwidth"] = bandwidth;
jsonDocument["RefOut"] = setting.ReferenceOut;