Rev 153 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | #include "main.h" |
2 | |||
3 | volatile unsigned int CountMilliseconds = 0; |
||
4 | volatile static unsigned int tim_main; |
||
5 | volatile unsigned char UpdateMotor = 0; |
||
6 | volatile unsigned int cntKompass = 0; |
||
7 | volatile unsigned int beeptime = 0; |
||
8 | int ServoValue = 0; |
||
136 | salvo | 9 | //Salvo 8.9.2007 |
143 | salvo | 10 | volatile uint8_t Kompass_Neuer_Wert= 0; |
136 | salvo | 11 | volatile unsigned int Kompass_Value_Old = 0; |
12 | // Salvo End |
||
1 | ingob | 13 | enum { |
14 | STOP = 0, |
||
15 | CK = 1, |
||
16 | CK8 = 2, |
||
17 | CK64 = 3, |
||
18 | CK256 = 4, |
||
19 | CK1024 = 5, |
||
20 | T0_FALLING_EDGE = 6, |
||
21 | T0_RISING_EDGE = 7 |
||
22 | }; |
||
23 | |||
24 | |||
25 | SIGNAL (SIG_OVERFLOW0) // 8kHz |
||
26 | { |
||
27 | static unsigned char cnt_1ms = 1,cnt = 0; |
||
28 | // TCNT0 -= 250;//TIMER_RELOAD_VALUE; |
||
29 | |||
30 | if(!cnt--) |
||
31 | { |
||
32 | cnt = 9; |
||
33 | cnt_1ms++; |
||
34 | cnt_1ms %= 2; |
||
35 | if(!cnt_1ms) UpdateMotor = 1; |
||
36 | CountMilliseconds++; |
||
37 | if(Timeout) Timeout--; |
||
38 | } |
||
39 | |||
40 | if(beeptime > 1) |
||
41 | { |
||
42 | beeptime--; |
||
43 | PORTD |= (1<<2); |
||
44 | } |
||
45 | else |
||
46 | PORTD &= ~(1<<2); |
||
47 | |||
136 | salvo | 48 | // if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) |
1 | ingob | 49 | { |
50 | if(PINC & 0x10) |
||
51 | { |
||
52 | cntKompass++; |
||
53 | } |
||
54 | else |
||
55 | { |
||
56 | if((cntKompass) && (cntKompass < 4000)) |
||
57 | { |
||
104 | salvo | 58 | // Salvo Kompassoffset 30.8.2007 *********** |
136 | salvo | 59 | Kompass_Value_Old = KompassValue; |
104 | salvo | 60 | KompassValue = cntKompass -KOMPASS_OFFSET; |
61 | |||
62 | if (KompassValue < 0) |
||
63 | { |
||
64 | KompassValue += 360; |
||
65 | } |
||
66 | if (KompassValue >= 360) |
||
67 | { |
||
68 | KompassValue -= 360; |
||
69 | } |
||
70 | // Salvo End |
||
1 | ingob | 71 | } |
72 | // if(cntKompass < 10) cntKompass = 10; |
||
73 | // KompassValue = (unsigned long)((unsigned long)(cntKompass-10)*720L + 1L) / 703L; |
||
155 | salvo | 74 | //Salvo 12.9.2007 Ersatzkompass als Basis nehmen, nicht den magnetkompass |
1 | ingob | 75 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
155 | salvo | 76 | // int i; |
77 | // i = GyroKomp_Int/GYROKOMP_INC_GRAD_DEFAULT; |
||
78 | // if (i < 180) KompassRichtung = ((540 + i - KompassStartwert) % 360) - 180; |
||
79 | // else KompassRichtung = ((540 + (i-360) - KompassStartwert) % 360) - 180; |
||
80 | // Salvo End |
||
136 | salvo | 81 | Kompass_Neuer_Wert = 1; |
82 | cntKompass = 0; |
||
1 | ingob | 83 | } |
84 | } |
||
85 | } |
||
86 | |||
87 | |||
88 | void Timer_Init(void) |
||
89 | { |
||
90 | tim_main = SetDelay(10); |
||
91 | TCCR0B = CK8; |
||
92 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
||
93 | OCR0A = 0; |
||
94 | OCR0B = 120; |
||
95 | TCNT0 = -TIMER_RELOAD_VALUE; // reload |
||
96 | //OCR1 = 0x00; |
||
97 | |||
98 | TCCR2A=(1<<COM2A1)|(1<<COM2A0)|3; |
||
99 | TCCR2B=(0<<CS20)|(1<<CS21)|(1<<CS22); |
||
100 | |||
101 | // TIMSK2 |= _BV(TOIE2); |
||
102 | TIMSK2 |= _BV(OCIE2A); |
||
103 | |||
104 | TIMSK0 |= _BV(TOIE0); |
||
105 | OCR2A = 10; |
||
106 | TCNT2 = 0; |
||
107 | |||
108 | } |
||
109 | |||
110 | // ----------------------------------------------------------------------- |
||
111 | |||
112 | unsigned int SetDelay (unsigned int t) |
||
113 | { |
||
114 | // TIMSK0 &= ~_BV(TOIE0); |
||
115 | return(CountMilliseconds + t + 1); |
||
116 | // TIMSK0 |= _BV(TOIE0); |
||
117 | } |
||
118 | |||
119 | // ----------------------------------------------------------------------- |
||
120 | char CheckDelay(unsigned int t) |
||
121 | { |
||
122 | // TIMSK0 &= ~_BV(TOIE0); |
||
123 | return(((t - CountMilliseconds) & 0x8000) >> 9); |
||
124 | // TIMSK0 |= _BV(TOIE0); |
||
125 | } |
||
126 | |||
127 | // ----------------------------------------------------------------------- |
||
128 | void Delay_ms(unsigned int w) |
||
129 | { |
||
130 | unsigned int akt; |
||
131 | akt = SetDelay(w); |
||
132 | while (!CheckDelay(akt)); |
||
133 | } |
||
134 | |||
135 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
136 | // Servo ansteuern |
||
137 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
138 | SIGNAL(SIG_OUTPUT_COMPARE2A) |
||
139 | { |
||
140 | static unsigned char timer = 10; |
||
141 | |||
142 | if(!timer--) |
||
143 | { |
||
144 | TCCR2A=(1<<COM2A1)|(0<<COM2A0)|3; |
||
145 | ServoValue = Parameter_ServoNickControl; |
||
146 | if(EE_Parameter.ServoNickCompInvert & 0x01) ServoValue += ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
||
147 | else ServoValue -= ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
||
148 | |||
149 | if(ServoValue < EE_Parameter.ServoNickMin) ServoValue = EE_Parameter.ServoNickMin; |
||
150 | else if(ServoValue > EE_Parameter.ServoNickMax) ServoValue = EE_Parameter.ServoNickMax; |
||
151 | |||
143 | salvo | 152 | // DebugOut.Analog[10] = ServoValue; |
1 | ingob | 153 | OCR2A = ServoValue;// + 75; |
154 | timer = EE_Parameter.ServoNickRefresh; |
||
155 | } |
||
156 | else |
||
157 | { |
||
158 | TCCR2A =3; |
||
159 | PORTD&=~0x80; |
||
160 | } |
||
161 | } |