A7105 dynamic tuning on channel 15

This commit is contained in:
Pascal Langer 2018-01-04 14:37:05 +01:00
parent fabda76e98
commit 5cc49a8862
10 changed files with 157 additions and 53 deletions

View File

@ -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
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;
bfp = 0xffff + offset;
}
else
{
bip = 0x4b; // 2400 MHz (default)
bfp = (offset<<11)/1000;
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);
}

View File

@ -228,6 +228,9 @@ uint16_t ReadAFHDS2A()
static uint16_t packet_counter=0;
uint8_t data_rx;
uint16_t start;
#ifndef FORCE_AFHDS2A_TUNING
A7105_AdjustLOBaseFreq(1);
#endif
switch(phase)
{
case AFHDS2A_BIND1:

View File

@ -27,7 +27,7 @@ void InitFailsafe()
{
for(uint8_t i=0;i<NUM_CHN;i++)
Failsafe_data[i]=1024;
Failsafe_data[THROTTLE]=(uint16_t)FAILSAFE_THROTTLE_LOW_VAL; //0=-125%, 204=-100%
Failsafe_data[THROTTLE]=(uint16_t)FAILSAFE_THROTTLE_LOW_VAL; //1=-125%, 204=-100%
FAILSAFE_VALUES_on;
#ifdef FAILSAFE_SERIAL_ONLY
if(mode_select == MODE_SERIAL)
@ -35,6 +35,16 @@ void InitFailsafe()
#endif
}
#endif
void InitChannel()
{
for(uint8_t i=0;i<NUM_CHN;i++)
Channel_data[i]=1024;
#ifdef FAILSAFE_ENABLE
Channel_data[THROTTLE]=(uint16_t)FAILSAFE_THROTTLE_LOW_VAL; //0=-125%, 204=-100%
#else
Channel_data[THROTTLE]=204;
#endif
}
/************************/
/** Convert routines **/

View File

@ -157,12 +157,15 @@ static void __attribute__((unused)) flysky_build_packet(uint8_t init)
uint16_t ReadFlySky()
{
if (bind_counter)
#ifndef FORCE_FLYSKY_TUNING
A7105_AdjustLOBaseFreq(1);
#endif
if(IS_BIND_DONE)
{
flysky_build_packet(1);
A7105_WriteData(21, 1);
bind_counter--;
if (! bind_counter)
if (bind_counter==0)
BIND_DONE;
}
else

View File

@ -274,6 +274,9 @@ uint16_t ReadHubsan()
uint16_t delay;
uint8_t i;
#ifndef FORCE_HUBSAN_TUNING
A7105_AdjustLOBaseFreq(1);
#endif
switch(phase)
{
case BIND_1:

View File

@ -19,7 +19,7 @@
#define VERSION_MAJOR 1
#define VERSION_MINOR 2
#define VERSION_REVISION 0
#define VERSION_PATCH_LEVEL 4
#define VERSION_PATCH_LEVEL 5
//******************
// Protocols
//******************

View File

@ -76,6 +76,7 @@ uint8_t packet[40];
#define NUM_CHN 16
// Servo data
uint16_t Servo_data[NUM_CHN];
uint16_t Channel_data[NUM_CHN];
uint8_t Servo_AUX;
uint16_t servo_max_100,servo_min_100,servo_max_125,servo_min_125;
uint16_t servo_mid;
@ -364,6 +365,7 @@ void setup()
for(uint8_t i=0;i<NUM_CHN;i++)
Servo_data[i]=1500;
Servo_data[THROTTLE]=servo_min_100;
InitChannel();
#ifdef ENABLE_PPM
memcpy((void *)PPM_data,Servo_data, sizeof(Servo_data));
#endif
@ -1200,8 +1202,11 @@ void update_serial_data()
Failsafe_data[i]=temp; //value range 0..2047, 0=no pulses, 2047=hold
else
#endif
{
Channel_data[i]=temp; //value range 0..2047, 0=-125%, 2047=+125%
Servo_data[i]=(temp*5)/8+860; //value range 860<->2140 -125%<->+125%
}
}
RX_DONOTUPDATE_off;
#ifdef ORANGE_TX
cli();

View File

@ -52,6 +52,12 @@
#define SERIAL_MAX_125 2140 // 125%
#define SERIAL_MIN_125 860 // 125%
//Channel MIN MAX values
#define CHANNEL_MAX_100 1844 // 100%
#define CHANNEL_MIN_100 204 // 100%
#define CHANNEL_MAX_125 2047 // 125%
#define CHANNEL_MIN_125 0 // 125%
//PPM values used to compare
#define PPM_MIN_COMMAND 1250
#define PPM_SWITCH 1550

View File

@ -86,6 +86,32 @@
#error "The CORONA forced frequency tuning value is outside of the range -127..127."
#endif
#endif
#ifdef FORCE_FLYSKY_TUNING
#if ( FORCE_FLYSKY_TUNING < -300 ) || ( FORCE_FLYSKY_TUNING > 300 )
#error "The Flysky forced frequency tuning value is outside of the range -300..300."
#endif
#endif
#ifdef FORCE_HUBSAN_TUNING
#if ( FORCE_HUBSAN_TUNING < -300 ) || ( FORCE_HUBSAN_TUNING > 300 )
#error "The Hubsan forced frequency tuning value is outside of the range -300..300."
#endif
#endif
#ifdef FORCE_AFHDS2A_TUNING
#if ( FORCE_AFHDS2A_TUNING < -300 ) || ( FORCE_AFHDS2A_TUNING > 300 )
#error "The AFHDS2A forced frequency tuning value is outside of the range -300..300."
#endif
#endif
#ifndef USE_A7105_CH15_TUNING
#ifndef FORCE_FLYSKY_TUNING
#define FORCE_FLYSKY_TUNING 0
#endif
#ifndef FORCE_HUBSAN_TUNING
#define FORCE_HUBSAN_TUNING 0
#endif
#ifndef FORCE_AFHDS2A_TUNING
#define FORCE_AFHDS2A_TUNING 0
#endif
#endif
//Change/Force configuration if OrangeTX
#ifdef ORANGE_TX

View File

@ -25,6 +25,16 @@
//To enable this config file remove the // from the line below. It's automatically loaded if the file exists for the AVR platform but not STM32...
//#define USE_MY_CONFIG
/*************************/
/*** BOOTLOADER USE ***/
/*************************/
//Allow flashing multimodule directly with TX(erky9x or opentx modified firmwares)
//Instructions: https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/tree/master/BootLoaders#compiling--uploading-firmware-with-the-flash-from-tx-bootloader
//To enable this feature remove the "//" on the next line. Requires a compatible bootloader or upload method to be selected when you use the Multi 4-in-1 Boards Manager definitions.
//#define CHECK_FOR_BOOTLOADER
/*******************/
/*** TX SETTINGS ***/
/*******************/
@ -57,13 +67,6 @@
//The goal is to prevent binding other people's model when powering up the TX, changing model or scanning through protocols.
#define WAIT_FOR_BIND
/*************************/
/*** BOOTLOADER USE ***/
/*************************/
//Allow flashing multimodule directly with TX(erky9x or opentx modified firmwares)
//Instructions: https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/tree/master/BootLoaders#compiling--uploading-firmware-with-the-flash-from-tx-bootloader
//To enable this feature remove the "//" on the next line. Requires a compatible bootloader or upload method to be selected when you use the Multi 4-in-1 Boards Manager definitions.
//#define CHECK_FOR_BOOTLOADER
/****************/
/*** RF CHIPS ***/
@ -77,6 +80,36 @@
#define CC2500_INSTALLED
#define NRF24L01_INSTALLED
/** OrangeRX TX **/
//If you compile for the OrangeRX TX module you need to select the correct board type.
//By default the compilation is done for the GREEN board, to switch to a BLUE board uncomment the line below by removing the "//"
//#define ORANGE_TX_BLUE
/** CC2500 Fine Frequency Tuning **/
//For optimal performance the CC2500 RF module used by the FrSkyD, FrSkyV, FrSkyX, and SFHSS protocols needs to be tuned for each protocol.
//Initial tuning should be done via the radio menu with a genuine FrSky or Futaba receiver.
//Once a good tuning value is found it can be set here and will override the radio's 'option' setting for all existing and new models which use that protocol.
//For more information: https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/tree/master/docs/Frequency_Tuning.md
//Uncomment the lines below (remove the "//") and set an appropriate value (replace the "0") to enable. Valid range is -127 to +127.
//#define FORCE_FRSKYD_TUNING 0
//#define FORCE_FRSKYV_TUNING 0
//#define FORCE_FRSKYX_TUNING 0
//#define FORCE_SFHSS_TUNING 0
//#define FORCE_CORONA_TUNING 0
/** A7105 Fine Frequency Tuning **/
//This is required in rare cases where some A7105 modules and/or RXs have an inaccurate crystal oscillator.
//If using Serial mode only (for now), you can use CH15 to find the right tuning value. -100%=-300, 0%=default 0, +100%=+300.
//Uncomment the line below (remove the "//") to enable this feature.
//#define USE_A7105_CH15_TUNING
//Once a good tuning value is found it can be set here and will override the frequency tuning for a specific protocol.
//Uncomment the lines below (remove the "//") and set an appropriate value (replace the "0") to enable. Valid range is -300 to +300 and default is 0.
//#define FORCE_FLYSKY_TUNING 0
//#define FORCE_HUBSAN_TUNING 0
//#define FORCE_AFHDS2A_TUNING 0
/** Low Power **/
//Low power is reducing the transmit power of the multi module. This setting is configurable per model in PPM (table below) or Serial mode (radio GUI).
//It can be activated when flying indoor or small models since the distance is short or if a model is causing issues when flying closed to the TX.
//By default low power is completly disabled on all rf chips to prevent mistakes, but you can enable it by uncommenting the lines below:
@ -85,14 +118,6 @@
//#define CC2500_ENABLE_LOW_POWER
//#define NRF24L01_ENABLE_LOW_POWER
//Fine tune of the A7105 LO base frequency
// This is required for some A7105 modules and/or RXs with inaccurate crystal oscillator.
// The offset is in +/-kHz. Default value is 0.
#define A7105_FREQ_OFFSET 0
//If you compile for the OrangeRX TX module you need to select the correct board type.
//By default the compilation is done for the GREEN board, to switch to a BLUE board uncomment the line below by removing the "//"
//#define ORANGE_TX_BLUE
/*****************/
/*** GLOBAL ID ***/
@ -110,6 +135,7 @@
//Default is commented, you should uncoment only for test purpose or if you know exactly what you are doing!!!
//#define FORCE_CYRF_ID "\x12\x34\x56\x78\x9A\xBC"
/****************************/
/*** PROTOCOLS TO INCLUDE ***/
/****************************/
@ -182,19 +208,6 @@
// You can force option b. by uncommenting the line below (remove the "//").
//#define FAILSAFE_SERIAL_ONLY
/*******************************/
/*** CC2500 FREQUENCY TUNING ***/
/*******************************/
//For optimal performance the CC2500 RF module used by the FrSkyD, FrSkyV, FrSkyX, and SFHSS protocols needs to be tuned for each protocol.
//Initial tuning should be done via the radio menu with a genuine FrSky or Futaba receiver.
//Once a good tuning value is found it can be set here and will override the radio's 'option' setting for all existing and new models which use that protocol.
//For more information: https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/tree/master/docs/Frequency_Tuning.md
//Uncomment the lines below (remove the "//") and set an appropriate value (replace the "0") to enable. Valid range is -127 to +127.
//#define FORCE_FRSKYD_TUNING 0
//#define FORCE_FRSKYV_TUNING 0
//#define FORCE_FRSKYX_TUNING 0
//#define FORCE_SFHSS_TUNING 0
//#define FORCE_CORONA_TUNING 0
/**************************/
/*** TELEMETRY SETTINGS ***/
@ -236,6 +249,7 @@
//!This is a work in progress!
//#define SPORT_POLLING
/****************************/
/*** SERIAL MODE SETTINGS ***/
/****************************/
@ -246,6 +260,7 @@
//If you do not plan to use the Serial mode comment this line using "//" to save Flash space
#define ENABLE_SERIAL
/*************************/
/*** PPM MODE SETTINGS ***/
/*************************/
@ -253,7 +268,7 @@
//If you do not plan to use the PPM mode comment this line using "//" to save Flash space, you don't need to configure anything below in this case
#define ENABLE_PPM
/*** TX END POINTS ***/
/** TX END POINTS **/
//It is important for the module to know the endpoints of your radio.
//Below are some standard transmitters already preconfigured.
//Uncomment only the one which matches your transmitter.
@ -278,6 +293,7 @@
#define PPM_MIN_125 1000 // 125%
#endif
/** Number of PPM Channels **/
// The line below is used to set the minimum number of channels which the module should receive to consider a PPM frame valid.
// The default value is 4 to receive at least AETR for flying models but you could also connect the PPM from a car radio which has only 3 channels by changing this number to 3.
#define MIN_PPM_CHANNELS 4
@ -285,6 +301,7 @@
// The default value is 16 to receive all possible channels but you might want to filter some "bad" channels from the PPM frame like the ones above 6 on the Walkera PL0811.
#define MAX_PPM_CHANNELS 16
/** Dial Protocol Selector Settings **/
//The table below indicates which protocol to run when a specific position on the dial has been selected.
//All fields and values are explained below. Everything is configurable from here like in the Serial mode.
//Example: You can associate multiple times the same protocol to different dial positions to take advantage of the model match (RX_Num)