SetOffsetFreq function

This commit is contained in:
M0WID 2020-08-18 22:21:11 +01:00
parent be199ef50c
commit 1cb4cdef6e
3 changed files with 67 additions and 8 deletions

View File

@ -87,9 +87,32 @@ void initBandscope()
/*
* This function section handles the fast bandscope sweep
* The display is split and shows a waterfall
* Number of points is reduced, and frequency change is done using an offset to aallow the delay time between
* changing frequency and taking a reading to be reduced
* The display is split and shows a waterfall.
* The number of points is reduced, and frequency change is done using an offset to allow the
* delay time between changing frequency and taking a reading to be reduced.
*
* Frequency scheme:
* When the LO frequency is < 480MHz the LO can be adjusted +- 80kHz from the
* nominal frequency in 156.25Hz steps.
* If the LO is above 480MHz the the adjustment is +-160kHz in 312.5Hz steps.
* If the IF is 434MHz then 480MHz -> 46Mhz for the signal being analysed, so fine
* for most of the HF bands.
*
* In bandscope mode the RBW is fixed at the minimum 2.6kHz, span at 200kHz and
* there are 80 data points
*
* 200kHz -> 2.5kHz steps between each reading or 16 * 156.25Hz if in low band
*
* Start by setting the LO to the frequency for the start of the sweep plus 80kHz
* and set the offset value at -80kHz.
* At each reading increment the offset value by 16 (8 in high band).
* In this mode the delay time between reading is set at a shorter value than
* normally used by the RBW as the LO does not turn off at each change in offset, unlike
* a normal frequency change.
* When the offset value reaches +80kHz then we need to reset the LO (using normal delaytime)
* and continue until we get to the end of the sweep.
*
*
*/

View File

@ -444,7 +444,7 @@ uint8_t registerBuf[4]; // Used to send frequency data in burst mode
/*
* "SetOffset" adjusts the frequency from the nominal value set in SetFrequency.
* "SetOffsetFreq" adjusts the frequency from the nominal value set in SetFrequency.
* It is intended for use by the SI4432 AFC algorithm to enable more accurate
* frequency matching of different radios, but we can turn off the AFC and use it
* to adjust the frequency without having the Si4432 go through its TX-RX-TX state machine
@ -452,6 +452,43 @@ uint8_t registerBuf[4]; // Used to send frequency data in burst mode
* The offset can vary +- 80kHz in low bands (f<480MHz) and +-160kHz in high bands (480-960MHz)
* negative numbers are twos complement of the positive offset
*/
void Si4432::SetOffsetFreq ( int32_t freq )
{
uint8_t registerBuf[3]; // Used to send data in burst mode
uint32_t posFreq;
if (freq < 0)
posFreq = -freq;
else
posFreq = freq;
uint16_t fo = (double)posFreq/(156.25 * (double)(_hbsel + 1));
if (freq < 0)
// do twos complement - invert the bits (0-8) (use XOR) and add one
fo = (fo ^ 0x3F) + 1;
Serial.printf(" offset frequency %i fo=%3x \n", freq, fo);
// write to the Si4432
registerBuf[0] = REG_FOFF1|0x80; // First register in write mode (bit 7 set)
registerBuf[1] = fo & 0xFF; // first 8 bits
registerBuf[2] = (fo >> 8 ) & 0x03; // last 2 bits
//_spi->beginTransaction ( SPISettings ( BUS_SPEED, BUS_ORDER, BUS_MODE ));
// spiSimpleTransaction(_spi->bus());
digitalWrite ( _cs, LOW ); // Select the correct device
_spi->transfer ( registerBuf, 3 ); // Send the data
digitalWrite ( _cs, HIGH ); // Deselect the device
//_spi->endTransaction();
}
/*
* "SetOffset" sets the frequency offset registers to correspond to the number of offset steps
*/
void Si4432::SetOffset ( int32_t offset )
{
uint8_t registerBuf[3]; // Used to send data in burst mode
@ -462,7 +499,7 @@ void Si4432::SetOffset ( int32_t offset )
else
posOffset = offset;
uint16_t fo = (double)offset/(156.25 * (double)(_hbsel + 1));
uint16_t fo = posOffset;
if (offset < 0)
// do twos complement - invert the bits (0-8) (use XOR) and add one
@ -485,8 +522,6 @@ void Si4432::SetOffset ( int32_t offset )
}
/*
* "SetRBW" Sets the "Resolution Bandwidth" based on a required value passed in
* and returns the actual value chosen as well as the required delay to allow the

View File

@ -178,7 +178,8 @@ void SetFrequency ( uint32_t Freq ); // Set module's frequency
uint32_t GetFrequency (); // Get the module's frequency
uint32_t ReadFrequency (); // Read frequency from SI4432
void SetOffset ( int32_t offset ); // Set a frequency offset from the nominal frequency
void SetOffsetFreq ( int32_t freq ); // Set a frequency offset from the nominal frequency
void SetOffset ( int32_t offset ); // Offset based on number of offset increments
void SetPowerReference ( int freq ); // Set the GPIO output for the LO
void SetDrive ( uint8_t level ); // Sets the drive level