Core: blinking pattern for PPM signal detection

This commit is contained in:
pascallanger 2016-11-17 12:08:44 +01:00
parent 6fe3f90a26
commit 4f9f10ddf2
4 changed files with 56 additions and 33 deletions

View File

@ -211,12 +211,18 @@ struct PPM_Parameters
#define TX_RX_PAUSE_on protocol_flags2 |= _BV(4) #define TX_RX_PAUSE_on protocol_flags2 |= _BV(4)
#define IS_TX_RX_PAUSE_on ( ( protocol_flags2 & _BV(4) ) !=0 ) #define IS_TX_RX_PAUSE_on ( ( protocol_flags2 & _BV(4) ) !=0 )
#define IS_TX_PAUSE_on ( ( protocol_flags2 & (_BV(4)|_BV(3)) ) !=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 *** //*** Blink timing ***
//******************** //********************
#define BLINK_BIND_TIME 100 #define BLINK_BIND_TIME 100
#define BLINK_SERIAL_TIME 500 #define BLINK_SERIAL_TIME 500
#define BLINK_PPM_TIME 1000
#define BLINK_BAD_PROTO_TIME_LOW 1000 #define BLINK_BAD_PROTO_TIME_LOW 1000
#define BLINK_BAD_PROTO_TIME_HIGH 50 #define BLINK_BAD_PROTO_TIME_HIGH 50
@ -406,6 +412,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
DSM2_11 1 DSM2_11 1
DSMX_22 2 DSMX_22 2
DSMX_11 3 DSMX_11 3
DSM_AUTO 4
sub_protocol==YD717 sub_protocol==YD717
YD717 0 YD717 0
SKYWLKR 1 SKYWLKR 1

View File

@ -51,7 +51,7 @@
//Global constants/variables //Global constants/variables
uint32_t MProtocol_id;//tx id, uint32_t MProtocol_id;//tx id,
uint32_t MProtocol_id_master; uint32_t MProtocol_id_master;
uint32_t blink=0; uint32_t blink=0,last_signal=0;
// //
uint16_t counter; uint16_t counter;
uint8_t channel; uint8_t channel;
@ -452,9 +452,9 @@ void loop()
void Update_All() void Update_All()
{ {
#ifdef ENABLE_SERIAL #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(); update_aux_flags();
if(IS_CHANGE_PROTOCOL_FLAG_on) if(IS_CHANGE_PROTOCOL_FLAG_on)
{ // Protocol needs to be changed { // Protocol needs to be changed
@ -462,30 +462,35 @@ void Update_All()
modules_reset(); //reset all modules modules_reset(); //reset all modules
protocol_init(); //init new protocol protocol_init(); //init new protocol
} }
INPUT_SIGNAL_on; //valid signal received
last_signal=millis();
} }
#endif //ENABLE_SERIAL #endif //ENABLE_SERIAL
#ifdef ENABLE_PPM #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;i<NUM_CHN;i++) for(uint8_t i=0;i<NUM_CHN;i++)
{ // update servo data without interrupts to prevent bad read in protocols { // update servo data without interrupts to prevent bad read in protocols
uint16_t temp_ppm ; uint16_t temp_ppm ;
cli(); // disable global int cli(); // disable global int
temp_ppm = PPM_data[i] ; temp_ppm = PPM_data[i] ;
sei(); // enable global int sei(); // enable global int
if(temp_ppm<PPM_MIN_125) temp_ppm=PPM_MIN_125; if(temp_ppm<PPM_MIN_125) temp_ppm=PPM_MIN_125;
else if(temp_ppm>PPM_MAX_125) temp_ppm=PPM_MAX_125; else if(temp_ppm>PPM_MAX_125) temp_ppm=PPM_MAX_125;
Servo_data[i]= temp_ppm ; Servo_data[i]= temp_ppm ;
} }
update_aux_flags(); 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 #endif //ENABLE_PPM
update_led_status();
#if defined(TELEMETRY) #if defined(TELEMETRY)
if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) ) if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) )
TelemetryUpdate(); TelemetryUpdate();
#endif #endif
update_led_status();
} }
// Update Servo_AUX flags based on servo AUX positions // 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 // Update led status based on binding and serial
static void update_led_status(void) 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<millis()) if(blink<millis())
{ {
if(cur_protocol[1]==0) //No valid serial received at least once if(IS_INPUT_SIGNAL_off)
blink+=BLINK_SERIAL_TIME; //blink slowly while waiting a valid serial input {
if(mode_select==MODE_SERIAL)
blink+=BLINK_SERIAL_TIME; //blink slowly if no valid serial input
else
blink+=BLINK_PPM_TIME; //blink more slowly if no valid PPM input
}
else else
if(remote_callback == 0) if(remote_callback == 0)
{ // Invalid protocol { // Invalid protocol
@ -513,10 +526,11 @@ static void update_led_status(void)
blink+=BLINK_BAD_PROTO_TIME_HIGH; blink+=BLINK_BAD_PROTO_TIME_HIGH;
} }
else else
{
if(IS_BIND_DONE_on) if(IS_BIND_DONE_on)
LED_off; //bind completed -> led on LED_off; //bind completed force led on
else blink+=BLINK_BIND_TIME; //blink fastly during binding
blink+=BLINK_BIND_TIME; //blink fastly during binding }
LED_toggle; LED_toggle;
} }
} }
@ -1051,25 +1065,27 @@ static uint32_t random_id(uint16_t adress, uint8_t create_new)
#endif #endif
#endif #endif
{ // Interrupt on PPM pin { // Interrupt on PPM pin
static int8_t chan=-1; static int8_t chan=0,bad_frame=1;
static uint16_t Prev_TCNT1=0; static uint16_t Prev_TCNT1=0;
uint16_t Cur_TCNT1; uint16_t Cur_TCNT1;
Cur_TCNT1 = TCNT1 - Prev_TCNT1 ; // Capture current Timer1 value Cur_TCNT1 = TCNT1 - Prev_TCNT1 ; // Capture current Timer1 value
if(Cur_TCNT1<1000) if(Cur_TCNT1<1000)
chan=-1; // bad frame bad_frame=1; // bad frame
else else
if(Cur_TCNT1>4840) if(Cur_TCNT1>4840)
{ { //start of frame
chan=0; // start of frame if(chan>3)
PPM_FLAG_on; // full frame present (even at startup since PPM_data has been initialized) PPM_FLAG_on; // good frame received if at least 4 channels have been seen
chan=0; // reset channel counter
bad_frame=0;
} }
else 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 { //servo values between 500us and 2420us will end up here
PPM_data[chan]= Cur_TCNT1>>1;; PPM_data[chan]= Cur_TCNT1>>1;;
if(chan++>=NUM_CHN) 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; Prev_TCNT1+=Cur_TCNT1;
} }

