From 4f9f10ddf256c87474469498022625ffac1d8463 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Thu, 17 Nov 2016 12:08:44 +0100 Subject: [PATCH] Core: blinking pattern for PPM signal detection --- Multiprotocol/Multiprotocol.h | 7 +++++ Multiprotocol/Multiprotocol.ino | 56 +++++++++++++++++++++------------ Multiprotocol/Pins.h | 24 +++++++------- Multiprotocol/Telemetry.ino | 2 +- 4 files changed, 56 insertions(+), 33 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index ccd2624..2287943 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -211,12 +211,18 @@ struct PPM_Parameters #define TX_RX_PAUSE_on protocol_flags2 |= _BV(4) #define IS_TX_RX_PAUSE_on ( ( protocol_flags2 & _BV(4) ) !=0 ) #define IS_TX_PAUSE_on ( ( protocol_flags2 & (_BV(4)|_BV(3)) ) !=0 ) +//Signal OK +#define INPUT_SIGNAL_off protocol_flags2 &= ~_BV(5) +#define INPUT_SIGNAL_on protocol_flags2 |= _BV(5) +#define IS_INPUT_SIGNAL_on ( ( protocol_flags2 & _BV(5) ) !=0 ) +#define IS_INPUT_SIGNAL_off ( ( protocol_flags2 & _BV(5) ) ==0 ) //******************** //*** Blink timing *** //******************** #define BLINK_BIND_TIME 100 #define BLINK_SERIAL_TIME 500 +#define BLINK_PPM_TIME 1000 #define BLINK_BAD_PROTO_TIME_LOW 1000 #define BLINK_BAD_PROTO_TIME_HIGH 50 @@ -406,6 +412,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- DSM2_11 1 DSMX_22 2 DSMX_11 3 + DSM_AUTO 4 sub_protocol==YD717 YD717 0 SKYWLKR 1 diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 2d9b176..cc217ae 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -51,7 +51,7 @@ //Global constants/variables uint32_t MProtocol_id;//tx id, uint32_t MProtocol_id_master; -uint32_t blink=0; +uint32_t blink=0,last_signal=0; // uint16_t counter; uint8_t channel; @@ -452,9 +452,9 @@ void loop() void Update_All() { #ifdef ENABLE_SERIAL - if(mode_select==MODE_SERIAL && IS_RX_FLAG_on) // Serial mode and something has been received + if(mode_select==MODE_SERIAL && IS_RX_FLAG_on) // Serial mode and something has been received { - update_serial_data(); // Update protocol and data + update_serial_data(); // Update protocol and data update_aux_flags(); if(IS_CHANGE_PROTOCOL_FLAG_on) { // Protocol needs to be changed @@ -462,30 +462,35 @@ void Update_All() modules_reset(); //reset all modules protocol_init(); //init new protocol } + + INPUT_SIGNAL_on; //valid signal received + last_signal=millis(); } #endif //ENABLE_SERIAL #ifdef ENABLE_PPM - if(mode_select!=MODE_SERIAL && IS_PPM_FLAG_on) // PPM mode and a full frame has been received + if(mode_select!=MODE_SERIAL && IS_PPM_FLAG_on) // PPM mode and a full frame has been received { for(uint8_t i=0;iPPM_MAX_125) temp_ppm=PPM_MAX_125; Servo_data[i]= temp_ppm ; } update_aux_flags(); - PPM_FLAG_off; // wait for next frame before update + PPM_FLAG_off; // wait for next frame before update + INPUT_SIGNAL_on; //valid signal received + last_signal=millis(); } #endif //ENABLE_PPM - update_led_status(); #if defined(TELEMETRY) if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) ) TelemetryUpdate(); #endif + update_led_status(); } // Update Servo_AUX flags based on servo AUX positions @@ -500,10 +505,18 @@ static void update_aux_flags(void) // Update led status based on binding and serial static void update_led_status(void) { + if(IS_INPUT_SIGNAL_on) + if(millis()-last_signal>50) + INPUT_SIGNAL_off; //no valid signal (PPM or Serial) received for 50ms if(blink led on - else - blink+=BLINK_BIND_TIME; //blink fastly during binding + LED_off; //bind completed force led on + blink+=BLINK_BIND_TIME; //blink fastly during binding + } LED_toggle; } } @@ -1051,25 +1065,27 @@ static uint32_t random_id(uint16_t adress, uint8_t create_new) #endif #endif { // Interrupt on PPM pin - static int8_t chan=-1; + static int8_t chan=0,bad_frame=1; static uint16_t Prev_TCNT1=0; uint16_t Cur_TCNT1; Cur_TCNT1 = TCNT1 - Prev_TCNT1 ; // Capture current Timer1 value if(Cur_TCNT1<1000) - chan=-1; // bad frame + bad_frame=1; // bad frame else if(Cur_TCNT1>4840) - { - chan=0; // start of frame - PPM_FLAG_on; // full frame present (even at startup since PPM_data has been initialized) + { //start of frame + if(chan>3) + PPM_FLAG_on; // good frame received if at least 4 channels have been seen + chan=0; // reset channel counter + bad_frame=0; } else - if(chan!=-1) // need to wait for start of frame + 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;; if(chan++>=NUM_CHN) - chan=-1; // don't accept any new channels + bad_frame=1; // don't accept any new channels } Prev_TCNT1+=Cur_TCNT1; } diff --git a/Multiprotocol/Pins.h b/Multiprotocol/Pins.h index c163b38..9850055 100644 --- a/Multiprotocol/Pins.h +++ b/Multiprotocol/Pins.h @@ -211,25 +211,25 @@ #define BIND_pin PA0 #define LED_pin PA1 // - #define PPM_pin PA8 //PPM 5V tolerant + #define PPM_pin PA8 //PPM 5V tolerant // - #define S1_pin PA4 //Dial switch pins + #define S1_pin PA4 //Dial switch pins #define S2_pin PA5 #define S3_pin PA6 #define S4_pin PA7 // - #define PE1_pin PB4 //PE1 - #define PE2_pin PB5 //PE2 + #define PE1_pin PB4 //PE1 + #define PE2_pin PB5 //PE2 //CS pins - #define CC25_CSN_pin PB6 //CC2500 - #define NRF_CSN_pin PB7 //NRF24L01 - #define CYRF_RST_pin PB8 //CYRF RESET - #define A7105_CSN_pin PB9 //A7105 - #define CYRF_CSN_pin PB12 //CYRF CSN + #define CC25_CSN_pin PB6 //CC2500 + #define NRF_CSN_pin PB7 //NRF24L01 + #define CYRF_RST_pin PB8 //CYRF RESET + #define A7105_CSN_pin PB9 //A7105 + #define CYRF_CSN_pin PB12 //CYRF CSN //SPI pins - #define SCK_pin PB13 //SCK - #define SDO_pin PB14 //MISO - #define SDI_pin PB15 //MOSI + #define SCK_pin PB13 //SCK + #define SDO_pin PB14 //MISO + #define SDI_pin PB15 //MOSI // #define TX_INV_pin PB3 #define RX_INV_pin PB1 diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index de2808e..491b591 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -724,7 +724,7 @@ void Serial_write( uint8_t byte ) else { byteLo |= 0xFE ; // Stop bit - } + } byte <<= 1 ; #ifdef INVERT_SERIAL byte |= 1 ; // Start bit