Skip to content

Commit

Permalink
Fix DSM telemetry and global cyrf6936 freq tunning
Browse files Browse the repository at this point in the history
 - 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
  • Loading branch information
Pascal Langer committed Aug 1, 2019
1 parent d3c82c4 commit 2c96933
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 48 deletions.
11 changes: 11 additions & 0 deletions Multiprotocol/CYRF6936_SPI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/*
Expand Down
2 changes: 1 addition & 1 deletion Multiprotocol/Common.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
11 changes: 8 additions & 3 deletions Multiprotocol/DSM_cyrf6936.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Multiprotocol/Multiprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Multiprotocol/Multiprotocol.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
35 changes: 18 additions & 17 deletions Multiprotocol/TX_Def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 5 additions & 1 deletion Multiprotocol/Validate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions Multiprotocol/WFLY_cyrf6936.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions Multiprotocol/_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
//-------------------------
Expand Down
18 changes: 11 additions & 7 deletions Protocols_Details.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2c96933

Please sign in to comment.