Rev 943 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 943 | Rev 950 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
2 | // + Copyright (c) 04.2007 Holger Buss |
3 | // + Nur für den privaten Gebrauch |
3 | // + Nur für den privaten Gebrauch |
4 | // + www.MikroKopter.com |
4 | // + www.MikroKopter.com |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist. |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist. |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
17 | // + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
17 | // + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
21 | // + Benutzung auf eigene Gefahr |
21 | // + Benutzung auf eigene Gefahr |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
25 | // + mit unserer Zustimmung zulässig |
25 | // + mit unserer Zustimmung zulässig |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
30 | // + this list of conditions and the following disclaimer. |
30 | // + this list of conditions and the following disclaimer. |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
32 | // + from this software without specific prior written permission. |
32 | // + from this software without specific prior written permission. |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
34 | // + for non-commercial use (directly or indirectly) |
34 | // + for non-commercial use (directly or indirectly) |
35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
36 | // + with our written permission |
36 | // + with our written permission |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
38 | // + clearly linked as origin |
38 | // + clearly linked as origin |
39 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
39 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | #include <avr/boot.h> |
52 | #include <avr/boot.h> |
53 | 53 | ||
54 | #include <avr/io.h> |
54 | #include <avr/io.h> |
55 | #include <avr/interrupt.h> |
55 | #include <avr/interrupt.h> |
56 | 56 | ||
57 | #include "main.h" |
57 | #include "main.h" |
58 | #include "timer0.h" |
58 | #include "timer0.h" |
59 | #include "timer2.h" |
59 | #include "timer2.h" |
60 | #include "uart.h" |
60 | #include "uart.h" |
61 | #if defined (__AVR_ATmega644P__) |
61 | #if defined (__AVR_ATmega644P__) |
62 | #include "uart1.h" |
62 | #include "uart1.h" |
63 | #endif |
63 | #endif |
64 | #include "led.h" |
64 | #include "led.h" |
65 | #include "menu.h" |
65 | #include "menu.h" |
66 | #include "fc.h" |
66 | #include "fc.h" |
67 | #include "rc.h" |
67 | #include "rc.h" |
68 | #include "analog.h" |
68 | #include "analog.h" |
69 | #include "printf_P.h" |
69 | #include "printf_P.h" |
70 | #ifdef USE_KILLAGREG |
70 | #ifdef USE_KILLAGREG |
71 | #include "mm3.h" |
71 | #include "mm3.h" |
72 | #endif |
72 | #endif |
73 | #ifdef USE_NAVICTRL |
73 | #ifdef USE_NAVICTRL |
74 | #include "spi.h" |
74 | #include "spi.h" |
75 | #endif |
75 | #endif |
76 | #ifdef USE_MK3MAG |
76 | #ifdef USE_MK3MAG |
77 | #include "mk3mag.h" |
77 | #include "mk3mag.h" |
78 | #endif |
78 | #endif |
79 | #include "twimaster.h" |
79 | #include "twimaster.h" |
80 | #include "eeprom.h" |
80 | #include "eeprom.h" |
81 | #include "_Settings.h" |
81 | #include "_Settings.h" |
82 | 82 | ||
83 | 83 | ||
84 | uint8_t BoardRelease = 10; |
84 | uint8_t BoardRelease = 10; |
85 | 85 | ||
86 | 86 | ||
87 | //############################################################################ |
87 | //############################################################################ |
88 | //Hauptprogramm |
88 | //Hauptprogramm |
89 | int main (void) |
89 | int main (void) |
90 | //############################################################################ |
90 | //############################################################################ |
91 | { |
91 | { |
92 | unsigned int timer; |
92 | unsigned int timer; |
93 | 93 | ||
94 | // disable interrupts global |
94 | // disable interrupts global |
95 | cli(); |
95 | cli(); |
96 | 96 | ||
97 | // get board release |
97 | // get board release |
98 | DDRB = 0x00; |
98 | DDRB = 0x00; |
99 | PORTB = 0x00; |
99 | PORTB = 0x00; |
100 | for(timer = 0; timer < 1000; timer++); // make some delay |
100 | for(timer = 0; timer < 1000; timer++); // make some delay |
101 | if(PINB & (1<<PINB0)) |
101 | if(PINB & (1<<PINB0)) |
102 | { |
102 | { |
103 | if(PINB & (1<<PINB1)) BoardRelease = 13; |
103 | if(PINB & (1<<PINB1)) BoardRelease = 13; |
104 | else BoardRelease = 11; |
104 | else BoardRelease = 11; |
105 | } |
105 | } |
106 | else BoardRelease = 10; |
106 | else BoardRelease = 10; |
107 | 107 | ||
108 | // set LED ports as output |
108 | // set LED ports as output |
109 | DDRB |= (1<<DDB1)|(1<<DDB0); |
109 | DDRB |= (1<<DDB1)|(1<<DDB0); |
110 | RED_ON; |
110 | RED_ON; |
111 | GRN_OFF; |
111 | GRN_OFF; |
112 | 112 | ||
113 | // disable watchdog |
113 | // disable watchdog |
114 | MCUSR &=~(1<<WDRF); |
114 | MCUSR &=~(1<<WDRF); |
115 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
115 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
116 | WDTCSR = 0; |
116 | WDTCSR = 0; |
117 | 117 | ||
118 | BeepTime = 2000; |
118 | BeepTime = 2000; |
119 | 119 | ||
120 | PPM_in[CH_GAS] = 0; |
120 | PPM_in[CH_GAS] = 0; |
121 | StickYaw = 0; |
121 | StickYaw = 0; |
122 | StickRoll = 0; |
122 | StickRoll = 0; |
123 | StickNick = 0; |
123 | StickNick = 0; |
124 | 124 | ||
125 | RED_OFF; |
125 | RED_OFF; |
126 | 126 | ||
127 | // initalize modules |
127 | // initalize modules |
128 | //LED_Init(); Is done within ParamSet_Init() below |
128 | //LED_Init(); Is done within ParamSet_Init() below |
129 | TIMER0_Init(); |
129 | TIMER0_Init(); |
130 | TIMER2_Init(); |
130 | TIMER2_Init(); |
131 | USART0_Init(); |
131 | USART0_Init(); |
132 | 132 | ||
133 | #if defined (__AVR_ATmega644P__) |
133 | #if defined (__AVR_ATmega644P__) |
134 | if (BoardRelease == 11) USART1_Init(); |
134 | if (BoardRelease > 10) USART1_Init(); |
135 | #endif |
135 | #endif |
136 | 136 | ||
137 | RC_Init(); |
137 | RC_Init(); |
138 | ADC_Init(); |
138 | ADC_Init(); |
139 | I2C_Init(); |
139 | I2C_Init(); |
140 | 140 | ||
141 | 141 | ||
142 | #ifdef USE_NAVICTRL |
142 | #ifdef USE_NAVICTRL |
143 | SPI_MasterInit(); |
143 | SPI_MasterInit(); |
144 | #endif |
144 | #endif |
145 | #ifdef USE_KILLAGREG |
145 | #ifdef USE_KILLAGREG |
146 | MM3_Init(); |
146 | MM3_Init(); |
147 | #endif |
147 | #endif |
148 | #ifdef USE_MK3MAG |
148 | #ifdef USE_MK3MAG |
149 | MK3MAG_Init(); |
149 | MK3MAG_Init(); |
150 | #endif |
150 | #endif |
151 | 151 | ||
152 | 152 | ||
153 | // enable interrupts global |
153 | // enable interrupts global |
154 | sei(); |
154 | sei(); |
155 | 155 | ||
156 | VersionInfo.Major = VERSION_MAJOR; |
156 | VersionInfo.Major = VERSION_MAJOR; |
157 | VersionInfo.Minor = VERSION_MINOR; |
157 | VersionInfo.Minor = VERSION_MINOR; |
158 | VersionInfo.PCCompatible = VERSION_COMPATIBLE; |
158 | VersionInfo.PCCompatible = VERSION_COMPATIBLE; |
159 | VersionInfo.Hardware = 1; // Flight Control |
159 | VersionInfo.Hardware = 1; // Flight Control |
160 | 160 | ||
161 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",BoardRelease/10,BoardRelease%10, VERSION_MAJOR, VERSION_MINOR,VERSION_INDEX + 'a'); |
161 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",BoardRelease/10,BoardRelease%10, VERSION_MAJOR, VERSION_MINOR,VERSION_INDEX + 'a'); |
162 | printf("\n\r=============================="); |
162 | printf("\n\r=============================="); |
163 | GRN_ON; |
163 | GRN_ON; |
164 | 164 | ||
165 | // Parameter set handling |
165 | // Parameter set handling |
166 | ParamSet_Init(); |
166 | ParamSet_Init(); |
167 | 167 | ||
168 | if(GetParamWord(PID_ACC_NICK) > 1023) |
168 | if(GetParamWord(PID_ACC_NICK) > 1023) |
169 | { |
169 | { |
170 | printf("\n\rACC not calibrated!"); |
170 | printf("\n\rACC not calibrated!"); |
171 | } |
171 | } |
172 | 172 | ||
173 | //wait for a short time (otherwise the RC channel check won't work below) |
173 | //wait for a short time (otherwise the RC channel check won't work below) |
174 | timer = SetDelay(500); |
174 | timer = SetDelay(500); |
175 | while(!CheckDelay(timer)); |
175 | while(!CheckDelay(timer)); |
176 | 176 | ||
177 | 177 | ||
178 | if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) |
178 | if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) |
179 | { |
179 | { |
180 | printf("\n\rCalibrating air pressure sensor.."); |
180 | printf("\n\rCalibrating air pressure sensor.."); |
181 | timer = SetDelay(1000); |
181 | timer = SetDelay(1000); |
182 | SearchAirPressureOffset(); |
182 | SearchAirPressureOffset(); |
183 | while (!CheckDelay(timer)); |
183 | while (!CheckDelay(timer)); |
184 | printf("OK\n\r"); |
184 | printf("OK\n\r"); |
185 | } |
185 | } |
186 | 186 | ||
187 | #ifdef USE_NAVICTRL |
187 | #ifdef USE_NAVICTRL |
188 | printf("\n\rSupport for NaviCtrl"); |
188 | printf("\n\rSupport for NaviCtrl"); |
189 | #endif |
189 | #endif |
190 | 190 | ||
191 | #ifdef USE_KILLAGREG |
191 | #ifdef USE_KILLAGREG |
192 | printf("\n\rSupport for MicroMag3 Compass"); |
192 | printf("\n\rSupport for MicroMag3 Compass"); |
193 | #endif |
193 | #endif |
194 | #ifdef USE_MK3MAG |
194 | #ifdef USE_MK3MAG |
195 | printf("\n\rSupport for MK3MAG Compass"); |
195 | printf("\n\rSupport for MK3MAG Compass"); |
196 | #endif |
196 | #endif |
197 | 197 | ||
198 | 198 | ||
199 | 199 | ||
200 | #if defined (USE_KILLAGREG) || defined (USE_MK3MAG) |
200 | #if defined (USE_KILLAGREG) || defined (USE_MK3MAG) |
201 | #if defined (__AVR_ATmega644P__) |
201 | #if defined (__AVR_ATmega644P__) |
202 | if(BoardRelease == 10) |
202 | if(BoardRelease == 10) |
203 | { |
203 | { |
204 | printf("\n\rSupport for GPS at 1st UART"); |
204 | printf("\n\rSupport for GPS at 1st UART"); |
205 | } |
205 | } |
206 | else |
206 | else |
207 | { |
207 | { |
208 | printf("\n\rSupport for GPS at 2nd UART"); |
208 | printf("\n\rSupport for GPS at 2nd UART"); |
209 | } |
209 | } |
210 | #else // (__AVR_ATmega644__) |
210 | #else // (__AVR_ATmega644__) |
211 | printf("\n\rSupport for GPS at 1st UART"); |
211 | printf("\n\rSupport for GPS at 1st UART"); |
212 | #endif |
212 | #endif |
213 | #endif |
213 | #endif |
214 | 214 | ||
215 | 215 | ||
216 | 216 | ||
217 | SetNeutral(); |
217 | SetNeutral(); |
218 | 218 | ||
219 | RED_OFF; |
219 | RED_OFF; |
220 | 220 | ||
221 | BeepTime = 2000; |
221 | BeepTime = 2000; |
222 | ExternControl.Digital[0] = 0x55; |
222 | ExternControl.Digital[0] = 0x55; |
223 | 223 | ||
224 | 224 | ||
225 | printf("\n\rControl: "); |
225 | printf("\n\rControl: "); |
226 | if (ParamSet.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
226 | if (ParamSet.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
227 | else printf("Neutral"); |
227 | else printf("Neutral"); |
228 | 228 | ||
229 | printf("\n\n\r"); |
229 | printf("\n\n\r"); |
230 | 230 | ||
231 | LCD_Clear(); |
231 | LCD_Clear(); |
232 | 232 | ||
233 | I2CTimeout = 2000; |
233 | I2CTimeout = 2000; |
234 | 234 | ||
235 | while (1) |
235 | while (1) |
236 | { |
236 | { |
237 | if(UpdateMotor) // control interval |
237 | if(UpdateMotor) // control interval |
238 | { |
238 | { |
239 | UpdateMotor = 0; // reset Flag, is enabled every 2 ms by isr of timer0 |
239 | UpdateMotor = 0; // reset Flag, is enabled every 2 ms by isr of timer0 |
240 | //PORTD |= (1<<PORTD4); |
240 | //PORTD |= (1<<PORTD4); |
241 | MotorControl(); |
241 | MotorControl(); |
242 | //PORTD &= ~(1<<PORTD4); |
242 | //PORTD &= ~(1<<PORTD4); |
243 | 243 | ||
244 | SendMotorData(); |
244 | SendMotorData(); |
245 | 245 | ||
246 | RED_OFF; |
246 | RED_OFF; |
247 | 247 | ||
248 | if(PcAccess) PcAccess--; |
248 | if(PcAccess) PcAccess--; |
249 | else |
249 | else |
250 | { |
250 | { |
251 | DubWiseKeys[0] = 0; |
251 | DubWiseKeys[0] = 0; |
252 | DubWiseKeys[1] = 0; |
252 | DubWiseKeys[1] = 0; |
253 | ExternControl.Config = 0; |
253 | ExternControl.Config = 0; |
254 | ExternStickNick= 0; |
254 | ExternStickNick= 0; |
255 | ExternStickRoll = 0; |
255 | ExternStickRoll = 0; |
256 | ExternStickYaw = 0; |
256 | ExternStickYaw = 0; |
257 | } |
257 | } |
258 | 258 | ||
259 | if(!I2CTimeout) |
259 | if(!I2CTimeout) |
260 | { |
260 | { |
261 | I2CTimeout = 5; |
261 | I2CTimeout = 5; |
262 | I2C_Reset(); |
262 | I2C_Reset(); |
263 | if((BeepModulation == 0xFFFF) && (MKFlags & MKFLAG_MOTOR_RUN) ) |
263 | if((BeepModulation == 0xFFFF) && (MKFlags & MKFLAG_MOTOR_RUN) ) |
264 | { |
264 | { |
265 | BeepTime = 10000; // 1 second |
265 | BeepTime = 10000; // 1 second |
266 | BeepModulation = 0x0080; |
266 | BeepModulation = 0x0080; |
267 | } |
267 | } |
268 | } |
268 | } |
269 | else |
269 | else |
270 | { |
270 | { |
271 | I2CTimeout--; |
271 | I2CTimeout--; |
272 | RED_OFF; |
272 | RED_OFF; |
273 | } |
273 | } |
274 | 274 | ||
275 | if(SIO_DEBUG && (!UpdateMotor || !(MKFlags & MKFLAG_MOTOR_RUN) )) |
275 | if(SIO_DEBUG && (!UpdateMotor || !(MKFlags & MKFLAG_MOTOR_RUN) )) |
276 | { |
276 | { |
277 | USART0_TransmitTxData(); |
277 | USART0_TransmitTxData(); |
278 | USART0_ProcessRxData(); |
278 | USART0_ProcessRxData(); |
279 | } |
279 | } |
280 | else USART0_ProcessRxData(); |
280 | else USART0_ProcessRxData(); |
281 | 281 | ||
282 | if(CheckDelay(timer)) |
282 | if(CheckDelay(timer)) |
283 | { |
283 | { |
284 | if(UBat < ParamSet.LowVoltageWarning) |
284 | if(UBat < ParamSet.LowVoltageWarning) |
285 | { |
285 | { |
286 | if(BeepModulation == 0xFFFF) |
286 | if(BeepModulation == 0xFFFF) |
287 | { |
287 | { |
288 | BeepTime = 6000; // 0.6 seconds |
288 | BeepTime = 6000; // 0.6 seconds |
289 | BeepModulation = 0x0300; |
289 | BeepModulation = 0x0300; |
290 | } |
290 | } |
291 | } |
291 | } |
292 | #ifdef USE_NAVICTRL |
292 | #ifdef USE_NAVICTRL |
293 | SPI_StartTransmitPacket(); |
293 | SPI_StartTransmitPacket(); |
294 | SendSPI = 4; |
294 | SendSPI = 4; |
295 | #endif |
295 | #endif |
296 | timer = SetDelay(20); // every 20 ms |
296 | timer = SetDelay(20); // every 20 ms |
297 | } |
297 | } |
298 | 298 | ||
299 | LED_Update(); |
299 | LED_Update(); |
300 | } |
300 | } |
301 | 301 | ||
302 | #ifdef USE_NAVICTRL |
302 | #ifdef USE_NAVICTRL |
303 | if(!SendSPI) |
303 | if(!SendSPI) |
304 | { // SendSPI is decremented in timer0.c with a rate of 9.765 kHz. |
304 | { // SendSPI is decremented in timer0.c with a rate of 9.765 kHz. |
305 | // within the SPI_TransmitByte() routine the value is set to 4. |
305 | // within the SPI_TransmitByte() routine the value is set to 4. |
306 | // I.e. the SPI_TransmitByte() is called at a rate of 9.765 kHz/4= 2441.25 Hz, |
306 | // I.e. the SPI_TransmitByte() is called at a rate of 9.765 kHz/4= 2441.25 Hz, |
307 | // and therefore the time of transmission of a complete spi-packet (32 bytes) is 32*4/9.765 kHz = 13.1 ms. |
307 | // and therefore the time of transmission of a complete spi-packet (32 bytes) is 32*4/9.765 kHz = 13.1 ms. |
308 | SPI_TransmitByte(); |
308 | SPI_TransmitByte(); |
309 | } |
309 | } |
310 | #endif |
310 | #endif |
311 | } |
311 | } |
312 | return (1); |
312 | return (1); |
313 | } |
313 | } |
314 | 314 | ||
315 | 315 |