Rev 1127 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1127 | Rev 1133 | ||
---|---|---|---|
Line 12... | Line 12... | ||
12 | 12 | ||
13 | unsigned int BeepMuster = 0xffff; |
13 | unsigned int BeepMuster = 0xffff; |
Line 14... | Line 14... | ||
14 | unsigned int ServoValue = 0; |
14 | unsigned int ServoValue = 0; |
15 | 15 | ||
16 | enum { |
16 | enum { |
17 | STOP = 0, |
17 | STOP = 0, |
18 | CK = 1, |
18 | CK = 1, |
19 | CK8 = 2, |
19 | CK8 = 2, |
20 | CK64 = 3, |
20 | CK64 = 3, |
21 | CK256 = 4, |
21 | CK256 = 4, |
22 | CK1024 = 5, |
22 | CK1024 = 5, |
23 | T0_FALLING_EDGE = 6, |
23 | T0_FALLING_EDGE = 6, |
Line -... | Line 24... | ||
- | 24 | T0_RISING_EDGE = 7 |
|
24 | T0_RISING_EDGE = 7 |
25 | }; |
25 | }; |
26 | |
26 | 27 | ||
27 | SIGNAL(SIG_OVERFLOW0) // 8kHz |
28 | SIGNAL (SIG_OVERFLOW0) // 8kHz |
28 | { |
29 | { |
29 | static unsigned char cnt_1ms = 1, cnt = 0; |
30 | static unsigned char cnt_1ms = 1,cnt = 0; |
30 | unsigned char pieper_ein = 0; |
31 | unsigned char pieper_ein = 0; |
31 | // TCNT0 -= 250;//TIMER_RELOAD_VALUE; |
32 | // TCNT0 -= 250;//TIMER_RELOAD_VALUE; |
32 | if (SendSPI) |
- | |
33 | SendSPI--; |
33 | if(SendSPI) SendSPI--; |
34 | if (!cnt--) { |
34 | if(!cnt--) |
35 | // cnt = 9; // Wenn der Kommentar 8kHz oben stimmt, muß durch 8 geteilt werden, nicht durch 10! |
35 | { |
36 | cnt = 7; |
- | |
37 | // cnt_1ms++; |
- | |
38 | // cnt_1ms %= 2; |
36 | cnt = 9; |
39 | cnt_1ms = !cnt_1ms; // So ist das etwas einfacher |
37 | cnt_1ms++; |
40 | if (!cnt_1ms) |
38 | cnt_1ms %= 2; |
41 | UpdateMotor = 1; |
39 | if(!cnt_1ms) UpdateMotor = 1; |
42 | CountMilliseconds++; |
40 | CountMilliseconds++; |
- | 41 | } |
|
43 | } |
42 | |
44 | 43 | if(beeptime > 1) |
|
45 | if (beeptime > 1) { |
- | |
46 | beeptime--; |
44 | { |
47 | if (beeptime & BeepMuster) |
45 | beeptime--; |
48 | pieper_ein = 1; |
46 | if(beeptime & BeepMuster) |
49 | else |
47 | { |
50 | pieper_ein = 0; |
- | |
51 | } else { |
48 | pieper_ein = 1; |
52 | pieper_ein = 0; |
- | |
53 | BeepMuster = 0xffff; |
- | |
54 | } |
- | |
55 | - | ||
56 | if (pieper_ein) { |
49 | } |
57 | if (PlatinenVersion == 10) |
- | |
58 | PORTD |= (1 << 2); // Speaker an PORTD.2 |
50 | else pieper_ein = 0; |
59 | else |
51 | } |
60 | PORTC |= (1 << 7); // Speaker an PORTC.7 |
52 | else |
61 | } else { |
53 | { |
62 | if (PlatinenVersion == 10) |
- | |
63 | PORTD &= ~(1 << 2); |
54 | pieper_ein = 0; |
64 | else |
55 | BeepMuster = 0xffff; |
65 | PORTC &= ~(1 << 7); |
- | |
66 | } |
56 | } |
67 | - | ||
68 | if (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) { |
57 | |
69 | if (PINC & 0x10) |
- | |
70 | cntKompass++; |
- | |
71 | else { |
58 | |
72 | if ((cntKompass) && (cntKompass < 362)) { |
- | |
73 | cntKompass += cntKompass / 41; |
- | |
74 | if (cntKompass > 10) KompassValue = cntKompass - 10; |
59 | if(pieper_ein) |
75 | else KompassValue = 0; |
- | |
76 | } |
- | |
77 | // if(cntKompass < 10) cntKompass = 10; |
- | |
78 | // KompassValue = (unsigned long)((unsigned long)(cntKompass-10)*720L + 1L) / 703L; |
60 | { |
- | 61 | if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker an PORTD.2 |
|
- | 62 | else PORTC |= (1<<7); // Speaker an PORTC.7 |
|
- | 63 | } |
|
- | 64 | else |
|
- | 65 | { |
|
- | 66 | if(PlatinenVersion == 10) PORTD &= ~(1<<2); |
|
- | 67 | else PORTC &= ~(1<<7); |
|
- | 68 | } |
|
- | 69 | ||
- | 70 | if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) |
|
- | 71 | { |
|
- | 72 | if(PINC & 0x10) |
|
- | 73 | { |
|
- | 74 | cntKompass++; |
|
- | 75 | } |
|
- | 76 | else |
|
- | 77 | { |
|
- | 78 | if((cntKompass) && (cntKompass < 362)) |
|
79 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
79 | { |
- | 80 | cntKompass += cntKompass / 41; |
|
- | 81 | if(cntKompass > 10) KompassValue = cntKompass - 10; else KompassValue = 0; |
|
- | 82 | } |
|
- | 83 | // if(cntKompass < 10) cntKompass = 10; |
|
- | 84 | // KompassValue = (unsigned long)((unsigned long)(cntKompass-10)*720L + 1L) / 703L; |
|
- | 85 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
|
80 | cntKompass = 0; |
86 | cntKompass = 0; |
Line 81... | Line 87... | ||
81 | } |
87 | } |
82 | } |
- | |
83 | } |
88 | } |
- | 89 | } |
|
84 | 90 | ||
85 | //---------------------------- |
91 | //---------------------------- |
86 | 92 | void Timer_Init(void) |
|
87 | void Timer_Init(void) { |
93 | { |
88 | tim_main = SetDelay(10); |
94 | tim_main = SetDelay(10); |
89 | TCCR0B = CK8; |
95 | TCCR0B = CK8; |
90 | TCCR0A = (1 << COM0A1) | (1 << COM0B1) | 3; //fast PWM |
96 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
Line 91... | Line 97... | ||
91 | OCR0A = 0; |
97 | OCR0A = 0; |
92 | OCR0B = 120; |
98 | OCR0B = 120; |
93 | TCNT0 = (unsigned char) - TIMER_RELOAD_VALUE; // reload |
99 | TCNT0 = (unsigned char)-TIMER_RELOAD_VALUE; // reload |
94 | //OCR1 = 0x00; |
100 | //OCR1 = 0x00; |
95 | 101 | ||
96 | TCCR2A = (1 << COM2A1) | (1 << COM2A0) | 3; |
102 | TCCR2A=(1<<COM2A1)|(1<<COM2A0)|3; |
Line 97... | Line 103... | ||
97 | // TCCR2B=(0<<CS20)|(1<<CS21)|(1<<CS22); // clk/256 |
103 | // TCCR2B=(0<<CS20)|(1<<CS21)|(1<<CS22); // clk/256 |
98 | TCCR2B = (0 << CS20) | (0 << CS21) | (1 << CS22); // clk/64 |
104 | TCCR2B=(0<<CS20)|(0<<CS21)|(1<<CS22); // clk/64 |
99 | 105 | ||
100 | 106 | ||
101 | TIMSK2 |= _BV(OCIE2A); |
107 | TIMSK2 |= _BV(OCIE2A); |
Line 102... | Line 108... | ||
102 | 108 | ||
Line 103... | Line 109... | ||
103 | TIMSK0 |= _BV(TOIE0); |
109 | TIMSK0 |= _BV(TOIE0); |
- | 110 | OCR2A = 10; |
|
104 | OCR2A = 10; |
111 | TCNT2 = 0; |
105 | TCNT2 = 0; |
112 | |
106 | 113 | } |
|
107 | } |
114 | |
Line 108... | Line 115... | ||
108 | 115 | // ----------------------------------------------------------------------- |
|
109 | // ----------------------------------------------------------------------- |
- | |
110 | 116 | ||
- | 117 | unsigned int SetDelay (unsigned int t) |
|
111 | unsigned int SetDelay(unsigned int t) { |
118 | { |
112 | // TIMSK0 &= ~_BV(TOIE0); |
119 | // TIMSK0 &= ~_BV(TOIE0); |
113 | return (CountMilliseconds + t + 1); |
120 | return(CountMilliseconds + t + 1); |
114 | // TIMSK0 |= _BV(TOIE0); |
121 | // TIMSK0 |= _BV(TOIE0); |
Line 115... | Line 122... | ||
115 | } |
122 | } |
116 | - | ||
117 | // ----------------------------------------------------------------------- |
123 | |
- | 124 | // ----------------------------------------------------------------------- |
|
118 | 125 | char CheckDelay(unsigned int t) |
|
119 | char CheckDelay(unsigned int t) { |
126 | { |
120 | // TIMSK0 &= ~_BV(TOIE0); |
127 | // TIMSK0 &= ~_BV(TOIE0); |
121 | return (((t - CountMilliseconds) & 0x8000) >> 9); |
128 | return(((t - CountMilliseconds) & 0x8000) >> 9); |
Line 122... | Line 129... | ||
122 | // TIMSK0 |= _BV(TOIE0); |
129 | // TIMSK0 |= _BV(TOIE0); |
- | 130 | } |
|
123 | } |
131 | |
124 | 132 | // ----------------------------------------------------------------------- |
|
125 | // ----------------------------------------------------------------------- |
133 | void Delay_ms(unsigned int w) |
126 | - | ||
127 | void Delay_ms(unsigned int w) { |
134 | { |
Line 128... | Line 135... | ||
128 | unsigned int akt; |
135 | unsigned int akt; |
129 | akt = SetDelay(w); |
136 | akt = SetDelay(w); |
130 | while (!CheckDelay(akt)); |
137 | while (!CheckDelay(akt)); |
131 | } |
- | |
132 | 138 | } |
|
Line 133... | Line 139... | ||
133 | void Delay_ms_Mess(unsigned int w) { |
139 | |
134 | unsigned int akt; |
140 | void Delay_ms_Mess(unsigned int w) |
135 | akt = SetDelay(w); |
141 | { |
136 | while (!CheckDelay(akt)) |
142 | unsigned int akt; |
137 | ANALOG_ON; |
143 | akt = SetDelay(w); |
138 | } |
144 | while (!CheckDelay(akt)) ANALOG_ON; |
139 | 145 | } |
|
140 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
146 | |
Line 141... | Line 147... | ||
141 | // Servo ansteuern |
147 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 142... | Line 148... | ||
142 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
148 | // Servo ansteuern |
143 | 149 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
144 | SIGNAL(SIG_OVERFLOW2) { |
150 | SIGNAL(SIG_OVERFLOW2) { |
145 | 151 | ||
146 | if (ServoState > 0) |
152 | if (ServoState > 0) |
147 | PORTD |= 0x80; |
153 | PORTD |= 0x80; |
148 | else |
154 | else |
149 | PORTD &= ~0x80; |
155 | PORTD &= ~0x80; |
150 | 156 | ||
151 | TCCR2A = 3; |
157 | TCCR2A = 3; |
152 | TIMSK2 &= ~_BV(TOIE2); |
158 | TIMSK2 &= ~_BV( TOIE2 ); |
153 | } |
159 | } |
154 | 160 | ||
155 | SIGNAL(SIG_OUTPUT_COMPARE2A) { |
161 | SIGNAL(SIG_OUTPUT_COMPARE2A) { |
156 | 162 | ||
157 | static unsigned char postPulse = 0x80; |
163 | static unsigned char postPulse = 0x80; |
158 | static int filterServo = 100; |
164 | static int filterServo = 100; |
159 | 165 | ||
160 | if (ServoState == 4) { |
166 | if( ServoState == 4 ) { |
161 | 167 | ||
162 | ServoValue = 0x0030; // Offset Part1 |
168 | ServoValue = 0x0030; // Offset Part1 |
163 | filterServo = (filterServo * 3 + (int) Parameter_ServoNickControl * 2) >> DIV_4; |
169 | filterServo = ( filterServo * 3 + (int) Parameter_ServoNickControl * 2 ) >> DIV_4; |
164 | ServoValue += filterServo; |
170 | ServoValue += filterServo; |
165 | 171 | ||
- | 172 | // Min und Max vorverlegt, damit sich diese auf ServoNickControl beziehen und ggf. noch Nick-kompensiert werden |
|
166 | // Min und Max vorverlegt, damit sich diese auf ServoNickControl beziehen und ggf. noch Nick-kompensiert werden |
173 | if( ServoValue < ( (int) EE_Parameter.ServoNickMin * 3 ) ) |
167 | if (ServoValue < ((int) EE_Parameter.ServoNickMin * 3)) |
174 | ServoValue = (int) EE_Parameter.ServoNickMin * 3; |
168 | ServoValue = (int) EE_Parameter.ServoNickMin * 3; |
175 | else if( ServoValue > ( (int) EE_Parameter.ServoNickMax * 3 ) ) |
169 | else if (ServoValue > ((int) EE_Parameter.ServoNickMax * 3)) |
176 | ServoValue = (int) EE_Parameter.ServoNickMax * 3; |
170 | ServoValue = (int) EE_Parameter.ServoNickMax * 3; |
177 | |
171 | 178 | long integral; |
|
172 | long integral; |
179 | |
173 | 180 | /* Über Parameter läßt sich zwischen "+" und "X" - Formations |
|
174 | /* Über Parameter läßt sich zwischen "+" und "X" - Formations |
181 | * umschalten (sh. parameter.h) |
175 | * umschalten (sh. parameter.h) |
182 | */ |
176 | */ |
183 | if( PARAM_X_FORMATION ) { |
177 | if (PARAM_X_FORMATION) |
184 | integral = IntegralNick - IntegralRoll; |
178 | integral = IntegralNick - IntegralRoll; |
185 | } else { |
- | 186 | integral = IntegralNick; |
|
179 | else |
187 | } |
180 | integral = IntegralNick; |
188 | |
181 | 189 | if( EE_Parameter.ServoNickCompInvert & 0x01 ) |
|
182 | if (EE_Parameter.ServoNickCompInvert & 0x01) |
190 | ServoValue += ( (long) ( (long) EE_Parameter.ServoNickComp * integral ) >> DIV_128 ) / ( 512L >> DIV_4 ); |
183 | ServoValue += ((long) ((long) EE_Parameter.ServoNickComp * integral) >> DIV_128) / (512L >> DIV_4); |
191 | else |
184 | else |
192 | ServoValue -= ( (long) ( (long) EE_Parameter.ServoNickComp * integral ) >> DIV_128 ) / ( 512L >> DIV_4 ); |
185 | ServoValue -= ((long) ((long) EE_Parameter.ServoNickComp * integral) >> DIV_128) / (512L >> DIV_4); |
193 | |
186 | 194 | DebugOut.Analog[20] = ServoValue; |
|
187 | DebugOut.Analog[20] = ServoValue; |
195 | |
188 | 196 | if ( ( ServoValue % 255 ) < 45 ) { |
|
189 | if ((ServoValue % 255) < 45) { |
197 | ServoValue += 77; |
190 | ServoValue += 77; |
198 | postPulse = 0x60 - 77; |
191 | postPulse = 0x60 - 77; |
199 | } else { |
192 | } else |
200 | postPulse = 0x60; |
193 | postPulse = 0x60; |
201 | } |
194 | 202 | ||
195 | OCR2A = 255 - (ServoValue % 256); |
203 | OCR2A = 255 - ( ServoValue % 256 ); |
196 | TCCR2A = (1 << COM2A1) | (1 << COM2A0) | 3; |
204 | TCCR2A = (1 << COM2A1 ) | ( 1 << COM2A0 ) | 3; |
197 | 205 | ||
198 | } else if ((ServoState > 0) && (ServoState < 4)) { |
206 | } else if( ( ServoState > 0 ) && ( ServoState < 4 ) ) { |
199 | 207 | ||
200 | if (ServoValue > 255) { |
208 | if( ServoValue > 255 ) { |
201 | PORTD |= 0x80; |
209 | PORTD |= 0x80; |
202 | TCCR2A = 3; |
210 | TCCR2A = 3; |