Subversion Repositories FlightCtrl

Rev

Rev 787 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 787 Rev 857
Line 3... Line 3...
3
volatile unsigned int CountMilliseconds = 0;
3
volatile unsigned int CountMilliseconds = 0;
4
volatile static unsigned int tim_main;
4
volatile static unsigned int tim_main;
5
volatile unsigned char UpdateMotor = 0;
5
volatile unsigned char UpdateMotor = 0;
6
volatile unsigned int beeptime = 0;
6
volatile unsigned int beeptime = 0;
7
unsigned int BeepMuster = 0xffff;
7
unsigned int BeepMuster = 0xffff;
8
int ServoValue = 0;
8
uint8_t ServoValue = 0;
Line 9... Line 9...
9
 
9
 
-
 
10
enum
10
enum {
11
{
11
  STOP             = 0,
12
  STOP             = 0,
12
  CK               = 1,
13
  CK               = 1,
13
  CK8              = 2,
14
  CK8              = 2,
14
  CK64             = 3,
15
  CK64             = 3,
Line 20... Line 21...
20
 
21
 
21
 
22
 
22
SIGNAL (SIG_OVERFLOW0)    // 9,8kHz
23
SIGNAL (SIG_OVERFLOW0)    // 9,8kHz
23
{
24
{
Line 24... Line 25...
24
    static uint8_t cnt_1ms = 1,cnt = 0;
25
    static uint8_t cnt_1ms = 1,cnt = 0;
25
    uint8_t pieper_ein = 0;
26
    uint8_t pieper_ein;
26
 
27
 
27
   if(!cnt--)
28
   if(!cnt--)
28
    {
29
    {
29
     cnt = 9;
30
     cnt = 9;
30
     cnt_1ms++;
31
     cnt_1ms++;
31
     cnt_1ms %= 2;
32
     cnt_1ms %= 2;
32
         if(!cnt_1ms) UpdateMotor = 1;
-
 
33
     CountMilliseconds++;
-
 
Line 34... Line 33...
34
     }  
33
         if(!cnt_1ms) UpdateMotor = 1;
35
 
34
     CountMilliseconds++;
36
PORTD |= (1<<PD4);
35
    }
37
 
36
 
38
     if(beeptime > 1)
37
    if(beeptime > 1)
39
        {
38
        {
40
        beeptime--;      
39
        beeptime--;      
41
        if(beeptime & BeepMuster)
40
        if(beeptime & BeepMuster)
42
         {
41
         {
43
          pieper_ein = 1;
42
          pieper_ein = 1;
44
         }
43
         }
45
         else pieper_ein = 0;
44
         else pieper_ein = 0;
46
        }
45
        }
47
     else
46
    else
Line 48... Line 47...
48
      {
47
      {
49
       pieper_ein = 0;
48
       pieper_ein = 0;
-
 
49
       BeepMuster = 0xffff;
50
       BeepMuster = 0xffff;
50
      }
-
 
51
 
51
      }
52
 
-
 
53
    if(pieper_ein)
52
 
54
        {
53
 
55
          #if (PlatinenVersion == 10)
54
     if(pieper_ein)
56
                   PORTD |= (1<<2); // Speaker an PORTD.2
55
        {
57
          #else
-
 
58
                   PORTC |= (1<<7); // Speaker an PORTC.7
-
 
59
                  #endif
56
          if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker an PORTD.2
60
        }
-
 
61
    else  
57
          else                      PORTC |= (1<<7); // Speaker an PORTC.7
62
        {
Line 58... Line 63...
58
        }
63
         #if (PlatinenVersion == 10)
59
     else  
64
                  PORTD &= ~(1<<2);
Line 80... Line 85...
80
TIMSK2 |= _BV(OCIE2A);
85
TIMSK2 |= _BV(OCIE2A);
Line 81... Line 86...
81
 
86
 
82
    TIMSK0 |= _BV(TOIE0);
87
    TIMSK0 |= _BV(TOIE0);
83
    OCR2A = 10;
88
    OCR2A = 10;
84
    TCNT2 = 0;
-
 
85
   
89
    TCNT2 = 0;
Line 86... Line 90...
86
}
90
}
Line 87... Line 91...
87
 
91
 
88
// -----------------------------------------------------------------------
92
// -----------------------------------------------------------------------
89
 
-
 
90
unsigned int SetDelay (unsigned int t)
93
 
91
{
-
 
92
//  TIMSK0 &= ~_BV(TOIE0);
94
unsigned int SetDelay (unsigned int t)
Line 93... Line 95...
93
  return(CountMilliseconds + t + 1);                                            
95
{
94
//  TIMSK0 |= _BV(TOIE0);
96
  return(CountMilliseconds + t + 1);                                            
95
}
97
}
96
 
-
 
97
// -----------------------------------------------------------------------
98
 
98
char CheckDelay(unsigned int t)
-
 
99
{
99
// -----------------------------------------------------------------------
Line 100... Line 100...
100
//  TIMSK0 &= ~_BV(TOIE0);
100
char CheckDelay(unsigned int t)
101
  return(((t - CountMilliseconds) & 0x8000) >> 9);
101
{
102
//  TIMSK0 |= _BV(TOIE0);
102
  return(((t - CountMilliseconds) & 0x8000) >> 9);
Line 120... Line 120...
120
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
120
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
121
//  Servo ansteuern
121
//  Servo ansteuern
122
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
122
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
123
SIGNAL(SIG_OUTPUT_COMPARE2A)
123
SIGNAL(SIG_OUTPUT_COMPARE2A)
124
{
124
{
125
  static unsigned char timer = 10;
125
  static uint8_t timer = 10;
Line 126... Line 126...
126
 
126
 
127
  if(!timer--)  
127
  if(!timer--)  
128
    {
128
    {
129
     TCCR2A=(1<<COM2A1)|(0<<COM2A0)|3;  
129
     TCCR2A=(1<<COM2A1)|(0<<COM2A0)|3;  
-
 
130
     //ServoValue =  Parameter_ServoNickControl;
130
     ServoValue =  Parameter_ServoNickControl;
131
         ServoValue = (((uint16_t)Parameter_ServoNickControl * Cam_Travel) /255) + EE_Parameter.ServoNickMin;
131
     if(EE_Parameter.ServoNickCompInvert & 0x01) ServoValue += ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512;
132
    if(EE_Parameter.ServoNickCompInvert & 0x01) ServoValue += ((uint16_t)EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512;
132
     else ServoValue -= ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512;
133
    else ServoValue -= ((uint16_t)EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512;
133
     
134
       
134
     if(ServoValue < EE_Parameter.ServoNickMin) ServoValue = EE_Parameter.ServoNickMin;
135
    if(ServoValue < EE_Parameter.ServoNickMin) ServoValue = EE_Parameter.ServoNickMin;
Line 135... Line 136...
135
     else if(ServoValue > EE_Parameter.ServoNickMax) ServoValue = EE_Parameter.ServoNickMax;
136
    else if(ServoValue > EE_Parameter.ServoNickMax) ServoValue = EE_Parameter.ServoNickMax;
136
 
137
 
137
     OCR2A = ServoValue;// + 75;
138
     OCR2A = ServoValue;// + 75;
138
     timer = EE_Parameter.ServoNickRefresh;
139
     timer = EE_Parameter.ServoNickRefresh;
139
    }
140
    }
140
    else
141
    else
141
    {
142
    {
142
     TCCR2A =3;
143
     TCCR2A = 3;
143
     PORTD&=~0x80;
144
     PORTD &=~ 0x80;