Subversion Repositories FlightCtrl

Rev

Rev 838 | Rev 979 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 838 Rev 966
Line 8... Line 8...
8
volatile unsigned int cntKompass = 0;
8
volatile unsigned int cntKompass = 0;
9
volatile unsigned int beeptime = 0;
9
volatile unsigned int beeptime = 0;
10
unsigned int BeepMuster = 0xffff;
10
unsigned int BeepMuster = 0xffff;
11
int ServoValue = 0;
11
int ServoValue = 0;
12
extern void MM3_Update(void);
12
extern void MM3_Update(void);
13
 
13
 
14
enum {
14
enum {
15
  STOP             = 0,
15
  STOP             = 0,
16
  CK               = 1,
16
    CK               = 1,
17
  CK8              = 2,
17
    CK8              = 2,
18
  CK64             = 3,
18
    CK64             = 3,
19
  CK256            = 4,
19
    CK256            = 4,
20
  CK1024           = 5,
20
    CK1024           = 5,
21
  T0_FALLING_EDGE  = 6,
21
    T0_FALLING_EDGE  = 6,
22
  T0_RISING_EDGE   = 7
22
    T0_RISING_EDGE   = 7
23
};
23
};
Line 24... Line 24...
24
 
24
 
25
 
25
 
26
SIGNAL (SIG_OVERFLOW0)    // 8kHz
26
SIGNAL (SIG_OVERFLOW0)    // 8kHz
27
{
27
{
28
    static unsigned char cnt_1ms = 1,cnt = 0;
28
  static unsigned char cnt_1ms = 1,cnt = 0;
29
    unsigned char pieper_ein = 0;
29
  unsigned char pieper_ein = 0;
30
 
30
 
31
   Count8Khz++;
31
  Count8Khz++;
32
   
32
 
33
        if(!cnt--)
33
  if(!cnt--)
34
    {
34
  {
35
                cnt = 9;
35
    cnt = 9;
36
                cnt_1ms++;
36
    cnt_1ms++;
37
                cnt_1ms %= 2;
-
 
38
                if(!cnt_1ms)
-
 
39
                {
-
 
40
                        UpdateMotor = 1;
-
 
41
                }
-
 
42
                CountMilliseconds++;
-
 
43
                cnt_ms++;
-
 
44
                // update compass value if this option is enabled in the settings
-
 
45
                MM3_Update(); // read out mm3 board
-
 
46
     }  
-
 
47
 
-
 
48
     if(beeptime > 1)
-
 
49
        {
-
 
50
        beeptime--;      
-
 
51
        if(beeptime & BeepMuster)
-
 
52
         {
-
 
53
          pieper_ein = 1;
-
 
54
         }
-
 
55
         else pieper_ein = 0;
-
 
56
        }
-
 
57
     else
-
 
58
      {
-
 
59
       pieper_ein = 0;
-
 
60
       BeepMuster = 0xffff;
-
 
61
      }
-
 
62
 
37
    cnt_1ms %= 2;
63
    if(pieper_ein)
38
    if(!cnt_1ms)
64
    {
39
    {
-
 
40
      UpdateMotor = 1;
65
        PORTC |= (1<<7); // Speaker an PORTC.7
41
    }
-
 
42
    CountMilliseconds++;
-
 
43
    cnt_ms++;
-
 
44
    // update compass value if this option is enabled in the settings
-
 
45
    MM3_Update(); // read out mm3 board
-
 
46
  }  
-
 
47
 
-
 
48
  if(beeptime > 1)
-
 
49
  {
66
    }
50
    beeptime--;      
-
 
51
    if(beeptime & BeepMuster)
-
 
52
    {
-
 
53
      pieper_ein = 1;
-
 
54
    }
-
 
55
    else pieper_ein = 0;
-
 
56
  }
-
 
57
  else
-
 
58
  {
-
 
59
    pieper_ein = 0;
-
 
60
    BeepMuster = 0xffff;
-
 
61
  }
-
 
62
 
-
 
63
  if(pieper_ein)
-
 
64
  {
-
 
65
    PORTC |= (1<<7); // Speaker an PORTC.7
-
 
66
  }
67
    else  
67
  else  
-
 
68
  {
-
 
69
    PORTC &= ~(1<<7);
-
 
70
  }
-
 
71
 
-
 
72
#if 0
-
 
73
  if(PINC & 0x10)
-
 
74
  {
-
 
75
    cntKompass++;
-
 
76
  }
-
 
77
  else
-
 
78
  {
-
 
79
    if((cntKompass) && (cntKompass < 4000))
-
 
80
    {
-
 
81
      if(cntKompass < 10)
-
 
82
      {
-
 
83
        cntKompass = 10;
68
    {
84
      }
69
        PORTC &= ~(1<<7);
-
 
70
    }
-
 
71
 
-
 
72
 #if 0
-
 
73
        if(PINC & 0x10)
-
 
74
        {
-
 
75
                cntKompass++;
-
 
76
        }
-
 
77
        else
-
 
78
        {
-
 
79
                if((cntKompass) && (cntKompass < 4000))
-
 
80
                {
-
 
81
                        if(cntKompass < 10)
85
      KompassValue = (((int) cntKompass-10) * 36) / 35;
82
                        {
-
 
83
                                cntKompass = 10;
-
 
84
                        }
86
    }
85
                        KompassValue = (((int) cntKompass-10) * 36) / 35;
-
 
86
                }
-
 
87
                cntKompass = 0;
87
    cntKompass = 0;
88
        }
88
  }
Line 89... Line 89...
89
#endif
89
#endif
90
}
90
}
91
 
91
 
92
 
92
 
