From 2c9693389e1934b827c1d2d1aa88bb57a86973be Mon Sep 17 00:00:00 2001 From: Pascal Langer Date: Thu, 1 Aug 2019 14:23:08 +0200 Subject: [PATCH] Fix DSM telemetry and global cyrf6936 freq tunning - Fixed DSM telemetry with some RXs (R720X) - Global frequency tunning for all protocols using the CYRF6936 by adjusting channel 15 when enabled - Changed default DSM_THROTTLE_KILL_CH to use channel 14 --- Multiprotocol/CYRF6936_SPI.ino | 11 +++++++++++ Multiprotocol/Common.ino | 2 +- Multiprotocol/DSM_cyrf6936.ino | 11 ++++++++--- Multiprotocol/Multiprotocol.h | 5 +++-- Multiprotocol/Multiprotocol.ino | 2 +- Multiprotocol/TX_Def.h | 35 +++++++++++++++++---------------- Multiprotocol/Validate.h | 6 +++++- Multiprotocol/WFLY_cyrf6936.ino | 13 ------------ Multiprotocol/_Config.h | 6 +++--- Protocols_Details.md | 18 ++++++++++------- 10 files changed, 61 insertions(+), 48 deletions(-) diff --git a/Multiprotocol/CYRF6936_SPI.ino b/Multiprotocol/CYRF6936_SPI.ino index 20136b8a8..63f45026c 100644 --- a/Multiprotocol/CYRF6936_SPI.ino +++ b/Multiprotocol/CYRF6936_SPI.ino @@ -152,6 +152,17 @@ void CYRF_SetPower(uint8_t val) CYRF_WriteRegister(CYRF_03_TX_CFG,power); prev_power=power; } + + #ifdef USE_CYRF6936_CH15_TUNING + static uint16_t Channel15=1024; + if(Channel15!=Channel_data[CH15]) + { // adjust frequency + Channel15=Channel_data[CH15]+0x155; // default value is 0x555 = 0x400 + 0x155 + CYRF_WriteRegister(CYRF_1B_TX_OFFSET_LSB, Channel15&0xFF); + CYRF_WriteRegister(CYRF_1C_TX_OFFSET_MSB, Channel15>>8); + Channel15-=0x155; + } + #endif } /* diff --git a/Multiprotocol/Common.ino b/Multiprotocol/Common.ino index c5525a1cc..5b0c6d98b 100644 --- a/Multiprotocol/Common.ino +++ b/Multiprotocol/Common.ino @@ -70,7 +70,7 @@ uint8_t convert_channel_8b_limit_deadband(uint8_t num,uint8_t min,uint8_t mid, u return val; } -// Revert a channel and store it +// Reverse a channel and store it void reverse_channel(uint8_t num) { uint16_t val=2048-Channel_data[num]; diff --git a/Multiprotocol/DSM_cyrf6936.ino b/Multiprotocol/DSM_cyrf6936.ino index 759e703b9..faea63759 100644 --- a/Multiprotocol/DSM_cyrf6936.ino +++ b/Multiprotocol/DSM_cyrf6936.ino @@ -375,9 +375,13 @@ static uint8_t __attribute__((unused)) DSM_Check_RX_packet() uint16_t ReadDsm() { -#define DSM_CH1_CH2_DELAY 4010 // Time between write of channel 1 and channel 2 -#define DSM_WRITE_DELAY 1950 // Time after write to verify write complete -#define DSM_READ_DELAY 600 // Time before write to check read phase, and switch channels. Was 400 but 600 seems what the 328p needs to read a packet + #define DSM_CH1_CH2_DELAY 4010 // Time between write of channel 1 and channel 2 + #ifdef STM32_BOARD + #define DSM_WRITE_DELAY 1500 // Time after write to verify write complete + #else + #define DSM_WRITE_DELAY 1950 // Time after write to verify write complete + #endif + #define DSM_READ_DELAY 600 // Time before write to check read phase, and switch channels. Was 400 but 600 seems what the 328p needs to read a packet #if defined DSM_TELEMETRY uint8_t rx_phase; uint8_t len; @@ -464,6 +468,7 @@ uint16_t ReadDsm() while ((uint8_t)((uint8_t)micros()-(uint8_t)start) < 100) // Wait max 100µs, max I've seen is 50µs if((CYRF_ReadRegister(CYRF_02_TX_CTRL) & 0x80) == 0x00) break; + if(phase==DSM_CH1_CHECK_A || phase==DSM_CH1_CHECK_B) { #if defined DSM_TELEMETRY diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 5a44ea8e9..ba5dfb882 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 2 #define VERSION_REVISION 1 -#define VERSION_PATCH_LEVEL 67 +#define VERSION_PATCH_LEVEL 68 //****************** // Protocols @@ -395,10 +395,11 @@ enum MultiPacketTypes #define debug(msg, ...) {char debug_buf[64]; sprintf(debug_buf, msg, ##__VA_ARGS__); Serial.write(debug_buf);} #define debugln(msg, ...) {char debug_buf[64]; sprintf(debug_buf, msg "\r\n", ##__VA_ARGS__); Serial.write(debug_buf);} #define debug_time(msg) { uint16_t debug_time_TCNT1=TCNT1; debug_time=debug_time_TCNT1-debug_time; debug(msg "%u", debug_time>>1); debug_time=debug_time_TCNT1; } + #define debugln_time(msg) { uint16_t debug_time_TCNT1=TCNT1; debug_time=debug_time_TCNT1-debug_time; debug(msg "%u\r\n", debug_time>>1); debug_time=debug_time_TCNT1; } #else #define debug(...) { } #define debugln(...) { } - #define debug_time(...) { } + #define debugln_time(...) { } #undef DEBUG_SERIAL #endif diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 1156b1262..a2dd0db92 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -398,7 +398,7 @@ void setup() #endif // Read or create protocol id - MProtocol_id_master=random_id(10,false); + MProtocol_id_master=random_id(EEPROM_ID_OFFSET,false); debugln("Module Id: %lx", MProtocol_id_master); diff --git a/Multiprotocol/TX_Def.h b/Multiprotocol/TX_Def.h index 91c49a8be..0a4726349 100644 --- a/Multiprotocol/TX_Def.h +++ b/Multiprotocol/TX_Def.h @@ -47,6 +47,24 @@ #define CHANNEL_MAX_COMMAND 1424 // 1750us //Channel definitions +#define CH1 0 +#define CH2 1 +#define CH3 2 +#define CH4 3 +#define CH5 4 +#define CH6 5 +#define CH7 6 +#define CH8 7 +#define CH9 8 +#define CH10 9 +#define CH11 10 +#define CH12 11 +#define CH13 12 +#define CH14 13 +#define CH15 14 +#define CH16 15 + +//Channel order #ifdef AETR #define AILERON 0 #define ELEVATOR 1 @@ -194,20 +212,3 @@ #define THROTTLE 1 #define RUDDER 0 #endif - -#define CH1 0 -#define CH2 1 -#define CH3 2 -#define CH4 3 -#define CH5 4 -#define CH6 5 -#define CH7 6 -#define CH8 7 -#define CH9 8 -#define CH10 9 -#define CH11 10 -#define CH12 11 -#define CH13 12 -#define CH14 13 -#define CH15 14 -#define CH16 15 diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index 75f82c088..0346e2420 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -18,7 +18,7 @@ #endif #endif -// Check for minimum version of multi-module boards +// Check for minimum board file definition version for DIY multi-module boards #define MIN_AVR_BOARD 107 #define MIN_ORX_BOARD 107 #define MIN_STM32_BOARD 114 @@ -124,6 +124,10 @@ #endif #endif +#if defined (USE_CYRF6936_CH15_TUNING) && (DSM_THROTTLE_KILL_CH == 15) + #error "Error Channel 15 conflict between the CYRF6936 freq tuning and the DSM throttle kill feature." +#endif + //Change/Force configuration if OrangeTX #ifdef ORANGE_TX #undef ENABLE_PPM // Disable PPM for OrangeTX module diff --git a/Multiprotocol/WFLY_cyrf6936.ino b/Multiprotocol/WFLY_cyrf6936.ino index e62102c95..baacbcd9c 100644 --- a/Multiprotocol/WFLY_cyrf6936.ino +++ b/Multiprotocol/WFLY_cyrf6936.ino @@ -80,9 +80,6 @@ static void __attribute__((unused)) WFLY_cyrf_data_config() static uint16_t __attribute__((unused)) WFLY_send_data_packet() { - #ifdef USE_CYRF6936_CH15_TUNING - static uint16_t Channel15=1024; - #endif packet_count++; packet[0] = rx_tx_addr[2]; packet[1] = rx_tx_addr[3]; @@ -137,16 +134,6 @@ static uint16_t __attribute__((unused)) WFLY_send_data_packet() sum += packet[i]; packet[len] = sum; - #ifdef USE_CYRF6936_CH15_TUNING - if(Channel15!=Channel_data[CH15]) - { // adjust frequency - Channel15=Channel_data[CH15]+0x155; // default value is 0x555 = 0x400 + 0x155 - CYRF_WriteRegister(CYRF_1B_TX_OFFSET_LSB, Channel15&0xFF); - CYRF_WriteRegister(CYRF_1C_TX_OFFSET_MSB, Channel15>>8); - Channel15-=0x155; - } - #endif - CYRF_ConfigRFChannel(hopping_frequency[(packet_count)%4]); CYRF_SetPower(0x08); CYRF_WriteDataPacketLen(packet, len+1); diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index b39f7ea18..6358f627f 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -222,10 +222,10 @@ // For more throw, 1024..1976us @100% and 904..2096us @125%, remove the "//" on the line below. Be aware that too much throw can damage some UMX servos. To achieve standard throw in this mode use a channel weight of 84%. //#define DSM_MAX_THROW //Some models (X-Vert, Blade 230S...) require a special value to instant stop the motor(s). -// You can disable this feature by adding "//" on the line below. You have to specify which channel (15 by default) will be used to kill the throttle channel. -// If the channel 15 is above -50% the throttle is untouched but if it is between -50% and -100%, the throttle output will be forced between -100% and -150%. +// You can disable this feature by adding "//" on the line below. You have to specify which channel (14 by default) will be used to kill the throttle channel. +// If the channel 14 is above -50% the throttle is untouched but if it is between -50% and -100%, the throttle output will be forced between -100% and -150%. // For example, a value of -80% applied on channel 15 will instantly kill the motors on the X-Vert. -#define DSM_THROTTLE_KILL_CH 15 +#define DSM_THROTTLE_KILL_CH 14 //AFHDS2A specific settings //------------------------- diff --git a/Protocols_Details.md b/Protocols_Details.md index 6892ddd4b..b833a2951 100644 --- a/Protocols_Details.md +++ b/Protocols_Details.md @@ -123,6 +123,8 @@ Traxxas|43|Traxxas||||||||NRF24L01 # A7105 RF Module +If USE_A7105_CH15_TUNING is enabled, the value of channel 15 is used by all A7105 protocols for tuning the frequency. This is required in rare cases where some A7105 modules and/or RXs have an inaccurate crystal oscillator. + ## FLYSKY - *1* Extended limits supported @@ -372,12 +374,14 @@ A|E|T|R|CH5|CH6|CH7|CH8 *** # CYRF6936 RF Module +If USE_CYRF6936_CH15_TUNING is enabled, the value of channel 15 is used by all CYRF6936 protocols for tuning the frequency. This is required in rare cases where some CYRF6936 modules and/or RXs have an inaccurate crystal oscillator. + ## DEVO - *7* Extended limits and failsafe supported -CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8 ----|---|---|---|---|---|---|--- -A|E|T|R|CH5|CH6|CH7|CH8 +CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12 +---|---|---|---|---|---|---|---|---|---|---|--- +A|E|T|R|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12 Note that the RX ouput will be EATR. @@ -483,16 +487,16 @@ Telemetry enabled for TSSI and plugins option=number of channels from 4 to 12. An invalid option value will end up with 6 channels. -CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12|----|----|CH15 ----|---|---|---|---|---|---|---|---|----|----|----|----|----|---- -A|E|T|R|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12|----|----|TH_KILL +CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12|----|CH14 +---|---|---|---|---|---|---|---|---|----|----|----|----|---- +A|E|T|R|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12|----|TH_KILL Notes: - model/type/number of channels indicated on the RX can be different from what the RX is in fact wanting to see. So don't hesitate to test different combinations until you have something working. Using Auto is the best way to find these settings. - RX output will match the Spektrum standard TAER independently of the input configuration AETR, RETA... - RX output will match the Spektrum standard throw (1500µs +/- 400µs -> 1100..1900µs) for a 100% input. This is true for both Serial and PPM input. For PPM, make sure the end points PPM_MIN_100 and PPM_MAX_100 in _config.h are matching your TX ouput. The maximum ouput is 1000..2000µs based on an input of 125%. - If you want to override the above and get maximum throw (old way) uncomment in _config.h the line #define DSM_MAX_THROW . In this mode to achieve standard throw use a channel weight of 84%. - - TH_KILL is a feature which is enabled on channel 15 by default (can be disabled/changed) in the _config.h file. Some models (X-Vert, Blade 230S...) require a special position to instant stop the motor(s). If the channel 15 is above -50% the throttle is untouched but if it is between -50% and -100%, the throttle output will be forced between -100% and -150%. For example, a value of -80% applied on channel 15 will instantly kill the motors on the X-Vert. + - TH_KILL is a feature which is enabled on channel 14 by default (can be disabled/changed) in the _config.h file. Some models (X-Vert, Blade 230S...) require a special position to instant stop the motor(s). If the channel 15 is above -50% the throttle is untouched but if it is between -50% and -100%, the throttle output will be forced between -100% and -150%. For example, a value of -80% applied on channel 14 will instantly kill the motors on the X-Vert. ### Sub_protocol DSM2_22 - *0* DSM2, Resolution 1024, refresh rate 22ms