62,9 → 62,8 |
#include "mk3mag.h" |
#endif |
|
volatile uint16_t millisecondsCount = 0; |
volatile uint32_t globalMillisClock = 0; |
volatile uint8_t runFlightControl = 0; |
volatile uint16_t cntKompass = 0; |
volatile uint16_t beepTime = 0; |
volatile uint16_t beepModulation = BEEP_MODULATION_NONE; |
|
106,10 → 105,9 |
TCCR0A |= (1 << COM0A1) | (1 << COM0B1) | (1 << WGM01) | (1 << WGM00); |
|
// Timer/Counter 0 Control Register B |
|
// set clock divider for timer 0 to SYSKLOCK/8 = 20MHz / 8 = 2.5MHz |
// set clock divider for timer 0 to SYSCLOCK/8 = 20MHz/8 = 2.5MHz |
// i.e. the timer increments from 0x00 to 0xFF with an update rate of 2.5 MHz |
// hence the timer overflow interrupt frequency is 2.5 MHz / 256 = 9.765 kHz |
// hence the timer overflow interrupt frequency is 2.5 MHz/256 = 9.765 kHz |
|
// divider 8 (Bits CS02 = 0, CS01 = 1, CS00 = 0) |
TCCR0B &= ~((1 << FOC0A) | (1 << FOC0B) | (1 << WGM02)); |
133,8 → 131,7 |
/*****************************************************/ |
/* Interrupt Routine of Timer 0 */ |
/*****************************************************/ |
ISR(TIMER0_OVF_vect) |
{ // 9765.625 Hz |
ISR(TIMER0_OVF_vect) { // 9765.625 Hz |
static uint8_t cnt_1ms = 1, cnt = 0; |
uint8_t beeperOn = 0; |
|
152,7 → 149,7 |
debugOut.digital[1] &= ~DEBUG_MAINLOOP_TIMER; |
runFlightControl = 1; // every 2nd run (976.5625 Hz/2 = 488.28125 Hz) |
} |
millisecondsCount++; // increment millisecond counter |
globalMillisClock++; // increment millisecond counter |
} |
|
// beeper on if duration is not over |
191,12 → 188,12 |
|
// ----------------------------------------------------------------------- |
uint16_t setDelay(uint16_t t) { |
return (millisecondsCount + t - 1); |
return (globalMillisClock + t - 1); |
} |
|
// ----------------------------------------------------------------------- |
int8_t checkDelay(uint16_t t) { |
return (((t - millisecondsCount) & 0x8000) >> 8); // check sign bit |
return (((t - globalMillisClock) & 0x8000) >> 8); // check sign bit |
} |
|
// ----------------------------------------------------------------------- |