Subversion Repositories FlightCtrl

Rev

Rev 838 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
838 MikeW 1
/*#######################################################################################
2
Decodieren eines RC Summen Signals
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 04.2007 Holger Buss
6
// + only for non-profit use
7
// + www.MikroKopter.com
8
// + see the File "License.txt" for further Informations
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
 
11
#include "rc.h"
12
#include "main.h"
13
 
966 MikeW 14
int PPM_in[11] = {0,0,0,0,0,0,0,0,0,0,0};
838 MikeW 15
int RCQuality = 0;
966 MikeW 16
unsigned char NewPpmData = 1;
838 MikeW 17
 
18
//############################################################################
19
//zum decodieren des PPM-Signals wird Timer1 mit seiner Input
20
//Capture Funktion benutzt:
21
void rc_sum_init (void)
22
//############################################################################
23
{
966 MikeW 24
  TCCR1B=(1<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1); //timer1 prescale 64 
25
  TIMSK1 |= _BV(ICIE1);
26
  return;
838 MikeW 27
}
28
 
29
//############################################################################
30
//Diese Routine startet und inizialisiert den Timer für RC
31
SIGNAL(SIG_INPUT_CAPTURE1)
32
//############################################################################
33
{
966 MikeW 34
  static unsigned int AltICR=0;
35
  signed int signal = 0,tmp;
36
  static int index;
37
  static float RC_Quality = 0.0F;
38
  static int PPM_org[11];
39
 
40
  signal = (unsigned int) ICR1 - AltICR;
41
  AltICR = ICR1;
42
 
43
  //Syncronisationspause?
44
  if ((signal > 1500) && (signal < 8000))        
45
  {
46
    index = 1;
47
    NewPpmData = 0;  // Null bedeutet: Neue Daten
48
  }
49
  else
50
  {
51
    if(index < 10)
838 MikeW 52
    {
966 MikeW 53
      if((signal > 250) && (signal < 687))
54
      {
55
        signal -= 466;
56
        // Stabiles Signal
57
        if(abs(signal - PPM_in[index]) < 6)
58
        {
59
          if(SenderOkay < 200)
60
          {
61
            SenderOkay += 10;
62
          }
63
        }
64
        /* Give an estimate for the Signal Level based on the RC-Jitter see
65
        http://forum.mikrokopter.de/topic-post44807.html#post44807*/
66
        if (abs(2 * (signal - PPM_org[index]) > (int) RC_Quality))
838 MikeW 67
        {
966 MikeW 68
          RC_Quality = 0.99F * RC_Quality + 0.01F * (float) abs(2 * (signal - PPM_org[index])) ;
838 MikeW 69
        }
966 MikeW 70
        else
71
        {
72
          RC_Quality = 0.998F * RC_Quality + 0.002F * (float) abs(2 * (signal - PPM_org[index]));
73
        }
74
        tmp = (3 * (PPM_in[index]) + signal) / 4;  
75
        PPM_in[index] = tmp;
76
        PPM_org[index] = signal;
77
      }
78
      else
79
      {
80
        RC_Quality = 0.95F * RC_Quality + 0.05F * 100;         
81
      }
82
      RC_Quality = MIN(100.F, RC_Quality);
83
      RCQuality = 100 - (int) RC_Quality;
84
      DebugOut.Analog[12] = RCQuality;
85
      index++;  
86
      if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20;  // Servosignal an J3 anlegen
87
      if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10;  // Servosignal an J4 anlegen
88
      if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08;  // Servosignal an J5 anlegen 
89
    }
90
  }
838 MikeW 91
}
92
 
93
 
94
 
95
 
96