View File

@ -211,25 +211,25 @@
#define BIND_pin PA0 #define BIND_pin PA0
#define LED_pin PA1 #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 S2_pin PA5
#define S3_pin PA6 #define S3_pin PA6
#define S4_pin PA7 #define S4_pin PA7
// //
#define PE1_pin PB4 //PE1 #define PE1_pin PB4 //PE1
#define PE2_pin PB5 //PE2 #define PE2_pin PB5 //PE2
//CS pins //CS pins
#define CC25_CSN_pin PB6 //CC2500 #define CC25_CSN_pin PB6 //CC2500
#define NRF_CSN_pin PB7 //NRF24L01 #define NRF_CSN_pin PB7 //NRF24L01
#define CYRF_RST_pin PB8 //CYRF RESET #define CYRF_RST_pin PB8 //CYRF RESET
#define A7105_CSN_pin PB9 //A7105 #define A7105_CSN_pin PB9 //A7105
#define CYRF_CSN_pin PB12 //CYRF CSN #define CYRF_CSN_pin PB12 //CYRF CSN
//SPI pins //SPI pins
#define SCK_pin PB13 //SCK #define SCK_pin PB13 //SCK
#define SDO_pin PB14 //MISO #define SDO_pin PB14 //MISO
#define SDI_pin PB15 //MOSI #define SDI_pin PB15 //MOSI
// //
#define TX_INV_pin PB3 #define TX_INV_pin PB3
#define RX_INV_pin PB1 #define RX_INV_pin PB1

View File

@ -724,7 +724,7 @@ void Serial_write( uint8_t byte )
else else
{ {
byteLo |= 0xFE ; // Stop bit byteLo |= 0xFE ; // Stop bit
} }
byte <<= 1 ; byte <<= 1 ;
#ifdef INVERT_SERIAL #ifdef INVERT_SERIAL
byte |= 1 ; // Start bit byte |= 1 ; // Start bit