Subversion Repositories MK3Mag

Rev

Rev 1 | Rev 12 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7 hbuss 1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + MK3Mag 3D-Compass
3
// + ATMEGA168 mit 8MHz
4
// + (c) 05.2008 Holger Buss
5
// + Nur für den privaten Gebrauch
6
// + Keine Garantie auf Fehlerfreiheit
7
// + Kommerzielle Nutzung nur mit meiner Zustimmung
8
// + Der Code ist für die Hardware MK3Mag entwickelt worden
9
// + www.mikrokopter.com
10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 11
#include "main.h"
12
volatile unsigned int CountMilliseconds = 0;
13
volatile unsigned char Timer0Overflow;
14
unsigned int I2C_Timeout = 0;
15
unsigned int SIO_Timeout = 0;
16
 
17
 
18
enum {
19
  STOP             = 0,
20
  CK               = 1,
21
  CK8              = 2,
22
  CK64             = 3,
23
  CK256            = 4,
24
  CK1024           = 5,
25
  T0_FALLING_EDGE  = 6,
26
  T0_RISING_EDGE   = 7
27
};
28
 
29
 
30
SIGNAL(SIG_OVERFLOW0)
31
{
32
 static unsigned char cnt;
33
 static unsigned int cmps_cnt;
7 hbuss 34
 TCNT0 -= 101;  // reload
1 ingob 35
 Timer0Overflow++;
36
 
37
 if(++cmps_cnt == 380)
38
 {
39
  PORTB |= 0x04;
40
  cmps_cnt = 0;
41
 }
42
 else
43
 if(cmps_cnt == PwmHeading)
44
 {
45
  PORTB &= ~0x04;
46
 }
47
 
48
 if(!--cnt)
49
  {
50
   cnt = 10;
51
   CountMilliseconds += 1;
52
   if(I2C_Timeout) I2C_Timeout--;
53
   if(SIO_Timeout) SIO_Timeout--;
54
  }
55
}
56
 
57
 
58
void Timer0_Init(void)
59
{
60
 TCCR0B = TIMER_TEILER;  // Starten des Timers
61
// TCNT0 = 100;  // reload
62
 TIM0_START;
63
 TIMER2_INT_ENABLE;
64
}
65
 
66
 
67
unsigned int SetDelay(unsigned int t)
68
{
69
  return(CountMilliseconds + t - 1);                                            
70
}
71
 
72
char CheckDelay (unsigned int t)
73
{
74
  return(((t - CountMilliseconds) & 0x8000) >> 8);
75
}
76
 
77
void Delay_ms(unsigned int w)
78
{
79
 unsigned int akt;
80
 akt = SetDelay(w);
81
 while (!CheckDelay(akt));
82
}