Browse Source

Merge pull request #3 from dustin/master

New failsafe code to stop sending pulses on failure.
readerror67 9 years ago
parent
commit
b73b8cd8c8
1 changed files with 10 additions and 15 deletions
  1. 10
    15
      frsky_arduino_rx_complete.ino

+ 10
- 15
frsky_arduino_rx_complete.ino View File

38
 #define chanel_number 8  //set the number of chanels
38
 #define chanel_number 8  //set the number of chanels
39
 #define SEEK_CHANSKIP   13
39
 #define SEEK_CHANSKIP   13
40
 #define MAX_MISSING_PKT 20
40
 #define MAX_MISSING_PKT 20
41
+#define FAILSAFE_MISSING_PKT 170
41
 #define PPM_FrLen 22500
42
 #define PPM_FrLen 22500
42
 #define PPM_PulseLen 300
43
 #define PPM_PulseLen 300
43
 #define default_servo_value 1500
44
 #define default_servo_value 1500
106
 static byte jumper1 = 0;
107
 static byte jumper1 = 0;
107
 static byte jumper2 = 0;
108
 static byte jumper2 = 0;
108
 volatile int ppm[chanel_number];
109
 volatile int ppm[chanel_number];
110
+volatile bool failed = false;
109
 static uint16_t total_servo_time = 0;
111
 static uint16_t total_servo_time = 0;
110
 static byte cur_chan_numb = 0;
112
 static byte cur_chan_numb = 0;
111
 boolean debug = false;
113
 boolean debug = false;
216
     unsigned long time = micros();
218
     unsigned long time = micros();
217
 
219
 
218
     #if defined(FAILSAFE)
220
     #if defined(FAILSAFE)
219
-        if (missingPackets > 170) {
220
-            //**************************************
221
-            //noInterrupts();//
222
-            //digitalWrite(sigPin, LOW);
223
-            //Servo_Ports_LOW;
224
-            //**********************************************
221
+        if (missingPackets > FAILSAFE_MISSING_PKT) {
222
+            failed = true;
225
             missingPackets = 0;
223
             missingPackets = 0;
226
-            int i;
227
-            for (i = 0; i < 8; i++) {
228
-                Servo_data[i] = 1000;
229
-                ppm[i] = 1000;
230
-                if (i == 2) {
231
-                    Servo_data[2] = 1000; //THROTLE ON CHN3 here it can be changed Throttle on other channel
232
-                    ppm[2] = 1000;
233
-                }
234
-            }
235
         }
224
         }
236
     #endif
225
     #endif
237
 
226
 
267
                             cc2500_strobe(CC2500_SIDLE);
256
                             cc2500_strobe(CC2500_SIDLE);
268
                             nextChannel(1);
257
                             nextChannel(1);
269
                             LED_ON;
258
                             LED_ON;
259
+                            failed = false;
270
                             break;
260
                             break;
271
                         }
261
                         }
272
                     }
262
                     }
475
 
465
 
476
 ISR(TIMER1_COMPA_vect)
466
 ISR(TIMER1_COMPA_vect)
477
 {
467
 {
468
+    if (failed) {
469
+        digitalWrite(sigPin, HIGH);
470
+        return;
471
+    }
472
+
478
     TCNT1 = 0;
473
     TCNT1 = 0;
479
     if (jumper1 == 0) {
474
     if (jumper1 == 0) {
480
         pinMode(Servo5_OUT, OUTPUT);
475
         pinMode(Servo5_OUT, OUTPUT);

Loading…
Cancel
Save