Subversion Repositories FlightCtrl

Rev

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

Rev 2052 Rev 2060
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 millisecondsCount = 0;
-
 
66
volatile uint8_t  runFlightControl = 0;
65
volatile uint32_t globalMillisClock = 0;
67
volatile uint16_t cntKompass = 0;
66
volatile uint8_t  runFlightControl = 0;
Line 68... Line 67...
68
volatile uint16_t beepTime = 0;
67
volatile uint16_t beepTime = 0;
69
volatile uint16_t beepModulation = BEEP_MODULATION_NONE;
68
volatile uint16_t beepModulation = BEEP_MODULATION_NONE;
Line 104... Line 103...
104
  // Clear OC0B on Compare Match, set OC0B at BOTTOM, (Bits COM0B1 = 1, COM0B0 = 0)
103
  // Clear OC0B on Compare Match, set OC0B at BOTTOM, (Bits COM0B1 = 1, COM0B0 = 0)
105
  TCCR0A &= ~((1 << COM0A0) | (1 << COM0B0));
104
  TCCR0A &= ~((1 << COM0A0) | (1 << COM0B0));
106
  TCCR0A |= (1 << COM0A1) | (1 << COM0B1) | (1 << WGM01) | (1 << WGM00);
105
  TCCR0A |= (1 << COM0A1) | (1 << COM0B1) | (1 << WGM01) | (1 << WGM00);
Line 107... Line 106...
107
 
106
 
108
  // Timer/Counter 0 Control Register B
-
 
109
 
107
  // Timer/Counter 0 Control Register B
110
  // set clock divider for timer 0 to SYSKLOCK/8 = 20MHz / 8 = 2.5MHz
108
  // set clock divider for timer 0 to SYSCLOCK/8 = 20MHz/8 = 2.5MHz
111
  // i.e. the timer increments from 0x00 to 0xFF with an update rate of 2.5 MHz
109
  // i.e. the timer increments from 0x00 to 0xFF with an update rate of 2.5 MHz
Line 112... Line 110...
112
  // hence the timer overflow interrupt frequency is 2.5 MHz / 256 = 9.765 kHz
110
  // hence the timer overflow interrupt frequency is 2.5 MHz/256 = 9.765 kHz
113
 
111
 
114
  // divider 8 (Bits CS02 = 0, CS01 = 1, CS00 = 0)
112
  // divider 8 (Bits CS02 = 0, CS01 = 1, CS00 = 0)
Line 131... Line 129...
131
}
129
}
Line 132... Line 130...
132
 
130
 
133
/*****************************************************/
131
/*****************************************************/
134
/*          Interrupt Routine of Timer 0             */
132
/*          Interrupt Routine of Timer 0             */
135
/*****************************************************/
133
/*****************************************************/
136
ISR(TIMER0_OVF_vect)
-
 
137
{ // 9765.625 Hz
134
ISR(TIMER0_OVF_vect) { // 9765.625 Hz
138
  static uint8_t cnt_1ms = 1, cnt = 0;
135
  static uint8_t cnt_1ms = 1, cnt = 0;
Line 139... Line 136...
139
  uint8_t beeperOn = 0;
136
  uint8_t beeperOn = 0;
140
 
137
 
Line 150... Line 147...
150
        debugOut.digital[1] |= DEBUG_MAINLOOP_TIMER;
147
        debugOut.digital[1] |= DEBUG_MAINLOOP_TIMER;
151
      else
148
      else
152
        debugOut.digital[1] &= ~DEBUG_MAINLOOP_TIMER;
149
        debugOut.digital[1] &= ~DEBUG_MAINLOOP_TIMER;
153
      runFlightControl = 1; // every 2nd run (976.5625 Hz/2 = 488.28125 Hz)
150
      runFlightControl = 1; // every 2nd run (976.5625 Hz/2 = 488.28125 Hz)
154
    }
151
    }
155
    millisecondsCount++; // increment millisecond counter
152
    globalMillisClock++; // increment millisecond counter
156
  }
153
  }
Line 157... Line 154...
157
 
154
 
158
  // beeper on if duration is not over
155
  // beeper on if duration is not over
159
  if (beepTime) {
156
  if (beepTime) {
Line 189... Line 186...
189
#endif
186
#endif
190
}
187
}
Line 191... Line 188...
191
 
188
 
192
// -----------------------------------------------------------------------
189
// -----------------------------------------------------------------------
193
uint16_t setDelay(uint16_t t) {
190
uint16_t setDelay(uint16_t t) {
194
  return (millisecondsCount + t - 1);
191
  return (globalMillisClock + t - 1);
Line 195... Line 192...
195
}
192
}
196
 
193
 
197
// -----------------------------------------------------------------------
194
// -----------------------------------------------------------------------
198
int8_t checkDelay(uint16_t t) {
195
int8_t checkDelay(uint16_t t) {
Line 199... Line 196...
199
  return (((t - millisecondsCount) & 0x8000) >> 8); // check sign bit
196
  return (((t - globalMillisClock) & 0x8000) >> 8); // check sign bit
200
}
197
}
201
 
198