Subversion Repositories FlightCtrl

Rev

Rev 685 | Rev 688 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 685 Rev 687
1
/*#######################################################################################
1
/*#######################################################################################
2
Decodieren eines RC Summen Signals
2
Decodieren eines RC Summen Signals
3
#######################################################################################*/
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 04.2007 Holger Buss
5
// + Copyright (c) 04.2007 Holger Buss
6
// + only for non-profit use
6
// + only for non-profit use
7
// + www.MikroKopter.com
7
// + www.MikroKopter.com
8
// + see the File "License.txt" for further Informations
8
// + see the File "License.txt" for further Informations
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
10
 
10
 
11
#include <stdlib.h>
11
#include <avr/io.h>
12
#include <avr/io.h>
12
#include <avr/interrupt.h>
13
#include <avr/interrupt.h>
13
 
14
 
14
#include "rc.h"
15
#include "rc.h"
15
#include "fc.h"
16
#include "fc.h"
16
 
17
 
17
volatile int PPM_in[11];
18
volatile int16_t PPM_in[11];
18
volatile int PPM_diff[11];  // das diffenzierte Stick-Signal
19
volatile int16_t PPM_diff[11];  // das diffenzierte Stick-Signal
-
 
20
volatile uint8_t NewPpmData = 1;
-
 
21
 
-
 
22
/***************************************************************/
-
 
23
/* zum decodieren des PPM-Signals wird Timer1 mit seiner Input */
-
 
24
/* Capture Funktion benutzt:                                   */
19
volatile unsigned char NewPpmData = 1;
-
 
20
 
-
 
21
//############################################################################
-
 
22
//zum decodieren des PPM-Signals wird Timer1 mit seiner Input
25
/***************************************************************/
23
//Capture Funktion benutzt:
-
 
24
void rc_sum_init (void)
26
 
25
//############################################################################
27
void rc_sum_init (void)
26
{
28
{
27
        TCCR1B=(1<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1);//|(1 << WGM12); //timer1 prescale 64
29
        TCCR1B=(1<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1);//|(1 << WGM12); //timer1 prescale 64
28
 
30
 
29
// PWM
31
// PWM
30
//TCCR1A = (1 << COM1B1) | (1 << WGM11) | (1 << WGM10);
32
//TCCR1A = (1 << COM1B1) | (1 << WGM11) | (1 << WGM10);
31
//TCCR1B |= (1 << WGM12);
33
//TCCR1B |= (1 << WGM12);
32
//OCR1B = 55;
34
//OCR1B = 55;
33
 
35
 
34
    TIMSK1 |= _BV(ICIE1);
36
    TIMSK1 |= _BV(ICIE1);
35
    AdNeutralGier = 0;
37
    AdNeutralGier = 0;
36
    AdNeutralRoll = 0;
38
    AdNeutralRoll = 0;
37
    AdNeutralNick = 0;
39
    AdNeutralNick = 0;
38
    return;
40
    return;
39
}
41
}
40
 
42
 
41
//############################################################################
43
//############################################################################
42
//Diese Routine startet und inizialisiert den Timer für RC
44
//Diese Routine startet und inizialisiert den Timer für RC
43
SIGNAL(SIG_INPUT_CAPTURE1)
45
SIGNAL(SIG_INPUT_CAPTURE1)
44
//############################################################################
46
//############################################################################
45
 
47
 
46
{
48
{
47
        static unsigned int AltICR=0;
49
        static unsigned int AltICR=0;
48
    signed int signal = 0,tmp;
50
    signed int signal = 0,tmp;
49
        static int index;
51
        static int index;
50
 
52
 
51
        signal = (unsigned int) ICR1 - AltICR;
53
        signal = (unsigned int) ICR1 - AltICR;
52
        AltICR = ICR1;
54
        AltICR = ICR1;
53
 
55
 
54
    //Syncronisationspause?
56
    //Syncronisationspause?
55
//      if((signal > (int) Parameter_UserParam2 * 10) && (signal < 8000))
57
//      if((signal > (int) Parameter_UserParam2 * 10) && (signal < 8000))
56
        if((signal > 1100) && (signal < 8000))
58
        if((signal > 1100) && (signal < 8000))
57
        {
59
        {
58
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
60
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
59
        index = 1;
61
        index = 1;
60
        }
62
        }
61
        else
63
        else
62
        {
64
        {
63
        if(index < 10)
65
        if(index < 10)
64
            {
66
            {
65
            if((signal > 250) && (signal < 687))
67
            if((signal > 250) && (signal < 687))
66
                {
68
                {
67
                signal -= 466;
69
                signal -= 466;
68
                // Stabiles Signal
70
                // Stabiles Signal
69
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;}
71
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;}
70
//                tmp = (7 * (PPM_in[index]) + signal) / 8;
72
//                tmp = (7 * (PPM_in[index]) + signal) / 8;
71
                tmp = (3 * (PPM_in[index]) + signal) / 4;
73
                tmp = (3 * (PPM_in[index]) + signal) / 4;
72
                if(tmp > signal+1) tmp--; else
74
                if(tmp > signal+1) tmp--; else
73
                if(tmp < signal-1) tmp++;
75
                if(tmp < signal-1) tmp++;
74
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
76
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
75
                else PPM_diff[index] = 0;
77
                else PPM_diff[index] = 0;
76
                PPM_in[index] = tmp;
78
                PPM_in[index] = tmp;
77
                }
79
                }
78
            index++;
80
            index++;
79
         if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20;  // Servosignal an J3 anlegen
81
         if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20;  // Servosignal an J3 anlegen
80
         if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10;  // Servosignal an J4 anlegen
82
         if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10;  // Servosignal an J4 anlegen
81
         if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08;  // Servosignal an J5 anlegen
83
         if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08;  // Servosignal an J5 anlegen
82
        }
84
        }
83
        }
85
        }
84
}
86
}
85
 
87
 
86
 
88
 
87
 
89
 
88
 
90
 
89
 
91
 
90
 
92