diff --git a/Multiprotocol/Corona_cc2500.ino b/Multiprotocol/Corona_cc2500.ino index c3a46ee..8b2c7ff 100644 --- a/Multiprotocol/Corona_cc2500.ino +++ b/Multiprotocol/Corona_cc2500.ino @@ -104,6 +104,12 @@ static void __attribute__((unused)) CORONA_init() // 8 Channels with direct values from PPM static void __attribute__((unused)) CORONA_send_packet() { + // Tune frequency if it has been changed + if ( prev_option != option ) + { + CC2500_WriteReg(CC2500_0C_FSCTRL0, option); + prev_option = option ; + } if(IS_BIND_DONE) { if(state==0 || sub_protocol==COR_V1) @@ -124,12 +130,6 @@ static void __attribute__((unused)) CORONA_send_packet() packet[17] = 0x00; - // Tune frequency if it has been changed - if ( prev_option != option ) - { - CC2500_WriteReg(CC2500_0C_FSCTRL0, option); - prev_option = option ; - } // Packet period is based on hopping switch(hopping_frequency_no) { @@ -217,7 +217,7 @@ uint16_t ReadCORONA() uint16_t initCORONA() { if(sub_protocol==COR_V1) - bind_counter=700; // Stay in bind mode for 5s + bind_counter=1400; // Stay in bind mode for 5s else bind_counter=187; // Stay in bind mode for 5s state=400; // Used by V2 to send RF channels + ID for 2.65s at startup diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index c02a8e6..256dfd3 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -137,8 +137,11 @@ const uint8_t CH_EATR[]={ELEVATOR, AILERON, THROTTLE, RUDDER, AUX1, AUX2, AUX3, uint8_t mode_select; uint8_t protocol_flags=0,protocol_flags2=0; +#ifdef ENABLE_PPM // PPM variable volatile uint16_t PPM_data[NUM_CHN]; +volatile uint8_t PPM_chan_max=0; +#endif #if not defined (ORANGE_TX) && not defined (STM32_BOARD) //Random variable @@ -363,12 +366,17 @@ void setup() // Set default channels' value for(uint8_t i=0;iPPM_MAX_125) temp_ppm=PPM_MAX_125; + + uint16_t temp_ppm2; + temp_ppm2=map(temp_ppm,PPM_MIN_100,PPM_MAX_100,CHANNEL_MIN_100,CHANNEL_MAX_100); + if(temp_ppm2&0x8000) temp_ppm2=CHANNEL_MIN_125; + else if(temp_ppm2>CHANNEL_MAX_125) temp_ppm2=CHANNEL_MAX_125; + Channel_data[i]=temp_ppm2; + + temp_ppm>>=1; + if(temp_ppmPPM_MAX_125) temp_ppm=PPM_MAX_125; Servo_data[i]= temp_ppm ; } PPM_FLAG_off; // wait for next frame before update @@ -1525,20 +1541,23 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) uint16_t Cur_TCNT1; Cur_TCNT1 = TCNT1 - Prev_TCNT1 ; // Capture current Timer1 value - if(Cur_TCNT1<1000) + if(Cur_TCNT1<1600) bad_frame=1; // bad frame else - if(Cur_TCNT1>4840) + if(Cur_TCNT1>4400) { //start of frame if(chan>=MIN_PPM_CHANNELS) + { PPM_FLAG_on; // good frame received if at least 4 channels have been seen + if(chan>PPM_chan_max) PPM_chan_max=chan; // Saving the number of channels received + } chan=0; // reset channel counter bad_frame=0; } else if(bad_frame==0) // need to wait for start of frame - { //servo values between 500us and 2420us will end up here - PPM_data[chan]= Cur_TCNT1>>1;; + { //servo values between 800us and 2200us will end up here + PPM_data[chan]=Cur_TCNT1; if(chan++>=MAX_PPM_CHANNELS) bad_frame=1; // don't accept any new channels }