mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-12-18 23:03:15 +00:00
A7105 dynamic tuning on channel 15
This commit is contained in:
@@ -168,27 +168,58 @@ void A7105_Strobe(uint8_t address) {
|
||||
|
||||
// Fine tune A7105 LO base frequency
|
||||
// this is required for some A7105 modules and/or RXs with inaccurate crystal oscillator
|
||||
// arg: offset in +/-kHz
|
||||
void A7105_AdjustLOBaseFreq(int16_t offset)
|
||||
void A7105_AdjustLOBaseFreq(uint8_t cmd)
|
||||
{
|
||||
static int16_t old_offset=2048;
|
||||
int16_t offset=1024;
|
||||
if(cmd==0)
|
||||
{ // Called at init of the A7105
|
||||
old_offset=2048;
|
||||
switch(protocol)
|
||||
{
|
||||
case MODE_HUBSAN:
|
||||
#ifdef FORCE_HUBSAN_TUNING
|
||||
offset=(int16_t)FORCE_HUBSAN_TUNING;
|
||||
#endif
|
||||
break;
|
||||
case MODE_FLYSKY:
|
||||
#ifdef FORCE_FLYSKY_TUNING
|
||||
offset=(int16_t)FORCE_FLYSKY_TUNING;
|
||||
#endif
|
||||
break;
|
||||
case MODE_AFHDS2A:
|
||||
#ifdef FORCE_AFHDS2A_TUNING
|
||||
offset=(int16_t)FORCE_AFHDS2A_TUNING;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(offset==1024) // Use channel 15 as an input
|
||||
offset=map(Channel_data[14],CHANNEL_MIN_100,CHANNEL_MAX_100,-300,300);
|
||||
|
||||
if(old_offset==offset) // offset is the same as before...
|
||||
return;
|
||||
old_offset=offset;
|
||||
|
||||
// LO base frequency = 32e6*(bip+(bfp/(2^16)))
|
||||
uint8_t bip; // LO base frequency integer part
|
||||
uint32_t bfp; // LO base frequency fractional part
|
||||
uint8_t bip; // LO base frequency integer part
|
||||
uint16_t bfp; // LO base frequency fractional part
|
||||
offset++; // as per datasheet, not sure why recommended, but that's a +1kHz drift only ...
|
||||
offset<<=1;
|
||||
if(offset < 0)
|
||||
{
|
||||
bip = 0x4a; // 2368 MHz
|
||||
bfp = 0xffff+((offset<<11)/1000)+1;
|
||||
bip = 0x4a; // 2368 MHz
|
||||
bfp = 0xffff + offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
bip = 0x4b; // 2400 MHz (default)
|
||||
bfp = (offset<<11)/1000;
|
||||
bip = 0x4b; // 2400 MHz (default)
|
||||
bfp = offset;
|
||||
}
|
||||
if(offset == 0)
|
||||
bfp = 0x0002; // as per datasheet, not sure why recommended, but that's a +1kHz drift only ...
|
||||
A7105_WriteReg( A7105_11_PLL_III, bip);
|
||||
A7105_WriteReg( A7105_12_PLL_IV, (bfp >> 8) & 0xff);
|
||||
A7105_WriteReg( A7105_13_PLL_V, bfp & 0xff);
|
||||
//debugln("Channel: %d, offset: %d, bip: %2x, bfp: %4x", Channel_data[14], offset, bip, bfp);
|
||||
}
|
||||
|
||||
|
||||
@@ -294,7 +325,7 @@ void A7105_Init(void)
|
||||
A7105_SetTxRxMode(TX_EN);
|
||||
A7105_SetPower();
|
||||
|
||||
A7105_AdjustLOBaseFreq(A7105_FREQ_OFFSET);
|
||||
A7105_AdjustLOBaseFreq(0);
|
||||
|
||||
A7105_Strobe(A7105_STANDBY);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user