Rev 64 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 64 | Rev 92 | ||
---|---|---|---|
1 | /*####################################################################################### |
1 | /*####################################################################################### |
2 | Flight Control |
2 | Flight Control |
3 | #######################################################################################*/ |
3 | #######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Regler für Brushless-Motoren |
5 | // + Regler für Brushless-Motoren |
6 | // + ATMEGA8 mit 8MHz |
6 | // + ATMEGA8 mit 8MHz |
7 | // + Nur für den privaten Gebrauch |
7 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
8 | // + Copyright (c) 12.2007 Holger Buss |
8 | // + Copyright (c) 12.2007 Holger Buss |
9 | // + www.MikroKopter.com |
9 | // + www.MikroKopter.com |
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
11 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
11 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
12 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
12 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
13 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
13 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
14 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
14 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
15 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
15 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
16 | // + Verkauf von Luftbildaufnahmen, usw. |
16 | // + Verkauf von Luftbildaufnahmen, usw. |
17 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
18 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
18 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
19 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
19 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
20 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
21 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
21 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
22 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
22 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
23 | // + eindeutig als Ursprung verlinkt werden |
23 | // + eindeutig als Ursprung verlinkt werden |
24 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
25 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
25 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
26 | // + Benutzung auf eigene Gefahr |
26 | // + Benutzung auf eigene Gefahr |
27 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
27 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
29 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
30 | // + mit unserer Zustimmung zulässig |
30 | // + mit unserer Zustimmung zulässig |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
32 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
35 | // + this list of conditions and the following disclaimer. |
35 | // + this list of conditions and the following disclaimer. |
36 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
37 | // + from this software without specific prior written permission. |
37 | // + from this software without specific prior written permission. |
38 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
38 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
39 | // + for non-commercial use (directly or indirectly) |
39 | // + for non-commercial use (directly or indirectly) |
40 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
40 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
41 | // + with our written permission |
41 | // + with our written permission |
42 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
42 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
43 | // + clearly linked as origin |
43 | // + clearly linked as origin |
44 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
44 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
53 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
53 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
54 | // + POSSIBILITY OF SUCH DAMAGE. |
54 | // + POSSIBILITY OF SUCH DAMAGE. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | #include "main.h" |
56 | #include "main.h" |
57 | 57 | ||
58 | volatile unsigned char Phase = 0,ShadowTCCR1A = 0; |
58 | volatile unsigned char Phase = 0,ShadowTCCR1A = 0; |
59 | volatile unsigned char CompFreigabeTimer = 100; |
59 | volatile unsigned char CompFreigabeTimer = 100; |
60 | volatile unsigned char CompInterruptFreigabe = 0; |
60 | volatile unsigned char CompInterruptFreigabe = 0; |
61 | 61 | ||
62 | 62 | ||
63 | //############################################################################ |
63 | //############################################################################ |
64 | // |
64 | // |
65 | SIGNAL(SIG_OVERFLOW2) |
65 | SIGNAL(SIG_OVERFLOW2) |
66 | //############################################################################ |
66 | //############################################################################ |
67 | { |
67 | { |
68 | } |
68 | } |
69 | 69 | ||
70 | //############################################################################ |
70 | //############################################################################ |
71 | // + Interruptroutine |
71 | // + Interruptroutine |
72 | // + Wird durch den Analogkomperator ausgelöst |
72 | // + Wird durch den Analogkomperator ausgelöst |
73 | // + Dadurch wird das Kommutieren erzeugt |
73 | // + Dadurch wird das Kommutieren erzeugt |
74 | SIGNAL(SIG_COMPARATOR) |
74 | SIGNAL(SIG_COMPARATOR) |
75 | //############################################################################ |
75 | //############################################################################ |
76 | { |
76 | { |
77 | unsigned char sense = 0; |
77 | unsigned char sense = 0; |
78 | do |
78 | do |
79 | { |
79 | { |
80 | if(SENSE_H) sense = 1; else sense = 0; |
80 | if(SENSE_H) sense = 1; else sense = 0; |
81 | switch(Phase) |
81 | switch(Phase) |
82 | { |
82 | { |
83 | case 0: |
83 | case 0: |
84 | STEUER_A_H; |
84 | STEUER_A_H; |
85 | if(sense) |
85 | if(sense) |
86 | { |
86 | { |
87 | STEUER_C_L; |
87 | STEUER_C_L; |
88 | if(ZeitZumAdWandeln) AdConvert(); |
88 | if(ZeitZumAdWandeln) AdConvert(); |
89 | SENSE_FALLING_INT; |
89 | SENSE_FALLING_INT; |
90 | SENSE_B; |
90 | SENSE_B; |
91 | Phase++; |
91 | Phase++; |
92 | CntKommutierungen++; |
92 | CntKommutierungen++; |
93 | } |
93 | } |
94 | else |
94 | else |
95 | { |
95 | { |
96 | STEUER_B_L; |
96 | STEUER_B_L; |
97 | } |
97 | } |
98 | break; |
98 | break; |
99 | case 1: |
99 | case 1: |
100 | STEUER_C_L; |
100 | STEUER_C_L; |
101 | if(!sense) |
101 | if(!sense) |
102 | { |
102 | { |
103 | STEUER_B_H; |
103 | STEUER_B_H; |
104 | if(ZeitZumAdWandeln) AdConvert(); |
104 | if(ZeitZumAdWandeln) AdConvert(); |
105 | SENSE_A; |
105 | SENSE_A; |
106 | SENSE_RISING_INT; |
106 | SENSE_RISING_INT; |
107 | Phase++; |
107 | Phase++; |
108 | CntKommutierungen++; |
108 | CntKommutierungen++; |
109 | } |
109 | } |
110 | else |
110 | else |
111 | { |
111 | { |
112 | STEUER_A_H; |
112 | STEUER_A_H; |
113 | } |
113 | } |
114 | 114 | ||
115 | break; |
115 | break; |
116 | case 2: |
116 | case 2: |
117 | STEUER_B_H; |
117 | STEUER_B_H; |
118 | if(sense) |
118 | if(sense) |
119 | { |
119 | { |
120 | STEUER_A_L; |
120 | STEUER_A_L; |
121 | if(ZeitZumAdWandeln) AdConvert(); |
121 | if(ZeitZumAdWandeln) AdConvert(); |
122 | SENSE_C; |
122 | SENSE_C; |
123 | SENSE_FALLING_INT; |
123 | SENSE_FALLING_INT; |
124 | Phase++; |
124 | Phase++; |
125 | CntKommutierungen++; |
125 | CntKommutierungen++; |
126 | } |
126 | } |
127 | else |
127 | else |
128 | { |
128 | { |
129 | STEUER_C_L; |
129 | STEUER_C_L; |
130 | } |
130 | } |
131 | 131 | ||
132 | break; |
132 | break; |
133 | case 3: |
133 | case 3: |
134 | STEUER_A_L; |
134 | STEUER_A_L; |
135 | if(!sense) |
135 | if(!sense) |
136 | { |
136 | { |
137 | STEUER_C_H; |
137 | STEUER_C_H; |
138 | if(ZeitZumAdWandeln) AdConvert(); |
138 | if(ZeitZumAdWandeln) AdConvert(); |
139 | SENSE_B; |
139 | SENSE_B; |
140 | SENSE_RISING_INT; |
140 | SENSE_RISING_INT; |
141 | Phase++; |
141 | Phase++; |
142 | CntKommutierungen++; |
142 | CntKommutierungen++; |
143 | } |
143 | } |
144 | else |
144 | else |
145 | { |
145 | { |
146 | STEUER_B_H; |
146 | STEUER_B_H; |
147 | } |
147 | } |
148 | 148 | ||
149 | 149 | ||
150 | break; |
150 | break; |
151 | case 4: |
151 | case 4: |
152 | STEUER_C_H; |
152 | STEUER_C_H; |
153 | if(sense) |
153 | if(sense) |
154 | { |
154 | { |
155 | STEUER_B_L; |
155 | STEUER_B_L; |
156 | if(ZeitZumAdWandeln) AdConvert(); |
156 | if(ZeitZumAdWandeln) AdConvert(); |
157 | SENSE_A; |
157 | SENSE_A; |
158 | SENSE_FALLING_INT; |
158 | SENSE_FALLING_INT; |
159 | Phase++; |
159 | Phase++; |
160 | CntKommutierungen++; |
160 | CntKommutierungen++; |
161 | } |
161 | } |
162 | else |
162 | else |
163 | { |
163 | { |
164 | STEUER_A_L; |
164 | STEUER_A_L; |
165 | } |
165 | } |
166 | 166 | ||
167 | break; |
167 | break; |
168 | case 5: |
168 | case 5: |
169 | STEUER_B_L; |
169 | STEUER_B_L; |
170 | if(!sense) |
170 | if(!sense) |
171 | { |
171 | { |
172 | STEUER_A_H; |
172 | STEUER_A_H; |
173 | if(ZeitZumAdWandeln) AdConvert(); |
173 | if(ZeitZumAdWandeln) AdConvert(); |
174 | SENSE_C; |
174 | SENSE_C; |
175 | SENSE_RISING_INT; |
175 | SENSE_RISING_INT; |
176 | Phase = 0; |
176 | Phase = 0; |
177 | CntKommutierungen++; |
177 | CntKommutierungen++; |
178 | } |
178 | } |
179 | else |
179 | else |
180 | { |
180 | { |
181 | STEUER_C_H; |
181 | STEUER_C_H; |
182 | } |
182 | } |
183 | break; |
183 | break; |
184 | } |
184 | } |
185 | } |
185 | } |
186 | while((SENSE_L && sense) || (SENSE_H && !sense)); |
186 | while((SENSE_L && sense) || (SENSE_H && !sense)); |
187 | ZeitZumAdWandeln = 0; |
187 | ZeitZumAdWandeln = 0; |
188 | } |
188 | } |
189 | 189 | ||
190 | //############################################################################ |
190 | //############################################################################ |
191 | // |
191 | // |
192 | void Manuell(void) |
192 | void Manuell(void) |
193 | //############################################################################ |
193 | //############################################################################ |
194 | { |
194 | { |
195 | switch(Phase) |
195 | switch(Phase) |
196 | { |
196 | { |
197 | case 0: |
197 | case 0: |
198 | STEUER_A_H; |
198 | STEUER_A_H; |
199 | STEUER_B_L; |
199 | STEUER_B_L; |
200 | SENSE_C; |
200 | SENSE_C; |
201 | SENSE_RISING_INT; |
201 | SENSE_RISING_INT; |
202 | break; |
202 | break; |
203 | case 1: |
203 | case 1: |
204 | STEUER_A_H; |
204 | STEUER_A_H; |
205 | STEUER_C_L; |
205 | STEUER_C_L; |
206 | SENSE_B; |
206 | SENSE_B; |
207 | SENSE_FALLING_INT; |
207 | SENSE_FALLING_INT; |
208 | break; |
208 | break; |
209 | case 2: |
209 | case 2: |
210 | STEUER_B_H; |
210 | STEUER_B_H; |
211 | STEUER_C_L; |
211 | STEUER_C_L; |
212 | SENSE_A; |
212 | SENSE_A; |
213 | SENSE_RISING_INT; |
213 | SENSE_RISING_INT; |
214 | break; |
214 | break; |
215 | case 3: |
215 | case 3: |
216 | STEUER_B_H; |
216 | STEUER_B_H; |
217 | STEUER_A_L; |
217 | STEUER_A_L; |
218 | SENSE_C; |
218 | SENSE_C; |
219 | SENSE_FALLING_INT; |
219 | SENSE_FALLING_INT; |
220 | break; |
220 | break; |
221 | case 4: |
221 | case 4: |
222 | STEUER_C_H; |
222 | STEUER_C_H; |
223 | STEUER_A_L; |
223 | STEUER_A_L; |
224 | SENSE_B; |
224 | SENSE_B; |
225 | SENSE_RISING_INT; |
225 | SENSE_RISING_INT; |
226 | break; |
226 | break; |
227 | case 5: |
227 | case 5: |
228 | STEUER_C_H; |
228 | STEUER_C_H; |
229 | STEUER_B_L; |
229 | STEUER_B_L; |
230 | SENSE_A; |
230 | SENSE_A; |
231 | SENSE_FALLING_INT; |
231 | SENSE_FALLING_INT; |
232 | break; |
232 | break; |
233 | } |
233 | } |
234 | } |
234 | } |
235 | 235 | ||
236 | 236 |