Subversion Repositories FlightCtrl

Rev

Rev 1127 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1127 Rev 1133
Line 22... Line 22...
22
    CK1024 = 5,
22
  CK1024           = 5,
23
    T0_FALLING_EDGE = 6,
23
  T0_FALLING_EDGE  = 6,
24
    T0_RISING_EDGE = 7
24
  T0_RISING_EDGE   = 7
25
};
25
};
Line -... Line 26...
-
 
26
 
26
 
27
 
27
SIGNAL(SIG_OVERFLOW0) // 8kHz
28
SIGNAL (SIG_OVERFLOW0)    // 8kHz
28
{
29
{
29
    static unsigned char cnt_1ms = 1, cnt = 0;
30
    static unsigned char cnt_1ms = 1,cnt = 0;
30
    unsigned char pieper_ein = 0;
31
    unsigned char pieper_ein = 0;
31
    //    TCNT0 -= 250;//TIMER_RELOAD_VALUE;
32
//    TCNT0 -= 250;//TIMER_RELOAD_VALUE;
32
    if (SendSPI)
33
   if(SendSPI) SendSPI--;
33
        SendSPI--;
34
   if(!cnt--)
34
    if (!cnt--) {
-
 
35
//        cnt = 9;   // Wenn der Kommentar 8kHz oben stimmt, muß durch 8 geteilt werden, nicht durch 10!
35
    {
36
        cnt = 7;
36
     cnt = 9;
37
//        cnt_1ms++;
37
     cnt_1ms++;
38
//        cnt_1ms %= 2;
-
 
39
        cnt_1ms = !cnt_1ms;  // So ist das etwas einfacher
-
 
40
        if (!cnt_1ms)
38
     cnt_1ms %= 2;
41
            UpdateMotor = 1;
39
     if(!cnt_1ms) UpdateMotor = 1;
42
        CountMilliseconds++;
40
     CountMilliseconds++;
Line 43... Line 41...
43
    }
41
    }  
-
 
42
 
44
 
43
     if(beeptime > 1)
45
    if (beeptime > 1) {
44
        {
-
 
45
        beeptime--;      
46
        beeptime--;
46
        if(beeptime & BeepMuster)
-
 
47
         {
-
 
48
          pieper_ein = 1;
-
 
49
         }
47
        if (beeptime & BeepMuster)
50
         else pieper_ein = 0;
48
            pieper_ein = 1;
-
 
49
        else
51
        }
50
            pieper_ein = 0;
52
     else
51
    } else {
53
      {
52
        pieper_ein = 0;
54
       pieper_ein = 0;
Line -... Line 55...
-
 
55
       BeepMuster = 0xffff;
53
        BeepMuster = 0xffff;
56
      }
54
    }
57
 
55
 
58
 
56
    if (pieper_ein) {
-
 
57
        if (PlatinenVersion == 10)
59
     if(pieper_ein)
58
            PORTD |= (1 << 2); // Speaker an PORTD.2
60
        {
59
        else
-
 
60
            PORTC |= (1 << 7); // Speaker an PORTC.7
-
 
61
    } else {
61
          if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker an PORTD.2
-
 
62
          else                      PORTC |= (1<<7); // Speaker an PORTC.7
-
 
63
        }
62
        if (PlatinenVersion == 10)
64
     else  
63
            PORTD &= ~(1 << 2);
65
        {
Line 64... Line 66...
64
        else
66
         if(PlatinenVersion == 10) PORTD &= ~(1<<2);
-
 
67
         else                      PORTC &= ~(1<<7);
65
            PORTC &= ~(1 << 7);
68
        }
-
 
69
 
66
    }
70
 if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)
-
 
71
 {
67
 
72
  if(PINC & 0x10)
-
 
73
   {
68
    if (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) {
74
    cntKompass++;
-
 
75
   }
69
        if (PINC & 0x10)
76
  else
70
            cntKompass++;
77
   {
71
        else {
-
 
72
            if ((cntKompass) && (cntKompass < 362)) {
78
    if((cntKompass) && (cntKompass < 362))
73
                cntKompass += cntKompass / 41;
79
    {
74
                if (cntKompass > 10) KompassValue = cntKompass - 10;
80
     cntKompass += cntKompass / 41;
75
                else KompassValue = 0;
81
     if(cntKompass > 10) KompassValue = cntKompass - 10; else KompassValue = 0;
76
            }
82
    }
77
            //     if(cntKompass < 10) cntKompass = 10;
83
//     if(cntKompass < 10) cntKompass = 10;
78
            //     KompassValue = (unsigned long)((unsigned long)(cntKompass-10)*720L + 1L) / 703L;
84
//     KompassValue = (unsigned long)((unsigned long)(cntKompass-10)*720L + 1L) / 703L;
79
            KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
85
     KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
Line 80... Line 86...
80
            cntKompass = 0;
86
    cntKompass = 0;
81
        }
-
 
82
    }
87
   }
-
 
88
 }
83
}
89
}
84
 
