Subversion Repositories FlightCtrl

Rev

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

Rev 1872 Rev 1887
Line 60... Line 60...
60
 
60
 
61
#ifdef USE_MK3MAG
61
#ifdef USE_MK3MAG
62
#include "mk3mag.h"
62
#include "mk3mag.h"
Line 63... Line 63...
63
#endif
63
#endif
64
 
64
 
65
volatile uint16_t CountMilliseconds = 0;
65
volatile uint16_t millisecondsCount = 0;
66
volatile uint8_t runFlightControl = 0;
66
volatile uint8_t  runFlightControl = 0;
67
volatile uint16_t cntKompass = 0;
67
volatile uint16_t cntKompass = 0;
Line 68... Line 68...
68
volatile uint16_t BeepTime = 0;
68
volatile uint16_t beepTime = 0;
69
volatile uint16_t BeepModulation = 0xFFFF;
69
volatile uint16_t beepModulation = 0xFFFF;
70
 
70
 
Line 134... Line 134...
134
/*          Interrupt Routine of Timer 0             */
134
/*          Interrupt Routine of Timer 0             */
135
/*****************************************************/
135
/*****************************************************/
136
ISR(TIMER0_OVF_vect)
136
ISR(TIMER0_OVF_vect)
137
{ // 9765.625 Hz
137
{ // 9765.625 Hz
138
  static uint8_t cnt_1ms = 1, cnt = 0;
138
  static uint8_t cnt_1ms = 1, cnt = 0;
139
  uint8_t Beeper_On = 0;
139
  uint8_t beeper_On = 0;
Line 140... Line 140...
140
 
140
 
141
#ifdef USE_NAVICTRL
141
#ifdef USE_NAVICTRL
142
  if(SendSPI) SendSPI--; // if SendSPI is 0, the transmit of a byte via SPI bus to and from The Navicontrol is done
142
  if(SendSPI) SendSPI--; // if SendSPI is 0, the transmit of a byte via SPI bus to and from The Navicontrol is done
Line 150... Line 150...
150
        DebugOut.Digital[1] |= DEBUG_MAINLOOP_TIMER;
150
        DebugOut.Digital[1] |= DEBUG_MAINLOOP_TIMER;
151
      else
151
      else
152
        DebugOut.Digital[1] &= ~DEBUG_MAINLOOP_TIMER;
152
        DebugOut.Digital[1] &= ~DEBUG_MAINLOOP_TIMER;
153
      runFlightControl = 1; // every 2nd run (976.5625 Hz/2 = 488.28125 Hz)
153
      runFlightControl = 1; // every 2nd run (976.5625 Hz/2 = 488.28125 Hz)
154
    }
154
    }
155
    CountMilliseconds++; // increment millisecond counter
155
    millisecondsCount++; // increment millisecond counter
156
  }
156
  }
Line 157... Line 157...
157
 
157
 
158
  // beeper on if duration is not over
158
  // beeper on if duration is not over
159
  if (BeepTime) {
159
  if (beepTime) {
160
    BeepTime--; // decrement BeepTime
160
    beepTime--; // decrement BeepTime
161
    if (BeepTime & BeepModulation)
161
    if (beepTime & beepModulation)
162
      Beeper_On = 1;
162
      beeper_On = 1;
163
    else
163
    else
164
      Beeper_On = 0;
164
      beeper_On = 0;
165
  } else { // beeper off if duration is over
165
  } else { // beeper off if duration is over
166
    Beeper_On = 0;
166
    beeper_On = 0;
167
    BeepModulation = 0xFFFF;
167
    beepModulation = 0xFFFF;
Line 168... Line 168...
168
  }
168
  }
169
 
169
 
170
  // if beeper is on
170
  // if beeper is on
171
  if (Beeper_On) {
171
  if (beeper_On) {
172
    // set speaker port to high.
172
    // set speaker port to high.
173
    if (BoardRelease == 10)
173
    if (BoardRelease == 10)
174
      PORTD |= (1 << PORTD2); // Speaker at PD2
174
      PORTD |= (1 << PORTD2); // Speaker at PD2
Line 191... Line 191...
191
  }
191
  }
192
#endif
192
#endif
193
}
193
}
Line 194... Line 194...
194
 
194
 
195
// -----------------------------------------------------------------------
195
// -----------------------------------------------------------------------
196
uint16_t SetDelay(uint16_t t) {
196
uint16_t setDelay(uint16_t t) {
197
  return (CountMilliseconds + t - 1);
197
  return (millisecondsCount + t - 1);
Line 198... Line 198...
198
}
198
}
199
 
199
 
200
// -----------------------------------------------------------------------
200
// -----------------------------------------------------------------------
201
int8_t CheckDelay(uint16_t t) {
201
int8_t checkDelay(uint16_t t) {
Line 202... Line 202...
202
  return (((t - CountMilliseconds) & 0x8000) >> 8); // check sign bit
202
  return (((t - millisecondsCount) & 0x8000) >> 8); // check sign bit
203
}
203
}
204
 
204
 
205
// -----------------------------------------------------------------------
205
// -----------------------------------------------------------------------
206
void Delay_ms(uint16_t w) {
206
void delay_ms(uint16_t w) {
207
  uint16_t t_stop = SetDelay(w);
207
  uint16_t t_stop = setDelay(w);
Line 208... Line 208...
208
  while (!CheckDelay(t_stop))
208
  while (!checkDelay(t_stop))
209
    ;
209
    ;
210
}
210
}
211
 
211
 
212
// -----------------------------------------------------------------------
212
// -----------------------------------------------------------------------
213
void Delay_ms_Mess(uint16_t w) {
213
void delay_ms_Mess(uint16_t w) {
214
  uint16_t t_stop;
214
  uint16_t t_stop;
215
  t_stop = SetDelay(w);
215
  t_stop = setDelay(w);
216
  while (!CheckDelay(t_stop)) {
216
  while (!checkDelay(t_stop)) {
217
    if (analogDataReady) {
217
    if (analogDataReady) {