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