90
 
85
//----------------------------
91
//----------------------------
86
 
92
void Timer_Init(void)
87
void Timer_Init(void) {
93
{
Line 106... Line 112...
106
 
112
   
Line 107... Line 113...
107
}
113
}
Line 108... Line 114...
108
 
114
 
-
 
115
// -----------------------------------------------------------------------
109
// -----------------------------------------------------------------------
116
 
110
 
117
unsigned int SetDelay (unsigned int t)
111
unsigned int SetDelay(unsigned int t) {
118
{
112
    //  TIMSK0 &= ~_BV(TOIE0);
119
//  TIMSK0 &= ~_BV(TOIE0);
Line 113... Line 120...
113
    return (CountMilliseconds + t + 1);
120
  return(CountMilliseconds + t + 1);                                            
114
    //  TIMSK0 |= _BV(TOIE0);
-
 
115
}
121
//  TIMSK0 |= _BV(TOIE0);
-
 
122
}
116
 
123
 
117
// -----------------------------------------------------------------------
124
// -----------------------------------------------------------------------
118
 
125
char CheckDelay(unsigned int t)
119
char CheckDelay(unsigned int t) {
126
{
Line 120... Line 127...
120
    //  TIMSK0 &= ~_BV(TOIE0);
127
//  TIMSK0 &= ~_BV(TOIE0);
121
    return (((t - CountMilliseconds) & 0x8000) >> 9);
-
 
122
    //  TIMSK0 |= _BV(TOIE0);
128
  return(((t - CountMilliseconds) & 0x8000) >> 9);
-
 
129
//  TIMSK0 |= _BV(TOIE0);
123
}
130
}
124
 
131
 
125
// -----------------------------------------------------------------------
132
// -----------------------------------------------------------------------
126
 
133
void Delay_ms(unsigned int w)
Line 127... Line 134...
127
void Delay_ms(unsigned int w) {
134
{
-
 
135
 unsigned int akt;
128
    unsigned int akt;
136
 akt = SetDelay(w);
129
    akt = SetDelay(w);
137
 while (!CheckDelay(akt));
130
    while (!CheckDelay(akt));
138
}
131
}
-
 
132
 
139
 
Line 133... Line 140...
133
void Delay_ms_Mess(unsigned int w) {
140
void Delay_ms_Mess(unsigned int w)
134
    unsigned int akt;
141
{
135
    akt = SetDelay(w);
142
 unsigned int akt;
136
    while (!CheckDelay(akt))
-
 
137
        ANALOG_ON;
143
 akt = SetDelay(w);
Line 138... Line 144...
138
}
144
 while (!CheckDelay(akt)) ANALOG_ON;
139
 
145
}
140
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
146
 
Line 172... Line 178...
172
        long integral;
178
                long integral;
Line 173... Line 179...
173
 
179
 
174
        /* Über Parameter läßt sich zwischen "+" und "X" - Formations
180
                /* Über Parameter läßt sich zwischen "+" und "X" - Formations
175
         * umschalten (sh. parameter.h)
181
                 * umschalten (sh. parameter.h)
176
         */
182
                 */
177
        if (PARAM_X_FORMATION)
183
                if( PARAM_X_FORMATION ) {
178
            integral = IntegralNick - IntegralRoll;
184
                        integral = IntegralNick - IntegralRoll;
179
        else
185
                } else {
-
 
186
                        integral = IntegralNick;
Line 180... Line 187...
180
            integral = IntegralNick;
187
                }
181
 
188
 
182
        if (EE_Parameter.ServoNickCompInvert & 0x01)
189
                if( EE_Parameter.ServoNickCompInvert & 0x01 )
183
            ServoValue += ((long) ((long) EE_Parameter.ServoNickComp * integral) >> DIV_128) / (512L >> DIV_4);
190
                        ServoValue += ( (long) ( (long) EE_Parameter.ServoNickComp * integral ) >> DIV_128 ) / ( 512L >> DIV_4 );
Line 187... Line 194...
187
        DebugOut.Analog[20] = ServoValue;
194
                DebugOut.Analog[20] = ServoValue;
Line 188... Line 195...
188
 
195
         
189
        if ((ServoValue % 255) < 45) {
196
                if ( ( ServoValue % 255 ) < 45 ) {
190
            ServoValue += 77;
197
                        ServoValue += 77;
191
            postPulse = 0x60 - 77;
198
                        postPulse   = 0x60 - 77;
192
        } else
199
                } else {
-
 
200
                        postPulse   = 0x60;
Line 193... Line 201...
193
            postPulse = 0x60;
201
                }
194
 
202
               
Line 195... Line 203...
195
        OCR2A = 255 - (ServoValue % 256);
203
                OCR2A  = 255 - ( ServoValue % 256 );