Rev 2093 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2093 | Rev 2174 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + www.MikroKopter.com |
2 | // + www.MikroKopter.com |
3 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // + Software Nutzungsbedingungen (english version: see below) |
4 | // + Software Nutzungsbedingungen (english version: see below) |
5 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
5 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
6 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
6 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
7 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
7 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
8 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
8 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
9 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
9 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
11 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
11 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
12 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
12 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
13 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
13 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
14 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
14 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
15 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
15 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
16 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
16 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
17 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
17 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
18 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
18 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
19 | // + des Mitverschuldens offen. |
19 | // + des Mitverschuldens offen. |
20 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
20 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
21 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
21 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
22 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
22 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
23 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
23 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
24 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
24 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
25 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
25 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
26 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
26 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
27 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
27 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // + Software LICENSING TERMS |
29 | // + Software LICENSING TERMS |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
31 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
32 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
32 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
33 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
33 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
34 | // + The Software may only be used with the Licensor's products. |
34 | // + The Software may only be used with the Licensor's products. |
35 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
35 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
36 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
36 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
37 | // + agreement shall be the property of the Licensor. |
37 | // + agreement shall be the property of the Licensor. |
38 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
38 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
39 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
39 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
40 | // + The customer shall be responsible for taking reasonable precautions |
40 | // + The customer shall be responsible for taking reasonable precautions |
41 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
41 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
42 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
42 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
43 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
43 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
44 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
44 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
45 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
45 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
46 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
46 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
47 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
47 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
48 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
48 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
49 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
49 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
50 | // + #### END OF LICENSING TERMS #### |
50 | // + #### END OF LICENSING TERMS #### |
51 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
51 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
52 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
53 | 53 | ||
54 | #include "main.h" |
54 | #include "main.h" |
55 | #define MULTIPLYER 4 |
55 | #define MULTIPLYER 4 |
56 | 56 | ||
57 | volatile unsigned int CountMilliseconds = 0; |
57 | volatile unsigned int CountMilliseconds = 0; |
58 | volatile static unsigned int tim_main; |
58 | volatile static unsigned int tim_main; |
59 | volatile unsigned char UpdateMotor = 0; |
59 | volatile unsigned char UpdateMotor = 0; |
60 | volatile unsigned int cntKompass = 0; |
60 | volatile unsigned int cntKompass = 0; |
61 | volatile unsigned int beeptime = 0; |
61 | volatile unsigned int beeptime = 0; |
62 | volatile unsigned char SendSPI = 0, ServoActive = 0, CalculateServoSignals = 1; |
62 | volatile unsigned char SendSPI = 0, ServoActive = 0, CalculateServoSignals = 1; |
63 | uint16_t RemainingPulse = 0; |
63 | uint16_t RemainingPulse = 255; // MartinR zur Sicherheit bei Interrupts |
64 | volatile int16_t ServoNickOffset = (255 / 2) * MULTIPLYER * 16; // initial value near center positon |
64 | volatile int16_t ServoNickOffset = (255 / 2) * MULTIPLYER * 16; // initial value near center positon |
65 | volatile int16_t ServoRollOffset = (255 / 2) * MULTIPLYER * 16; // initial value near center positon |
65 | volatile int16_t ServoRollOffset = (255 / 2) * MULTIPLYER * 16; // initial value near center positon |
66 | volatile int16_t ServoPanOffset = (255 / 2) * MULTIPLYER * 16; // MartinR: für Pan-Funktion |
66 | volatile int16_t ServoPanOffset = (255 / 2) * MULTIPLYER * 16; // MartinR: für Pan-Funktion |
67 | 67 | ||
68 | unsigned int BeepMuster = 0xffff; |
68 | unsigned int BeepMuster = 0xffff; |
69 | 69 | ||
70 | volatile int16_t ServoNickValue = 0; |
70 | volatile int16_t ServoNickValue = 0; |
71 | volatile int16_t ServoRollValue = 0; |
71 | volatile int16_t ServoRollValue = 0; |
72 | volatile int16_t ServoPanValue = 0; // MartinR : für PAN-Funktion |
72 | volatile int16_t ServoPanValue = 0; // MartinR : für PAN-Funktion |
73 | 73 | ||
74 | 74 | ||
75 | enum { |
75 | enum { |
76 | STOP = 0, |
76 | STOP = 0, |
77 | CK = 1, |
77 | CK = 1, |
78 | CK8 = 2, |
78 | CK8 = 2, |
79 | CK64 = 3, |
79 | CK64 = 3, |
80 | CK256 = 4, |
80 | CK256 = 4, |
81 | CK1024 = 5, |
81 | CK1024 = 5, |
82 | T0_FALLING_EDGE = 6, |
82 | T0_FALLING_EDGE = 6, |
83 | T0_RISING_EDGE = 7 |
83 | T0_RISING_EDGE = 7 |
84 | }; |
84 | }; |
85 | 85 | ||
86 | 86 | ||
87 | ISR(TIMER0_OVF_vect) // 9,7kHz |
87 | ISR(TIMER0_OVF_vect) // 9,7kHz |
88 | { |
88 | { |
89 | static unsigned char cnt_1ms = 1,cnt = 0, compass_active = 0; |
89 | static unsigned char cnt_1ms = 1,cnt = 0, compass_active = 0; |
90 | unsigned char pieper_ein = 0; |
90 | unsigned char pieper_ein = 0; |
91 | if(SendSPI) SendSPI--; |
91 | if(SendSPI) SendSPI--; |
92 | if(SpektrumTimer) SpektrumTimer--; |
92 | if(SpektrumTimer) SpektrumTimer--; |
93 | if(!cnt--) |
93 | if(!cnt--) |
94 | { |
94 | { |
95 | cnt = 9; |
95 | cnt = 9; |
96 | CountMilliseconds++; |
96 | CountMilliseconds++; |
97 | cnt_1ms++; |
97 | cnt_1ms++; |
98 | cnt_1ms %= 2; |
98 | cnt_1ms %= 2; |
99 | 99 | ||
100 | if(!cnt_1ms) UpdateMotor = 1; |
100 | if(!cnt_1ms) UpdateMotor = 1; |
101 | if(!(PINC & 0x10)) compass_active = 1; |
101 | if(!(PINC & 0x10)) compass_active = 1; |
102 | 102 | ||
103 | if(beeptime) |
103 | if(beeptime) |
104 | { |
104 | { |
105 | if(beeptime > 10) beeptime -= 10; else beeptime = 0; |
105 | if(beeptime > 10) beeptime -= 10; else beeptime = 0; |
106 | if(beeptime & BeepMuster) |
106 | if(beeptime & BeepMuster) |
107 | { |
107 | { |
108 | pieper_ein = 1; |
108 | pieper_ein = 1; |
109 | } |
109 | } |
110 | else pieper_ein = 0; |
110 | else pieper_ein = 0; |
111 | } |
111 | } |
112 | else |
112 | else |
113 | { |
113 | { |
114 | pieper_ein = 0; |
114 | pieper_ein = 0; |
115 | BeepMuster = 0xffff; |
115 | BeepMuster = 0xffff; |
116 | } |
116 | } |
117 | if(pieper_ein) |
117 | if(pieper_ein) |
118 | { |
118 | { |
119 | if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker an PORTD.2 |
119 | if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker an PORTD.2 |
120 | else PORTC |= (1<<7); // Speaker an PORTC.7 |
120 | else PORTC |= (1<<7); // Speaker an PORTC.7 |
121 | } |
121 | } |
122 | else |
122 | else |
123 | { |
123 | { |
124 | if(PlatinenVersion == 10) PORTD &= ~(1<<2); |
124 | if(PlatinenVersion == 10) PORTD &= ~(1<<2); |
125 | else PORTC &= ~(1<<7); |
125 | else PORTC &= ~(1<<7); |
126 | } |
126 | } |
127 | } |
127 | } |
128 | if(compass_active && !NaviDataOkay && Parameter_GlobalConfig & CFG_KOMPASS_AKTIV) |
128 | if(compass_active && !NaviDataOkay && Parameter_GlobalConfig & CFG_KOMPASS_AKTIV) |
129 | { |
129 | { |
130 | if(PINC & 0x10) |
130 | if(PINC & 0x10) |
131 | { |
131 | { |
132 | if(++cntKompass > 1000) compass_active = 0; |
132 | if(++cntKompass > 1000) compass_active = 0; |
133 | } |
133 | } |
134 | else |
134 | else |
135 | { |
135 | { |
136 | if((cntKompass) && (cntKompass < 362)) |
136 | if((cntKompass) && (cntKompass < 362)) |
137 | { |
137 | { |
138 | cntKompass += cntKompass / 41; |
138 | cntKompass += cntKompass / 41; |
139 | if(cntKompass > 10) KompassValue = cntKompass - 10; else KompassValue = 0; |
139 | if(cntKompass > 10) KompassValue = cntKompass - 10; else KompassValue = 0; |
140 | // KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
140 | // KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
141 | } |
141 | } |
142 | cntKompass = 0; |
142 | cntKompass = 0; |
143 | } |
143 | } |
144 | } |
144 | } |
145 | } |
145 | } |
146 | 146 | ||
147 | 147 | ||
148 | // ----------------------------------------------------------------------- |
148 | // ----------------------------------------------------------------------- |
149 | unsigned int SetDelay (unsigned int t) |
149 | unsigned int SetDelay (unsigned int t) |
150 | { |
150 | { |
151 | // TIMSK0 &= ~_BV(TOIE0); |
151 | // TIMSK0 &= ~_BV(TOIE0); |
152 | return(CountMilliseconds + t + 1); |
152 | return(CountMilliseconds + t + 1); |
153 | // TIMSK0 |= _BV(TOIE0); |
153 | // TIMSK0 |= _BV(TOIE0); |
154 | } |
154 | } |
155 | 155 | ||
156 | // ----------------------------------------------------------------------- |
156 | // ----------------------------------------------------------------------- |
157 | char CheckDelay(unsigned int t) |
157 | char CheckDelay(unsigned int t) |
158 | { |
158 | { |
159 | // TIMSK0 &= ~_BV(TOIE0); |
159 | // TIMSK0 &= ~_BV(TOIE0); |
160 | return(((t - CountMilliseconds) & 0x8000) >> 9); |
160 | return(((t - CountMilliseconds) & 0x8000) >> 9); |
161 | // TIMSK0 |= _BV(TOIE0); |
161 | // TIMSK0 |= _BV(TOIE0); |
162 | } |
162 | } |
163 | 163 | ||
164 | // ----------------------------------------------------------------------- |
164 | // ----------------------------------------------------------------------- |
165 | void Delay_ms(unsigned int w) |
165 | void Delay_ms(unsigned int w) |
166 | { |
166 | { |
167 | unsigned int akt; |
167 | unsigned int akt; |
168 | akt = SetDelay(w); |
168 | akt = SetDelay(w); |
169 | while (!CheckDelay(akt)); |
169 | while (!CheckDelay(akt)); |
170 | } |
170 | } |
171 | 171 | ||
172 | void Delay_ms_Mess(unsigned int w) |
172 | void Delay_ms_Mess(unsigned int w) |
173 | { |
173 | { |
174 | unsigned int akt; |
174 | unsigned int akt; |
175 | akt = SetDelay(w); |
175 | akt = SetDelay(w); |
176 | while (!CheckDelay(akt)) if(AdReady) {AdReady = 0; ANALOG_ON;} |
176 | while (!CheckDelay(akt)) if(AdReady) {AdReady = 0; ANALOG_ON;} |
177 | } |
177 | } |
178 | 178 | ||
179 | /*****************************************************/ |
179 | /*****************************************************/ |
180 | /* Initialize Timer 2 */ |
180 | /* Initialize Timer 2 */ |
181 | /*****************************************************/ |
181 | /*****************************************************/ |
182 | // The timer 2 is used to generate the PWM at PD7 (J7) |
182 | // The timer 2 is used to generate the PWM at PD7 (J7) |
183 | // to control a camera servo for nick compensation. |
183 | // to control a camera servo for nick compensation. |
184 | void TIMER2_Init(void) |
184 | void TIMER2_Init(void) |
185 | { |
185 | { |
186 | uint8_t sreg = SREG; |
186 | uint8_t sreg = SREG; |
187 | 187 | ||
188 | // disable all interrupts before reconfiguration |
188 | // disable all interrupts before reconfiguration |
189 | cli(); |
189 | cli(); |
190 | 190 | ||
191 | PORTD &= ~(1<<PORTD7); // set PD7 to low |
191 | PORTD &= ~(1<<PORTD7); // set PD7 to low |
192 | 192 | ||
193 | DDRC |= (1<<DDC6); // set PC6 as output (Reset for HEF4017) |
193 | DDRC |= (1<<DDC6); // set PC6 as output (Reset for HEF4017) |
194 | HEF4017R_ON; |
194 | HEF4017R_ON; |
195 | // Timer/Counter 2 Control Register A |
195 | // Timer/Counter 2 Control Register A |
196 | 196 | ||
197 | // Timer Mode is FastPWM with timer reload at OCR2A (Bits: WGM22 = 1, WGM21 = 1, WGM20 = 1) |
197 | // Timer Mode is FastPWM with timer reload at OCR2A (Bits: WGM22 = 1, WGM21 = 1, WGM20 = 1) |
198 | // PD7: Normal port operation, OC2A disconnected, (Bits: COM2A1 = 0, COM2A0 = 0) |
198 | // PD7: Normal port operation, OC2A disconnected, (Bits: COM2A1 = 0, COM2A0 = 0) |
199 | // PD6: Normal port operation, OC2B disconnected, (Bits: COM2B1 = 0, COM2B0 = 0) |
199 | // PD6: Normal port operation, OC2B disconnected, (Bits: COM2B1 = 0, COM2B0 = 0) |
200 | TCCR2A &= ~((1<<COM2A1)|(1<<COM2A0)|(1<<COM2B1)|(1<<COM2B0)); |
200 | TCCR2A &= ~((1<<COM2A1)|(1<<COM2A0)|(1<<COM2B1)|(1<<COM2B0)); |
201 | TCCR2A |= (1<<WGM21)|(1<<WGM20); |
201 | TCCR2A |= (1<<WGM21)|(1<<WGM20); |
202 | 202 | ||
203 | // Timer/Counter 2 Control Register B |
203 | // Timer/Counter 2 Control Register B |
204 | 204 | ||
205 | // Set clock divider for timer 2 to SYSKLOCK/32 = 20MHz / 32 = 625 kHz |
205 | // Set clock divider for timer 2 to SYSKLOCK/32 = 20MHz / 32 = 625 kHz |
206 | // The timer increments from 0x00 to 0xFF with an update rate of 625 kHz or 1.6 us |
206 | // The timer increments from 0x00 to 0xFF with an update rate of 625 kHz or 1.6 us |
207 | // hence the timer overflow interrupt frequency is 625 kHz / 256 = 2.44 kHz or 0.4096 ms |
207 | // hence the timer overflow interrupt frequency is 625 kHz / 256 = 2.44 kHz or 0.4096 ms |
208 | 208 | ||
209 | // divider 32 (Bits: CS022 = 0, CS21 = 1, CS20 = 1) |
209 | // divider 32 (Bits: CS022 = 0, CS21 = 1, CS20 = 1) |
210 | TCCR2B &= ~((1<<FOC2A)|(1<<FOC2B)|(1<<CS22)); |
210 | TCCR2B &= ~((1<<FOC2A)|(1<<FOC2B)|(1<<CS22)); |
211 | TCCR2B |= (1<<CS21)|(1<<CS20)|(1<<WGM22); |
211 | TCCR2B |= (1<<CS21)|(1<<CS20)|(1<<WGM22); |
212 | 212 | ||
213 | // Initialize the Timer/Counter 2 Register |
213 | // Initialize the Timer/Counter 2 Register |
214 | TCNT2 = 0; |
214 | TCNT2 = 0; |
215 | 215 | ||
216 | // Initialize the Output Compare Register A used for PWM generation on port PD7. |
216 | // Initialize the Output Compare Register A used for PWM generation on port PD7. |
217 | OCR2A = 255; |
217 | OCR2A = 255; |
218 | TCCR2A |= (1<<COM2A1); // set or clear at compare match depends on value of COM2A0 |
218 | TCCR2A |= (1<<COM2A1); // set or clear at compare match depends on value of COM2A0 |
219 | 219 | ||
220 | // Timer/Counter 2 Interrupt Mask Register |
220 | // Timer/Counter 2 Interrupt Mask Register |
221 | // Enable timer output compare match A Interrupt only |
221 | // Enable timer output compare match A Interrupt only |
222 | TIMSK2 &= ~((1<<OCIE2B)|(1<<TOIE2)); |
222 | TIMSK2 &= ~((1<<OCIE2B)|(1<<TOIE2)); |
223 | TIMSK2 |= (1<<OCIE2A); |
223 | TIMSK2 |= (1<<OCIE2A); |
224 | 224 | ||
225 | SREG = sreg; |
225 | SREG = sreg; |
226 | } |
226 | } |
227 | 227 | ||
228 | //---------------------------- |
228 | //---------------------------- |
229 | void Timer_Init(void) |
229 | void Timer_Init(void) |
230 | { |
230 | { |
231 | tim_main = SetDelay(10); |
231 | tim_main = SetDelay(10); |
232 | TCCR0B = CK8; |
232 | TCCR0B = CK8; |
233 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
233 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
234 | OCR0A = 0; |
234 | OCR0A = 0; |
235 | OCR0B = 180; |
235 | OCR0B = 180; |
236 | TCNT0 = (unsigned char)-TIMER_RELOAD_VALUE; // reload |
236 | TCNT0 = (unsigned char)-TIMER_RELOAD_VALUE; // reload |
237 | //OCR1 = 0x00; |
237 | //OCR1 = 0x00; |
238 | TIMSK0 |= _BV(TOIE0); |
238 | TIMSK0 |= _BV(TOIE0); |
239 | } |
239 | } |
240 | 240 | ||
241 | 241 | ||
242 | /*****************************************************/ |
242 | /*****************************************************/ |
243 | /* Control Servo Position */ |
243 | /* Control Servo Position */ |
244 | /*****************************************************/ |
244 | /*****************************************************/ |
245 | 245 | ||
246 | 246 | ||
247 | void CalculateServo(void) |
247 | void CalculateServo(void) |
248 | { |
248 | { |
249 | //signed char cosinus, sinus; // MartinR : so war es |
249 | //signed char cosinus, sinus; // MartinR : so war es |
250 | extern signed char cosinus, sinus; // MartinR : extern für PAN-Funktion |
250 | extern signed char cosinus, sinus; // MartinR : extern für PAN-Funktion |
251 | signed long nick, roll; |
251 | signed long nick, roll; |
252 | 252 | ||
253 | nick = 0; // MartinR : StartWert bei abgeschalteten Nick/ Roll ausgleich |
253 | nick = 0; // MartinR : StartWert bei abgeschalteten Nick/ Roll ausgleich |
254 | roll = 0; // MartinR : StartWert bei abgeschalteten Nick/ Roll ausgleich |
254 | roll = 0; // MartinR : StartWert bei abgeschalteten Nick/ Roll ausgleich |
255 | int tmp; // MartinR : für PAN-Funktion // Wert : 0-24 -> 0-360 -> 15° steps |
255 | int tmp; // MartinR : für PAN-Funktion // Wert : 0-24 -> 0-360 -> 15° steps |
256 | /* // MartinR: bisher |
256 | /* // MartinR: bisher |
257 | tmp = EE_Parameter.CamOrientation + ((Parameter_Servo4 - 125) * (Parameter_UserParam8 - 125)) / 400 ; //MartinR : für PAN-Funktion |
257 | tmp = EE_Parameter.CamOrientation + ((Parameter_Servo4 - 125) * (Parameter_UserParam8 - 125)) / 400 ; //MartinR : für PAN-Funktion |
258 | if (tmp < 0) tmp = 24- (abs(tmp)) % 24 ; // MartinR :Modulo 24 |
258 | if (tmp < 0) tmp = 24- (abs(tmp)) % 24 ; // MartinR :Modulo 24 |
259 | else tmp = tmp % 24 ; // MartinR :Modulo 24 |
259 | else tmp = tmp % 24 ; // MartinR :Modulo 24 |
260 | */ |
260 | */ |
261 | tmp = EE_Parameter.CamOrientation + ((Parameter_Servo4 - 125) * (Parameter_UserParam8 - 125)) / 200 ; //MartinR : für PAN-Funktion |
261 | tmp = EE_Parameter.CamOrientation + ((Parameter_Servo4 - 125) * (Parameter_UserParam8 - 125)) / 200 ; //MartinR : für PAN-Funktion |
262 | if (tmp < 0) tmp = 48- (abs(tmp)) % 48 ; // MartinR :Modulo 48 |
262 | if (tmp < 0) tmp = 48- (abs(tmp)) % 48 ; // MartinR :Modulo 48 |
263 | else tmp = tmp % 48 ; // MartinR :Modulo 48 |
263 | else tmp = tmp % 48 ; // MartinR :Modulo 48 |
264 | 264 | ||
265 | // cosinus = sintab[EE_Parameter.CamOrientation + 6]; // MartinR : so war es |
265 | // cosinus = sintab[EE_Parameter.CamOrientation + 6]; // MartinR : so war es |
266 | // sinus = sintab[EE_Parameter.CamOrientation]; // MartinR : so war es |
266 | // sinus = sintab[EE_Parameter.CamOrientation]; // MartinR : so war es |
267 | //cosinus = sintab[tmp + 6]; // MartinR : für PAN-Funktion |
267 | //cosinus = sintab[tmp + 6]; // MartinR : für PAN-Funktion |
268 | cosinus += (2*sintab[tmp + 12]- cosinus + 1) / 2; // MartinR : für PAN-Funktion |
268 | cosinus += (2*sintab[tmp + 12]- cosinus + 1) / 2; // MartinR : für PAN-Funktion |
269 | sinus += (2*sintab[tmp] - sinus + 1) / 2; // MartinR : für PAN-Funktion |
269 | sinus += (2*sintab[tmp] - sinus + 1) / 2; // MartinR : für PAN-Funktion |
270 | 270 | ||
271 | if(CalculateServoSignals == 1) |
271 | if(CalculateServoSignals == 1) |
272 | { |
272 | { |
273 | if (Parameter_UserParam7 < 50) // MartinR: um per UserParameter den Nickausgleich abzuschalten |
273 | if (Parameter_UserParam7 < 50) // MartinR: um per UserParameter den Nickausgleich abzuschalten |
274 | { |
274 | { |
275 | //nick = (cosinus * IntegralNick) / 128L - (sinus * IntegralRoll) / 128L; // MartinR: so war es |
275 | //nick = (cosinus * IntegralNick) / 128L - (sinus * IntegralRoll) / 128L; // MartinR: so war es |
276 | nick = (cosinus * IntegralNick) / 512L - (sinus * IntegralRoll) / 512L; // MartinR: bessere Auflösung |
276 | nick = (cosinus * IntegralNick) / 512L - (sinus * IntegralRoll) / 512L; // MartinR: bessere Auflösung |
277 | nick -= POI_KameraNick * 7; |
277 | nick -= POI_KameraNick * 7; |
278 | } |
278 | } |
279 | nick = ((long)EE_Parameter.ServoNickComp * nick) / 512L; |
279 | nick = ((long)EE_Parameter.ServoNickComp * nick) / 512L; |
280 | // offset (Range from 0 to 255 * 3 = 765) |
280 | // offset (Range from 0 to 255 * 3 = 765) |
281 | ServoNickOffset += ((int16_t)Parameter_ServoNickControl * (MULTIPLYER*16) - ServoNickOffset) / EE_Parameter.ServoManualControlSpeed; |
281 | ServoNickOffset += ((int16_t)Parameter_ServoNickControl * (MULTIPLYER*16) - ServoNickOffset) / EE_Parameter.ServoManualControlSpeed; |
282 | if(EE_Parameter.ServoCompInvert & 0x01) // inverting movement of servo |
282 | if(EE_Parameter.ServoCompInvert & 0x01) // inverting movement of servo |
283 | { |
283 | { |
284 | nick = ServoNickOffset / 16 + nick; |
284 | nick = ServoNickOffset / 16 + nick; |
285 | } |
285 | } |
286 | else |
286 | else |
287 | { // inverting movement of servo |
287 | { // inverting movement of servo |
288 | nick = ServoNickOffset / 16 - nick; |
288 | nick = ServoNickOffset / 16 - nick; |
289 | } |
289 | } |
290 | if(EE_Parameter.ServoFilterNick) ServoNickValue = ((ServoNickValue * EE_Parameter.ServoFilterNick) + nick) / (EE_Parameter.ServoFilterNick + 1); |
290 | if(EE_Parameter.ServoFilterNick) ServoNickValue = ((ServoNickValue * EE_Parameter.ServoFilterNick) + nick) / (EE_Parameter.ServoFilterNick + 1); |
291 | else ServoNickValue = nick; |
291 | else ServoNickValue = nick; |
292 | // limit servo value to its parameter range definition |
292 | // limit servo value to its parameter range definition |
293 | if(ServoNickValue < ((int16_t)EE_Parameter.ServoNickMin * MULTIPLYER)) |
293 | if(ServoNickValue < ((int16_t)EE_Parameter.ServoNickMin * MULTIPLYER)) |
294 | { |
294 | { |
295 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMin * MULTIPLYER; |
295 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMin * MULTIPLYER; |
296 | } |
296 | } |
297 | else |
297 | else |
298 | if(ServoNickValue > ((int16_t)EE_Parameter.ServoNickMax * MULTIPLYER)) |
298 | if(ServoNickValue > ((int16_t)EE_Parameter.ServoNickMax * MULTIPLYER)) |
299 | { |
299 | { |
300 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMax * MULTIPLYER; |
300 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMax * MULTIPLYER; |
301 | } |
301 | } |
302 | if(PlatinenVersion < 20) CalculateServoSignals = 0; else CalculateServoSignals++; |
302 | if(PlatinenVersion < 20) CalculateServoSignals = 0; else CalculateServoSignals++; |
303 | } |
303 | } |
304 | else |
304 | else |
305 | { |
305 | { |
306 | if (Parameter_UserParam7 < 100) // MartinR: um per UserParameter den Nickausgleich abzuschalten |
306 | if (Parameter_UserParam7 < 100) // MartinR: um per UserParameter den Nickausgleich abzuschalten |
307 | { |
307 | { |
308 | //roll = (cosinus * IntegralRoll) / 128L + (sinus * IntegralNick) / 128L; // MartinR: so war es |
308 | //roll = (cosinus * IntegralRoll) / 128L + (sinus * IntegralNick) / 128L; // MartinR: so war es |
309 | roll = (cosinus * IntegralRoll) / 512L + (sinus * IntegralNick) / 512L; // MartinR: bessere Auflösung |
309 | roll = (cosinus * IntegralRoll) / 512L + (sinus * IntegralNick) / 512L; // MartinR: bessere Auflösung |
310 | } |
310 | } |
311 | roll = ((long)EE_Parameter.ServoRollComp * roll) / 512L; |
311 | roll = ((long)EE_Parameter.ServoRollComp * roll) / 512L; |
312 | ServoRollOffset += ((int16_t)Parameter_ServoRollControl * (MULTIPLYER*16) - ServoRollOffset) / EE_Parameter.ServoManualControlSpeed; |
312 | ServoRollOffset += ((int16_t)Parameter_ServoRollControl * (MULTIPLYER*16) - ServoRollOffset) / EE_Parameter.ServoManualControlSpeed; |
313 | if(EE_Parameter.ServoCompInvert & 0x02) |
313 | if(EE_Parameter.ServoCompInvert & 0x02) |
314 | { // inverting movement of servo |
314 | { // inverting movement of servo |
315 | roll = ServoRollOffset / 16 + roll; |
315 | roll = ServoRollOffset / 16 + roll; |
316 | } |
316 | } |
317 | else |
317 | else |
318 | { // inverting movement of servo |
318 | { // inverting movement of servo |
319 | roll = ServoRollOffset / 16 - roll; |
319 | roll = ServoRollOffset / 16 - roll; |
320 | } |
320 | } |
321 | if(EE_Parameter.ServoFilterRoll) ServoRollValue = ((ServoRollValue * EE_Parameter.ServoFilterRoll) + roll) / (EE_Parameter.ServoFilterRoll + 1); |
321 | if(EE_Parameter.ServoFilterRoll) ServoRollValue = ((ServoRollValue * EE_Parameter.ServoFilterRoll) + roll) / (EE_Parameter.ServoFilterRoll + 1); |
322 | else ServoRollValue = roll; |
322 | else ServoRollValue = roll; |
323 | // limit servo value to its parameter range definition |
323 | // limit servo value to its parameter range definition |
324 | if(ServoRollValue < ((int16_t)EE_Parameter.ServoRollMin * MULTIPLYER)) |
324 | if(ServoRollValue < ((int16_t)EE_Parameter.ServoRollMin * MULTIPLYER)) |
325 | { |
325 | { |
326 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMin * MULTIPLYER; |
326 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMin * MULTIPLYER; |
327 | } |
327 | } |
328 | else |
328 | else |
329 | if(ServoRollValue > ((int16_t)EE_Parameter.ServoRollMax * MULTIPLYER)) |
329 | if(ServoRollValue > ((int16_t)EE_Parameter.ServoRollMax * MULTIPLYER)) |
330 | { |
330 | { |
331 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMax * MULTIPLYER; |
331 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMax * MULTIPLYER; |
332 | } |
332 | } |
333 | 333 | ||
334 | // MartinR: Filterung der Pan- Funktion |
334 | // MartinR: Filterung der Pan- Funktion |
335 | ServoPanOffset += ((int16_t)Parameter_Servo4 * (MULTIPLYER*16) - ServoPanOffset) / EE_Parameter.ServoManualControlSpeed; |
335 | ServoPanOffset += ((int16_t)Parameter_Servo4 * (MULTIPLYER*16) - ServoPanOffset) / EE_Parameter.ServoManualControlSpeed; |
336 | ServoPanValue = (int16_t)ServoPanOffset/16; // offset (Range from 0 to 255 * 3 = 765) |
336 | ServoPanValue = (int16_t)ServoPanOffset/16; // offset (Range from 0 to 255 * 3 = 765) |
337 | 337 | ||
338 | CalculateServoSignals = 0; |
338 | CalculateServoSignals = 0; |
339 | } |
339 | } |
340 | } |
340 | } |
341 | 341 | ||
342 | ISR(TIMER2_COMPA_vect) |
342 | ISR(TIMER2_COMPA_vect) |
343 | { |
343 | { |
344 | // frame len 22.5 ms = 14063 * 1.6 us |
344 | // frame len 22.5 ms = 14063 * 1.6 us |
345 | // stop pulse: 0.3 ms = 188 * 1.6 us |
345 | // stop pulse: 0.3 ms = 188 * 1.6 us |
346 | // min servo pulse: 0.6 ms = 375 * 1.6 us |
346 | // min servo pulse: 0.6 ms = 375 * 1.6 us |
347 | // max servo pulse: 2.4 ms = 1500 * 1.6 us |
347 | // max servo pulse: 2.4 ms = 1500 * 1.6 us |
348 | // resolution: 1500 - 375 = 1125 steps |
348 | // resolution: 1500 - 375 = 1125 steps |
349 | 349 | ||
350 | #define IRS_RUNTIME 127 |
350 | #define IRS_RUNTIME 127 |
351 | #define PPM_STOPPULSE 188 |
351 | #define PPM_STOPPULSE 188 |
352 | #define PPM_FRAMELEN (1757 * EE_Parameter.ServoNickRefresh) |
352 | #define PPM_FRAMELEN (1757 * EE_Parameter.ServoNickRefresh) |
353 | #define MINSERVOPULSE 375 |
353 | #define MINSERVOPULSE 375 |
354 | #define MAXSERVOPULSE 1500 |
354 | #define MAXSERVOPULSE 1500 |
355 | #define SERVORANGE (MAXSERVOPULSE - MINSERVOPULSE) |
355 | #define SERVORANGE (MAXSERVOPULSE - MINSERVOPULSE) |
356 | 356 | ||
357 | static uint8_t PulseOutput = 0; |
357 | static uint8_t PulseOutput = 0; |
358 | static uint16_t ServoFrameTime = 0; |
358 | static uint16_t ServoFrameTime = 0; |
359 | static uint8_t ServoIndex = 0; |
359 | static uint8_t ServoIndex = 0; |
360 | 360 | ||
361 | 361 | ||
362 | if(PlatinenVersion < 20) |
362 | if(PlatinenVersion < 20) |
363 | { |
363 | { |
364 | /* // MartinR : deaktiviert wegen Platzbedarf |
- | |
365 | //--------------------------- |
364 | //--------------------------- |
366 | // Nick servo state machine |
365 | // Nick servo state machine |
367 | //--------------------------- |
366 | //--------------------------- |
368 | if(!PulseOutput) // pulse output complete |
367 | if(!PulseOutput) // pulse output complete |
369 | { |
368 | { |
370 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
369 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
371 | { |
370 | { |
372 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
371 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
373 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
372 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
374 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
373 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
375 | // range servo pulse width |
374 | // range servo pulse width |
376 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
375 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
377 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
376 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
378 | // accumulate time for correct update rate |
377 | // accumulate time for correct update rate |
379 | ServoFrameTime = RemainingPulse; |
378 | ServoFrameTime = RemainingPulse; |
380 | } |
379 | } |
381 | else // we had a high pulse |
380 | else // we had a high pulse |
382 | { |
381 | { |
383 | TCCR2A |= (1<<COM2A0); // make a low pulse |
382 | TCCR2A |= (1<<COM2A0); // make a low pulse |
384 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; |
383 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; |
385 | CalculateServoSignals = 1; |
384 | CalculateServoSignals = 1; |
386 | } |
385 | } |
387 | // set pulse output active |
386 | // set pulse output active |
388 | PulseOutput = 1; |
387 | PulseOutput = 1; |
389 | } |
388 | } |
390 | */ |
- | |
391 | } // EOF Nick servo state machine |
389 | } // EOF Nick servo state machine |
392 | else |
390 | else |
393 | { |
391 | { |
394 | //----------------------------------------------------- |
392 | //----------------------------------------------------- |
395 | // PPM state machine, onboard demultiplexed by HEF4017 |
393 | // PPM state machine, onboard demultiplexed by HEF4017 |
396 | //----------------------------------------------------- |
394 | //----------------------------------------------------- |
397 | if(!PulseOutput) // pulse output complete |
395 | if(!PulseOutput) // pulse output complete |
398 | { |
396 | { |
399 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
397 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
400 | { |
398 | { |
401 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
399 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
402 | 400 | ||
403 | if(ServoIndex == 0) // if we are at the sync gap |
401 | if(ServoIndex == 0) // if we are at the sync gap |
404 | { |
402 | { |
405 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; // generate sync gap by filling time to full frame time |
403 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; // generate sync gap by filling time to full frame time |
406 | ServoFrameTime = 0; // reset servo frame time |
404 | ServoFrameTime = 0; // reset servo frame time |
407 | HEF4017R_ON; // enable HEF4017 reset |
405 | HEF4017R_ON; // enable HEF4017 reset |
408 | } |
406 | } |
409 | else // servo channels |
407 | else // servo channels |
410 | { |
408 | { |
411 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
409 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
412 | switch(ServoIndex) // map servo channels |
410 | switch(ServoIndex) // map servo channels |
413 | { |
411 | { |
414 | case 1: // Nick Compensation Servo |
412 | case 1: // Nick Compensation Servo |
415 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
413 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
416 | break; |
414 | break; |
417 | case 2: // Roll Compensation Servo |
415 | case 2: // Roll Compensation Servo |
418 | RemainingPulse += ServoRollValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
416 | RemainingPulse += ServoRollValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
419 | break; |
417 | break; |
420 | case 3: |
418 | case 3: |
421 | RemainingPulse += ((int16_t)Parameter_Servo3 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
419 | RemainingPulse += ((int16_t)Parameter_Servo3 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
422 | break; |
420 | break; |
423 | case 4: |
421 | case 4: |
424 | //RemainingPulse += ((int16_t)Parameter_Servo4 * MULTIPLYER) - (256 / 2) * MULTIPLYER; // MartinR: so war es |
422 | //RemainingPulse += ((int16_t)Parameter_Servo4 * MULTIPLYER) - (256 / 2) * MULTIPLYER; // MartinR: so war es |
425 | RemainingPulse += ServoPanValue - (256 / 2) * MULTIPLYER; // MartinR: zur Filterung der Pan-Funktion |
423 | RemainingPulse += ServoPanValue - (256 / 2) * MULTIPLYER; // MartinR: zur Filterung der Pan-Funktion |
426 | break; |
424 | break; |
427 | case 5: |
425 | case 5: |
428 | RemainingPulse += ((int16_t)Parameter_Servo5 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
426 | RemainingPulse += ((int16_t)Parameter_Servo5 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
429 | break; |
427 | break; |
430 | default: // other servo channels |
428 | default: // other servo channels |
431 | RemainingPulse += 2 * PPM_in[ServoIndex]; // add channel value, factor of 2 because timer 1 increments 3.2µs |
429 | RemainingPulse += 2 * PPM_in[ServoIndex]; // add channel value, factor of 2 because timer 1 increments 3.2µs |
432 | break; |
430 | break; |
433 | } |
431 | } |
434 | // range servo pulse width |
432 | // range servo pulse width |
435 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
433 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
436 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
434 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
437 | // substract stop pulse width |
435 | // substract stop pulse width |
438 | RemainingPulse -= PPM_STOPPULSE; |
436 | RemainingPulse -= PPM_STOPPULSE; |
439 | // accumulate time for correct sync gap |
437 | // accumulate time for correct sync gap |
440 | ServoFrameTime += RemainingPulse; |
438 | ServoFrameTime += RemainingPulse; |
441 | } |
439 | } |
442 | } |
440 | } |
443 | else // we had a high pulse |
441 | else // we had a high pulse |
444 | { |
442 | { |
445 | TCCR2A |= (1<<COM2A0); // make a low pulse |
443 | TCCR2A |= (1<<COM2A0); // make a low pulse |
446 | // set pulsewidth to stop pulse width |
444 | // set pulsewidth to stop pulse width |
447 | RemainingPulse = PPM_STOPPULSE; |
445 | RemainingPulse = PPM_STOPPULSE; |
448 | // accumulate time for correct sync gap |
446 | // accumulate time for correct sync gap |
449 | ServoFrameTime += RemainingPulse; |
447 | ServoFrameTime += RemainingPulse; |
450 | if((ServoActive && SenderOkay) || ServoActive == 2) HEF4017R_OFF; // disable HEF4017 reset |
448 | if((ServoActive && SenderOkay) || ServoActive == 2) HEF4017R_OFF; // disable HEF4017 reset |
451 | else HEF4017R_ON; |
449 | else HEF4017R_ON; |
452 | ServoIndex++; // change to next servo channel |
450 | ServoIndex++; // change to next servo channel |
453 | if(ServoIndex > EE_Parameter.ServoNickRefresh) |
451 | if(ServoIndex > EE_Parameter.ServoNickRefresh) |
454 | { |
452 | { |
455 | CalculateServoSignals = 1; |
453 | CalculateServoSignals = 1; |
456 | ServoIndex = 0; // reset to the sync gap |
454 | ServoIndex = 0; // reset to the sync gap |
457 | } |
455 | } |
458 | } |
456 | } |
459 | // set pulse output active |
457 | // set pulse output active |
460 | PulseOutput = 1; |
458 | PulseOutput = 1; |
461 | } |
459 | } |
462 | } // EOF PPM state machine |
460 | } // EOF PPM state machine |
463 | 461 | ||
464 | // General pulse output generator |
462 | // General pulse output generator |
465 | if(RemainingPulse > (255 + IRS_RUNTIME)) |
463 | if(RemainingPulse > (255 + IRS_RUNTIME)) |
466 | { |
464 | { |
467 | OCR2A = 255; |
465 | OCR2A = 255; |
468 | RemainingPulse -= 255; |
466 | RemainingPulse -= 255; |
469 | } |
467 | } |
470 | else |
468 | else |
471 | { |
469 | { |
472 | if(RemainingPulse > 255) // this is the 2nd last part |
470 | if(RemainingPulse > 255) // this is the 2nd last part |
473 | { |
471 | { |
474 | if((RemainingPulse - 255) < IRS_RUNTIME) |
472 | if((RemainingPulse - 255) < IRS_RUNTIME) |
475 | { |
473 | { |
476 | OCR2A = 255 - IRS_RUNTIME; |
474 | OCR2A = 255 - IRS_RUNTIME; |
477 | RemainingPulse -= 255 - IRS_RUNTIME; |
475 | RemainingPulse -= 255 - IRS_RUNTIME; |
478 | 476 | ||
479 | } |
477 | } |
480 | else // last part > ISR_RUNTIME |
478 | else // last part > ISR_RUNTIME |
481 | { |
479 | { |
482 | OCR2A = 255; |
480 | OCR2A = 255; |
483 | RemainingPulse -= 255; |
481 | RemainingPulse -= 255; |
484 | } |
482 | } |
485 | } |
483 | } |
486 | else // this is the last part |
484 | else // this is the last part |
487 | { |
485 | { |
488 | OCR2A = RemainingPulse; |
486 | OCR2A = RemainingPulse; |
489 | RemainingPulse = 0; |
487 | RemainingPulse = 0; |
490 | PulseOutput = 0; // trigger to stop pulse |
488 | PulseOutput = 0; // trigger to stop pulse |
491 | } |
489 | } |
492 | } // EOF general pulse output generator |
490 | } // EOF general pulse output generator |
493 | } |
491 | } |
494 | 492 |