93
void Timer_Init(void)
93
void Timer_Init(void)
94
{
94
{
95
    tim_main = SetDelay(10);
95
  tim_main = SetDelay(10);
96
    TCCR0B = CK8;
96
  TCCR0B = CK8;
97
    TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM
97
  TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM
98
    OCR0A =  0;
98
  OCR0A =  0;
99
    OCR0B = 120;
99
  OCR0B = 120;
100
    TCNT0 = (unsigned char)-TIMER_RELOAD_VALUE;  // reload
100
  TCNT0 = (unsigned char)-TIMER_RELOAD_VALUE;  // reload
101
   
101
 
102
    TCCR2A=(1<<COM2A1)|(1<<COM2A0)|3;
102
  TCCR2A=(1<<COM2A1)|(1<<COM2A0)|3;
103
    TCCR2B=(0<<CS20)|(1<<CS21)|(1<<CS22);
103
  TCCR2B=(0<<CS20)|(1<<CS21)|(1<<CS22);
104
        TIMSK2 |= _BV(OCIE2A);
104
  TIMSK2 |= _BV(OCIE2A);
105
 
105
 
Line 106... Line 106...
106
    TIMSK0 |= _BV(TOIE0);
106
  TIMSK0 |= _BV(TOIE0);
Line 107... Line 107...
107
    OCR2A = 10;
107
  OCR2A = 10;
108
    TCNT2 = 0;
108
  TCNT2 = 0;
109
}
109
}
110
 
110
 
111
// -----------------------------------------------------------------------
111
// -----------------------------------------------------------------------
112
 
112
 
Line 113... Line 113...
113
unsigned int SetDelay (unsigned int t)
113
unsigned int SetDelay (unsigned int t)
114
{
114
{
115
//  TIMSK0 &= ~_BV(TOIE0);
115
  //  TIMSK0 &= ~_BV(TOIE0);
116
  return(CountMilliseconds + t + 1);                                            
116
  return(CountMilliseconds + t + 1);                                            
117
//  TIMSK0 |= _BV(TOIE0);
117
  //  TIMSK0 |= _BV(TOIE0);
118
}
118
}
119
 
119
 
Line 120... Line 120...
120
// -----------------------------------------------------------------------
120
// -----------------------------------------------------------------------
121
char CheckDelay(unsigned int t)
121
char CheckDelay(unsigned int t)
122
{
122
{
123
//  TIMSK0 &= ~_BV(TOIE0);
123
  //  TIMSK0 &= ~_BV(TOIE0);
124
  return(((t - CountMilliseconds) & 0x8000) >> 9);
124
  return(((t - CountMilliseconds) & 0x8000) >> 9);
125
//  TIMSK0 |= _BV(TOIE0);
125
  //  TIMSK0 |= _BV(TOIE0);
126
}
126
}
Line 127... Line 127...
127
 
127
 
128
// -----------------------------------------------------------------------
128
// -----------------------------------------------------------------------
129
void Delay_ms(unsigned int w)
129
void Delay_ms(unsigned int w)
130
{
130
{
131
 unsigned int akt;
131
  unsigned int akt;
132
 akt = SetDelay(w);
132
  akt = SetDelay(w);
Line 133... Line 133...
133
 while (!CheckDelay(akt));
133
  while (!CheckDelay(akt));
134
}
134
}
135
 
135
 
136
void Delay_ms_Mess(unsigned int w)
136
void Delay_ms_Mess(unsigned int w)
137
{
137
{
138
 unsigned int akt;
138
  unsigned int akt;
139
 akt = SetDelay(w);
139
  akt = SetDelay(w);
140
 while (!CheckDelay(akt)) ANALOG_ON;
140
  while (!CheckDelay(akt)) ANALOG_ON;
141
}
141
}
142
 
142
 
143
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
143
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
144
//  Servo ansteuern
144
//  Servo ansteuern
145
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
145
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
146
SIGNAL(SIG_OUTPUT_COMPARE2A)
146
SIGNAL(SIG_OUTPUT_COMPARE2A)
147
{
147
{
148
  static unsigned char timer = 10;
148
  static unsigned char timer = 10;
149
  unsigned char Parameter_ServoNickControl = 100;
149
  unsigned char Parameter_ServoNickControl = 100;
150
 
150
 
151
  if(!timer--)  
151
  if(!timer--)  
152
    {
152
  {
153
     TCCR2A=(1<<COM2A1)|(0<<COM2A0)|3;  
153
    TCCR2A=(1<<COM2A1)|(0<<COM2A0)|3;  
154
     ServoValue =  Parameter_ServoNickControl;
154
    ServoValue =  Parameter_ServoNickControl;
155
     if(EE_Parameter.ServoNickCompInvert & 0x01) ServoValue += ((long) EE_Parameter.ServoNickComp * (0)) / 512;
155
    if(EE_Parameter.ServoNickCompInvert & 0x01) ServoValue += ((long) EE_Parameter.ServoNickComp * (0)) / 512;
156
     else ServoValue -= ((long) EE_Parameter.ServoNickComp * (0)) / 512;
156
    else ServoValue -= ((long) EE_Parameter.ServoNickComp * (0)) / 512;
157
     
157
   
158
     if(ServoValue < EE_Parameter.ServoNickMin) ServoValue = EE_Parameter.ServoNickMin;
158
    if(ServoValue < EE_Parameter.ServoNickMin) ServoValue = EE_Parameter.ServoNickMin;
159
     else if(ServoValue > EE_Parameter.ServoNickMax) ServoValue = EE_Parameter.ServoNickMax;
159
    else if(ServoValue > EE_Parameter.ServoNickMax) ServoValue = EE_Parameter.ServoNickMax;