Rev 2166 | Rev 2192 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2166 | Rev 2191 | ||
---|---|---|---|
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 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 = 0; |
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 | 66 | ||
67 | unsigned int BeepMuster = 0xffff; |
67 | unsigned int BeepMuster = 0xffff; |
- | 68 | signed int NickServoValue = 128 * MULTIPLYER * 16; |
|
68 | 69 | ||
69 | volatile int16_t ServoNickValue = 0; |
70 | volatile int16_t ServoNickValue = 0; |
70 | volatile int16_t ServoRollValue = 0; |
71 | volatile int16_t ServoRollValue = 0; |
- | 72 | ||
- | 73 | // bitcoding for EE_Parameter.ServoCompInvert |
|
- | 74 | #define SERVO_NICK_INV 0x01 |
|
- | 75 | #define SERVO_ROLL_INV 0x02 |
|
71 | 76 | #define SERVO_RELATIVE 0x04 // direct poti control or relative moving of the servo value |
|
72 | 77 | ||
73 | enum { |
78 | enum { |
74 | STOP = 0, |
79 | STOP = 0, |
75 | CK = 1, |
80 | CK = 1, |
76 | CK8 = 2, |
81 | CK8 = 2, |
77 | CK64 = 3, |
82 | CK64 = 3, |
78 | CK256 = 4, |
83 | CK256 = 4, |
79 | CK1024 = 5, |
84 | CK1024 = 5, |
80 | T0_FALLING_EDGE = 6, |
85 | T0_FALLING_EDGE = 6, |
81 | T0_RISING_EDGE = 7 |
86 | T0_RISING_EDGE = 7 |
82 | }; |
87 | }; |
83 | 88 | ||
84 | 89 | ||
85 | ISR(TIMER0_OVF_vect) // 9,7kHz |
90 | ISR(TIMER0_OVF_vect) // 9,7kHz |
86 | { |
91 | { |
87 | static unsigned char cnt_1ms = 1,cnt = 0, compass_active = 0; |
92 | static unsigned char cnt_1ms = 1,cnt = 0, compass_active = 0; |
88 | unsigned char pieper_ein = 0; |
93 | unsigned char pieper_ein = 0; |
89 | if(SendSPI) SendSPI--; |
94 | if(SendSPI) SendSPI--; |
90 | if(SpektrumTimer) SpektrumTimer--; |
95 | if(SpektrumTimer) SpektrumTimer--; |
91 | if(!cnt--) |
96 | if(!cnt--) |
92 | { |
97 | { |
93 | cnt = 9; |
98 | cnt = 9; |
94 | CountMilliseconds++; |
99 | CountMilliseconds++; |
95 | cnt_1ms++; |
100 | cnt_1ms++; |
96 | cnt_1ms %= 2; |
101 | cnt_1ms %= 2; |
97 | 102 | ||
98 | if(!cnt_1ms) UpdateMotor = 1; |
103 | if(!cnt_1ms) UpdateMotor = 1; |
99 | if(!(PINC & 0x10)) compass_active = 1; |
104 | if(!(PINC & 0x10)) compass_active = 1; |
100 | 105 | ||
101 | if(beeptime) |
106 | if(beeptime) |
102 | { |
107 | { |
103 | if(beeptime > 10) beeptime -= 10; else beeptime = 0; |
108 | if(beeptime > 10) beeptime -= 10; else beeptime = 0; |
104 | if(beeptime & BeepMuster) |
109 | if(beeptime & BeepMuster) |
105 | { |
110 | { |
106 | pieper_ein = 1; |
111 | pieper_ein = 1; |
107 | } |
112 | } |
108 | else pieper_ein = 0; |
113 | else pieper_ein = 0; |
109 | } |
114 | } |
110 | else |
115 | else |
111 | { |
116 | { |
112 | pieper_ein = 0; |
117 | pieper_ein = 0; |
113 | BeepMuster = 0xffff; |
118 | BeepMuster = 0xffff; |
114 | } |
119 | } |
115 | if(pieper_ein) |
120 | if(pieper_ein) |
116 | { |
121 | { |
117 | if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker an PORTD.2 |
122 | if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker an PORTD.2 |
118 | else PORTC |= (1<<7); // Speaker an PORTC.7 |
123 | else PORTC |= (1<<7); // Speaker an PORTC.7 |
119 | } |
124 | } |
120 | else |
125 | else |
121 | { |
126 | { |
122 | if(PlatinenVersion == 10) PORTD &= ~(1<<2); |
127 | if(PlatinenVersion == 10) PORTD &= ~(1<<2); |
123 | else PORTC &= ~(1<<7); |
128 | else PORTC &= ~(1<<7); |
124 | } |
129 | } |
125 | } |
130 | } |
126 | if(compass_active && !NaviDataOkay && Parameter_GlobalConfig & CFG_KOMPASS_AKTIV) |
131 | if(compass_active && !NaviDataOkay && Parameter_GlobalConfig & CFG_KOMPASS_AKTIV) |
127 | { |
132 | { |
128 | if(PINC & 0x10) |
133 | if(PINC & 0x10) |
129 | { |
134 | { |
130 | if(++cntKompass > 1000) compass_active = 0; |
135 | if(++cntKompass > 1000) compass_active = 0; |
131 | } |
136 | } |
132 | else |
137 | else |
133 | { |
138 | { |
134 | if((cntKompass) && (cntKompass < 362)) |
139 | if((cntKompass) && (cntKompass < 362)) |
135 | { |
140 | { |
136 | cntKompass += cntKompass / 41; |
141 | cntKompass += cntKompass / 41; |
137 | if(cntKompass > 10) KompassValue = cntKompass - 10; else KompassValue = 0; |
142 | if(cntKompass > 10) KompassValue = cntKompass - 10; else KompassValue = 0; |
138 | // KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
143 | // KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
139 | } |
144 | } |
140 | cntKompass = 0; |
145 | cntKompass = 0; |
141 | } |
146 | } |
142 | } |
147 | } |
143 | } |
148 | } |
144 | 149 | ||
145 | 150 | ||
146 | // ----------------------------------------------------------------------- |
151 | // ----------------------------------------------------------------------- |
147 | unsigned int SetDelay(unsigned int t) |
152 | unsigned int SetDelay(unsigned int t) |
148 | { |
153 | { |
149 | // TIMSK0 &= ~_BV(TOIE0); |
154 | // TIMSK0 &= ~_BV(TOIE0); |
150 | return(CountMilliseconds + t + 1); |
155 | return(CountMilliseconds + t + 1); |
151 | // TIMSK0 |= _BV(TOIE0); |
156 | // TIMSK0 |= _BV(TOIE0); |
152 | } |
157 | } |
153 | 158 | ||
154 | // ----------------------------------------------------------------------- |
159 | // ----------------------------------------------------------------------- |
155 | char CheckDelay(unsigned int t) |
160 | char CheckDelay(unsigned int t) |
156 | { |
161 | { |
157 | // TIMSK0 &= ~_BV(TOIE0); |
162 | // TIMSK0 &= ~_BV(TOIE0); |
158 | return(((t - CountMilliseconds) & 0x8000) >> 9); |
163 | return(((t - CountMilliseconds) & 0x8000) >> 9); |
159 | // TIMSK0 |= _BV(TOIE0); |
164 | // TIMSK0 |= _BV(TOIE0); |
160 | } |
165 | } |
161 | 166 | ||
162 | // ----------------------------------------------------------------------- |
167 | // ----------------------------------------------------------------------- |
163 | void Delay_ms(unsigned int w) |
168 | void Delay_ms(unsigned int w) |
164 | { |
169 | { |
165 | unsigned int akt; |
170 | unsigned int akt; |
166 | akt = SetDelay(w); |
171 | akt = SetDelay(w); |
167 | while (!CheckDelay(akt)); |
172 | while (!CheckDelay(akt)); |
168 | } |
173 | } |
169 | 174 | ||
170 | void Delay_ms_Mess(unsigned int w) |
175 | void Delay_ms_Mess(unsigned int w) |
171 | { |
176 | { |
172 | unsigned int akt; |
177 | unsigned int akt; |
173 | akt = SetDelay(w); |
178 | akt = SetDelay(w); |
174 | while (!CheckDelay(akt)) if(AdReady) {AdReady = 0; ANALOG_ON;} |
179 | while (!CheckDelay(akt)) if(AdReady) {AdReady = 0; ANALOG_ON;} |
175 | } |
180 | } |
176 | 181 | ||
177 | /*****************************************************/ |
182 | /*****************************************************/ |
178 | /* Initialize Timer 2 */ |
183 | /* Initialize Timer 2 */ |
179 | /*****************************************************/ |
184 | /*****************************************************/ |
180 | // The timer 2 is used to generate the PWM at PD7 (J7) |
185 | // The timer 2 is used to generate the PWM at PD7 (J7) |
181 | // to control a camera servo for nick compensation. |
186 | // to control a camera servo for nick compensation. |
182 | void TIMER2_Init(void) |
187 | void TIMER2_Init(void) |
183 | { |
188 | { |
184 | uint8_t sreg = SREG; |
189 | uint8_t sreg = SREG; |
185 | 190 | ||
186 | // disable all interrupts before reconfiguration |
191 | // disable all interrupts before reconfiguration |
187 | cli(); |
192 | cli(); |
188 | 193 | ||
189 | PORTD &= ~(1<<PORTD7); // set PD7 to low |
194 | PORTD &= ~(1<<PORTD7); // set PD7 to low |
190 | 195 | ||
191 | DDRC |= (1<<DDC6); // set PC6 as output (Reset for HEF4017) |
196 | DDRC |= (1<<DDC6); // set PC6 as output (Reset for HEF4017) |
192 | HEF4017Reset_ON; |
197 | HEF4017Reset_ON; |
193 | // Timer/Counter 2 Control Register A |
198 | // Timer/Counter 2 Control Register A |
194 | 199 | ||
195 | // Timer Mode is FastPWM with timer reload at OCR2A (Bits: WGM22 = 1, WGM21 = 1, WGM20 = 1) |
200 | // Timer Mode is FastPWM with timer reload at OCR2A (Bits: WGM22 = 1, WGM21 = 1, WGM20 = 1) |
196 | // PD7: Normal port operation, OC2A disconnected, (Bits: COM2A1 = 0, COM2A0 = 0) |
201 | // PD7: Normal port operation, OC2A disconnected, (Bits: COM2A1 = 0, COM2A0 = 0) |
197 | // PD6: Normal port operation, OC2B disconnected, (Bits: COM2B1 = 0, COM2B0 = 0) |
202 | // PD6: Normal port operation, OC2B disconnected, (Bits: COM2B1 = 0, COM2B0 = 0) |
198 | TCCR2A &= ~((1<<COM2A1)|(1<<COM2A0)|(1<<COM2B1)|(1<<COM2B0)); |
203 | TCCR2A &= ~((1<<COM2A1)|(1<<COM2A0)|(1<<COM2B1)|(1<<COM2B0)); |
199 | TCCR2A |= (1<<WGM21)|(1<<WGM20); |
204 | TCCR2A |= (1<<WGM21)|(1<<WGM20); |
200 | 205 | ||
201 | // Timer/Counter 2 Control Register B |
206 | // Timer/Counter 2 Control Register B |
202 | 207 | ||
203 | // Set clock divider for timer 2 to SYSKLOCK/32 = 20MHz / 32 = 625 kHz |
208 | // Set clock divider for timer 2 to SYSKLOCK/32 = 20MHz / 32 = 625 kHz |
204 | // The timer increments from 0x00 to 0xFF with an update rate of 625 kHz or 1.6 us |
209 | // The timer increments from 0x00 to 0xFF with an update rate of 625 kHz or 1.6 us |
205 | // hence the timer overflow interrupt frequency is 625 kHz / 256 = 2.44 kHz or 0.4096 ms |
210 | // hence the timer overflow interrupt frequency is 625 kHz / 256 = 2.44 kHz or 0.4096 ms |
206 | 211 | ||
207 | // divider 32 (Bits: CS022 = 0, CS21 = 1, CS20 = 1) |
212 | // divider 32 (Bits: CS022 = 0, CS21 = 1, CS20 = 1) |
208 | TCCR2B &= ~((1<<FOC2A)|(1<<FOC2B)|(1<<CS22)); |
213 | TCCR2B &= ~((1<<FOC2A)|(1<<FOC2B)|(1<<CS22)); |
209 | TCCR2B |= (1<<CS21)|(1<<CS20)|(1<<WGM22); |
214 | TCCR2B |= (1<<CS21)|(1<<CS20)|(1<<WGM22); |
210 | 215 | ||
211 | // Initialize the Timer/Counter 2 Register |
216 | // Initialize the Timer/Counter 2 Register |
212 | TCNT2 = 0; |
217 | TCNT2 = 0; |
213 | 218 | ||
214 | // Initialize the Output Compare Register A used for PWM generation on port PD7. |
219 | // Initialize the Output Compare Register A used for PWM generation on port PD7. |
215 | OCR2A = 255; |
220 | OCR2A = 255; |
216 | TCCR2A |= (1<<COM2A1); // set or clear at compare match depends on value of COM2A0 |
221 | TCCR2A |= (1<<COM2A1); // set or clear at compare match depends on value of COM2A0 |
217 | 222 | ||
218 | // Timer/Counter 2 Interrupt Mask Register |
223 | // Timer/Counter 2 Interrupt Mask Register |
219 | // Enable timer output compare match A Interrupt only |
224 | // Enable timer output compare match A Interrupt only |
220 | TIMSK2 &= ~((1<<OCIE2B)|(1<<TOIE2)); |
225 | TIMSK2 &= ~((1<<OCIE2B)|(1<<TOIE2)); |
221 | TIMSK2 |= (1<<OCIE2A); |
226 | TIMSK2 |= (1<<OCIE2A); |
222 | 227 | ||
223 | SREG = sreg; |
228 | SREG = sreg; |
224 | } |
229 | } |
225 | 230 | ||
226 | //---------------------------- |
231 | //---------------------------- |
227 | void Timer_Init(void) |
232 | void Timer_Init(void) |
228 | { |
233 | { |
229 | tim_main = SetDelay(10); |
234 | tim_main = SetDelay(10); |
230 | TCCR0B = CK8; |
235 | TCCR0B = CK8; |
231 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
236 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
232 | OCR0A = 0; |
237 | OCR0A = 0; |
233 | OCR0B = 180; |
238 | OCR0B = 180; |
234 | TCNT0 = (unsigned char)-TIMER_RELOAD_VALUE; // reload |
239 | TCNT0 = (unsigned char)-TIMER_RELOAD_VALUE; // reload |
235 | //OCR1 = 0x00; |
240 | //OCR1 = 0x00; |
236 | TIMSK0 |= _BV(TOIE0); |
241 | TIMSK0 |= _BV(TOIE0); |
237 | } |
242 | } |
238 | 243 | ||
239 | 244 | ||
240 | /*****************************************************/ |
245 | /*****************************************************/ |
241 | /* Control Servo Position */ |
246 | /* Control Servo Position */ |
242 | /*****************************************************/ |
247 | /*****************************************************/ |
- | 248 | void CalcNickServoValue(void) |
|
- | 249 | { |
|
- | 250 | unsigned int max, min; |
|
- | 251 | ||
- | 252 | if(EE_Parameter.ServoCompInvert & SERVO_RELATIVE) // relative moving of the servo value |
|
- | 253 | { |
|
- | 254 | max = ((unsigned int) EE_Parameter.ServoNickMax * MULTIPLYER * 15); |
|
- | 255 | min = ((unsigned int) EE_Parameter.ServoNickMin * MULTIPLYER * 20); |
|
- | 256 | NickServoValue -= ((signed char) (Parameter_ServoNickControl - 128) / 2) * 4; |
|
- | 257 | LIMIT_MIN_MAX(NickServoValue,min, max); |
|
- | 258 | } |
|
- | 259 | else NickServoValue = (int16_t)Parameter_ServoNickControl * (MULTIPLYER*16); // direct poti control |
|
243 | 260 | } |
|
244 | 261 | ||
245 | void CalculateServo(void) |
262 | void CalculateServo(void) |
246 | { |
263 | { |
247 | signed char cosinus, sinus; |
264 | signed char cosinus, sinus; |
248 | signed long nick, roll; |
265 | signed long nick, roll; |
249 | 266 | ||
250 | cosinus = sintab[EE_Parameter.CamOrientation + 6]; |
267 | cosinus = sintab[EE_Parameter.CamOrientation + 6]; |
251 | sinus = sintab[EE_Parameter.CamOrientation]; |
268 | sinus = sintab[EE_Parameter.CamOrientation]; |
252 | 269 | ||
253 | if(CalculateServoSignals == 1) |
270 | if(CalculateServoSignals == 1) |
254 | { |
271 | { |
255 | nick = (cosinus * IntegralNick) / 128L - (sinus * IntegralRoll) / 128L; |
272 | nick = (cosinus * IntegralNick) / 128L - (sinus * IntegralRoll) / 128L; |
256 | nick -= POI_KameraNick * 7; |
273 | nick -= POI_KameraNick * 7; |
257 | nick = ((long)EE_Parameter.ServoNickComp * nick) / 512L; |
274 | nick = ((long)EE_Parameter.ServoNickComp * nick) / 512L; |
258 | // offset (Range from 0 to 255 * 3 = 765) |
275 | // offset (Range from 0 to 255 * 3 = 765) |
- | 276 | if(EE_Parameter.ServoCompInvert & SERVO_RELATIVE) ServoNickOffset = NickServoValue; |
|
259 | ServoNickOffset += ((int16_t)Parameter_ServoNickControl * (MULTIPLYER*16) - ServoNickOffset) / EE_Parameter.ServoManualControlSpeed; |
277 | else ServoNickOffset += (NickServoValue - ServoNickOffset) / EE_Parameter.ServoManualControlSpeed; |
- | 278 | ||
260 | if(EE_Parameter.ServoCompInvert & 0x01) // inverting movement of servo |
279 | if(EE_Parameter.ServoCompInvert & SERVO_NICK_INV) // inverting movement of servo |
261 | { |
280 | { |
262 | nick = ServoNickOffset / 16 + nick; |
281 | nick = ServoNickOffset / 16 + nick; |
263 | } |
282 | } |
264 | else |
283 | else |
265 | { // inverting movement of servo |
284 | { // inverting movement of servo |
266 | nick = ServoNickOffset / 16 - nick; |
285 | nick = ServoNickOffset / 16 - nick; |
267 | } |
286 | } |
268 | if(EE_Parameter.ServoFilterNick) ServoNickValue = ((ServoNickValue * EE_Parameter.ServoFilterNick) + nick) / (EE_Parameter.ServoFilterNick + 1); |
287 | if(EE_Parameter.ServoFilterNick) ServoNickValue = ((ServoNickValue * EE_Parameter.ServoFilterNick) + nick) / (EE_Parameter.ServoFilterNick + 1); |
269 | else ServoNickValue = nick; |
288 | else ServoNickValue = nick; |
270 | // limit servo value to its parameter range definition |
289 | // limit servo value to its parameter range definition |
271 | if(ServoNickValue < ((int16_t)EE_Parameter.ServoNickMin * MULTIPLYER)) |
290 | if(ServoNickValue < ((int16_t)EE_Parameter.ServoNickMin * MULTIPLYER)) |
272 | { |
291 | { |
273 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMin * MULTIPLYER; |
292 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMin * MULTIPLYER; |
274 | } |
293 | } |
275 | else |
294 | else |
276 | if(ServoNickValue > ((int16_t)EE_Parameter.ServoNickMax * MULTIPLYER)) |
295 | if(ServoNickValue > ((int16_t)EE_Parameter.ServoNickMax * MULTIPLYER)) |
277 | { |
296 | { |
278 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMax * MULTIPLYER; |
297 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMax * MULTIPLYER; |
279 | } |
298 | } |
280 | if(PlatinenVersion < 20) CalculateServoSignals = 0; else CalculateServoSignals++; |
299 | if(PlatinenVersion < 20) CalculateServoSignals = 0; else CalculateServoSignals++; |
281 | } |
300 | } |
282 | else |
301 | else |
283 | { |
302 | { |
284 | roll = (cosinus * IntegralRoll) / 128L + (sinus * IntegralNick) / 128L; |
303 | roll = (cosinus * IntegralRoll) / 128L + (sinus * IntegralNick) / 128L; |
285 | roll = ((long)EE_Parameter.ServoRollComp * roll) / 512L; |
304 | roll = ((long)EE_Parameter.ServoRollComp * roll) / 512L; |
286 | ServoRollOffset += ((int16_t)Parameter_ServoRollControl * (MULTIPLYER*16) - ServoRollOffset) / EE_Parameter.ServoManualControlSpeed; |
305 | ServoRollOffset += ((int16_t)Parameter_ServoRollControl * (MULTIPLYER*16) - ServoRollOffset) / EE_Parameter.ServoManualControlSpeed; |
287 | if(EE_Parameter.ServoCompInvert & 0x02) |
306 | if(EE_Parameter.ServoCompInvert & SERVO_ROLL_INV) |
288 | { // inverting movement of servo |
307 | { // inverting movement of servo |
289 | roll = ServoRollOffset / 16 + roll; |
308 | roll = ServoRollOffset / 16 + roll; |
290 | } |
309 | } |
291 | else |
310 | else |
292 | { // inverting movement of servo |
311 | { // inverting movement of servo |
293 | roll = ServoRollOffset / 16 - roll; |
312 | roll = ServoRollOffset / 16 - roll; |
294 | } |
313 | } |
295 | if(EE_Parameter.ServoFilterRoll) ServoRollValue = ((ServoRollValue * EE_Parameter.ServoFilterRoll) + roll) / (EE_Parameter.ServoFilterRoll + 1); |
314 | if(EE_Parameter.ServoFilterRoll) ServoRollValue = ((ServoRollValue * EE_Parameter.ServoFilterRoll) + roll) / (EE_Parameter.ServoFilterRoll + 1); |
296 | else ServoRollValue = roll; |
315 | else ServoRollValue = roll; |
297 | // limit servo value to its parameter range definition |
316 | // limit servo value to its parameter range definition |
298 | if(ServoRollValue < ((int16_t)EE_Parameter.ServoRollMin * MULTIPLYER)) |
317 | if(ServoRollValue < ((int16_t)EE_Parameter.ServoRollMin * MULTIPLYER)) |
299 | { |
318 | { |
300 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMin * MULTIPLYER; |
319 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMin * MULTIPLYER; |
301 | } |
320 | } |
302 | else |
321 | else |
303 | if(ServoRollValue > ((int16_t)EE_Parameter.ServoRollMax * MULTIPLYER)) |
322 | if(ServoRollValue > ((int16_t)EE_Parameter.ServoRollMax * MULTIPLYER)) |
304 | { |
323 | { |
305 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMax * MULTIPLYER; |
324 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMax * MULTIPLYER; |
306 | } |
325 | } |
307 | CalculateServoSignals = 0; |
326 | CalculateServoSignals = 0; |
308 | } |
327 | } |
309 | } |
328 | } |
310 | 329 | ||
311 | ISR(TIMER2_COMPA_vect) |
330 | ISR(TIMER2_COMPA_vect) |
312 | { |
331 | { |
313 | // frame len 22.5 ms = 14063 * 1.6 us |
332 | // frame len 22.5 ms = 14063 * 1.6 us |
314 | // stop pulse: 0.3 ms = 188 * 1.6 us |
333 | // stop pulse: 0.3 ms = 188 * 1.6 us |
315 | // min servo pulse: 0.6 ms = 375 * 1.6 us |
334 | // min servo pulse: 0.6 ms = 375 * 1.6 us |
316 | // max servo pulse: 2.4 ms = 1500 * 1.6 us |
335 | // max servo pulse: 2.4 ms = 1500 * 1.6 us |
317 | // resolution: 1500 - 375 = 1125 steps |
336 | // resolution: 1500 - 375 = 1125 steps |
318 | 337 | ||
319 | #define IRS_RUNTIME 127 |
338 | #define IRS_RUNTIME 127 |
320 | #define PPM_STOPPULSE 188 |
339 | #define PPM_STOPPULSE 188 |
321 | #define PPM_FRAMELEN (1757 * EE_Parameter.ServoNickRefresh) |
340 | #define PPM_FRAMELEN (1757 * EE_Parameter.ServoNickRefresh) |
322 | #define MINSERVOPULSE 375 |
341 | #define MINSERVOPULSE 375 |
323 | #define MAXSERVOPULSE 1500 |
342 | #define MAXSERVOPULSE 1500 |
324 | #define SERVORANGE (MAXSERVOPULSE - MINSERVOPULSE) |
343 | #define SERVORANGE (MAXSERVOPULSE - MINSERVOPULSE) |
325 | 344 | ||
326 | static uint8_t PulseOutput = 0; |
345 | static uint8_t PulseOutput = 0; |
327 | static uint16_t ServoFrameTime = 0; |
346 | static uint16_t ServoFrameTime = 0; |
328 | static uint8_t ServoIndex = 0; |
347 | static uint8_t ServoIndex = 0; |
329 | 348 | ||
330 | 349 | ||
331 | if(PlatinenVersion < 20) |
350 | if(PlatinenVersion < 20) |
332 | { |
351 | { |
333 | //--------------------------- |
352 | //--------------------------- |
334 | // Nick servo state machine |
353 | // Nick servo state machine |
335 | //--------------------------- |
354 | //--------------------------- |
336 | if(!PulseOutput) // pulse output complete |
355 | if(!PulseOutput) // pulse output complete |
337 | { |
356 | { |
338 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
357 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
339 | { |
358 | { |
340 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
359 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
341 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
360 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
342 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
361 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
343 | // range servo pulse width |
362 | // range servo pulse width |
344 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
363 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
345 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
364 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
346 | // accumulate time for correct update rate |
365 | // accumulate time for correct update rate |
347 | ServoFrameTime = RemainingPulse; |
366 | ServoFrameTime = RemainingPulse; |
348 | } |
367 | } |
349 | else // we had a high pulse |
368 | else // we had a high pulse |
350 | { |
369 | { |
351 | TCCR2A |= (1<<COM2A0); // make a low pulse |
370 | TCCR2A |= (1<<COM2A0); // make a low pulse |
352 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; |
371 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; |
353 | CalculateServoSignals = 1; |
372 | CalculateServoSignals = 1; |
354 | } |
373 | } |
355 | // set pulse output active |
374 | // set pulse output active |
356 | PulseOutput = 1; |
375 | PulseOutput = 1; |
357 | } |
376 | } |
358 | } // EOF Nick servo state machine |
377 | } // EOF Nick servo state machine |
359 | else |
378 | else |
360 | { |
379 | { |
361 | //----------------------------------------------------- |
380 | //----------------------------------------------------- |
362 | // PPM state machine, onboard demultiplexed by HEF4017 |
381 | // PPM state machine, onboard demultiplexed by HEF4017 |
363 | //----------------------------------------------------- |
382 | //----------------------------------------------------- |
364 | if(!PulseOutput) // pulse output complete |
383 | if(!PulseOutput) // pulse output complete |
365 | { |
384 | { |
366 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
385 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
367 | { |
386 | { |
368 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
387 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
369 | if(ServoIndex == 0) // if we are at the sync gap |
388 | if(ServoIndex == 0) // if we are at the sync gap |
370 | { |
389 | { |
371 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; // generate sync gap by filling time to full frame time |
390 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; // generate sync gap by filling time to full frame time |
372 | ServoFrameTime = 0; // reset servo frame time |
391 | ServoFrameTime = 0; // reset servo frame time |
373 | HEF4017Reset_ON; // enable HEF4017 reset |
392 | HEF4017Reset_ON; // enable HEF4017 reset |
374 | } |
393 | } |
375 | else // servo channels |
394 | else // servo channels |
376 | if(ServoIndex > EE_Parameter.ServoNickRefresh) |
395 | if(ServoIndex > EE_Parameter.ServoNickRefresh) |
377 | { |
396 | { |
378 | RemainingPulse = 10; // end it here |
397 | RemainingPulse = 10; // end it here |
379 | } |
398 | } |
380 | else |
399 | else |
381 | { |
400 | { |
382 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
401 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
383 | switch(ServoIndex) // map servo channels |
402 | switch(ServoIndex) // map servo channels |
384 | { |
403 | { |
385 | case 1: // Nick Compensation Servo |
404 | case 1: // Nick Compensation Servo |
386 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
405 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
387 | break; |
406 | break; |
388 | case 2: // Roll Compensation Servo |
407 | case 2: // Roll Compensation Servo |
389 | RemainingPulse += ServoRollValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
408 | RemainingPulse += ServoRollValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
390 | break; |
409 | break; |
391 | case 3: |
410 | case 3: |
392 | RemainingPulse += ((int16_t)Parameter_Servo3 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
411 | RemainingPulse += ((int16_t)Parameter_Servo3 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
393 | break; |
412 | break; |
394 | case 4: |
413 | case 4: |
395 | RemainingPulse += ((int16_t)Parameter_Servo4 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
414 | RemainingPulse += ((int16_t)Parameter_Servo4 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
396 | break; |
415 | break; |
397 | case 5: |
416 | case 5: |
398 | RemainingPulse += ((int16_t)Parameter_Servo5 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
417 | RemainingPulse += ((int16_t)Parameter_Servo5 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
399 | break; |
418 | break; |
400 | default: // other servo channels |
419 | default: // other servo channels |
401 | RemainingPulse += 2 * PPM_in[ServoIndex]; // add channel value, factor of 2 because timer 1 increments 3.2µs |
420 | RemainingPulse += 2 * PPM_in[ServoIndex]; // add channel value, factor of 2 because timer 1 increments 3.2µs |
402 | break; |
421 | break; |
403 | } |
422 | } |
404 | // range servo pulse width |
423 | // range servo pulse width |
405 | if(RemainingPulse > MAXSERVOPULSE) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
424 | if(RemainingPulse > MAXSERVOPULSE) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
406 | else if(RemainingPulse < MINSERVOPULSE) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
425 | else if(RemainingPulse < MINSERVOPULSE) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
407 | // substract stop pulse width |
426 | // substract stop pulse width |
408 | RemainingPulse -= PPM_STOPPULSE; |
427 | RemainingPulse -= PPM_STOPPULSE; |
409 | // accumulate time for correct sync gap |
428 | // accumulate time for correct sync gap |
410 | ServoFrameTime += RemainingPulse; |
429 | ServoFrameTime += RemainingPulse; |
411 | } |
430 | } |
412 | } |
431 | } |
413 | else // we had a high pulse |
432 | else // we had a high pulse |
414 | { |
433 | { |
415 | TCCR2A |= (1<<COM2A0); // make a low pulse |
434 | TCCR2A |= (1<<COM2A0); // make a low pulse |
416 | // set pulsewidth to stop pulse width |
435 | // set pulsewidth to stop pulse width |
417 | RemainingPulse = PPM_STOPPULSE; |
436 | RemainingPulse = PPM_STOPPULSE; |
418 | // accumulate time for correct sync gap |
437 | // accumulate time for correct sync gap |
419 | ServoFrameTime += RemainingPulse; |
438 | ServoFrameTime += RemainingPulse; |
420 | if((ServoActive && SenderOkay) || ServoActive == 2) HEF4017Reset_OFF; // disable HEF4017 reset |
439 | if((ServoActive && SenderOkay) || ServoActive == 2) HEF4017Reset_OFF; // disable HEF4017 reset |
421 | else HEF4017Reset_ON; |
440 | else HEF4017Reset_ON; |
422 | ServoIndex++; |
441 | ServoIndex++; |
423 | if(ServoIndex > EE_Parameter.ServoNickRefresh+1) |
442 | if(ServoIndex > EE_Parameter.ServoNickRefresh+1) |
424 | { |
443 | { |
425 | CalculateServoSignals = 1; |
444 | CalculateServoSignals = 1; |
426 | ServoIndex = 0; // reset to the sync gap |
445 | ServoIndex = 0; // reset to the sync gap |
427 | } |
446 | } |
428 | } |
447 | } |
429 | // set pulse output active |
448 | // set pulse output active |
430 | PulseOutput = 1; |
449 | PulseOutput = 1; |
431 | } |
450 | } |
432 | } // EOF PPM state machine |
451 | } // EOF PPM state machine |
433 | 452 | ||
434 | // General pulse output generator |
453 | // General pulse output generator |
435 | if(RemainingPulse > (255 + IRS_RUNTIME)) |
454 | if(RemainingPulse > (255 + IRS_RUNTIME)) |
436 | { |
455 | { |
437 | OCR2A = 255; |
456 | OCR2A = 255; |
438 | RemainingPulse -= 255; |
457 | RemainingPulse -= 255; |
439 | } |
458 | } |
440 | else |
459 | else |
441 | { |
460 | { |
442 | if(RemainingPulse > 255) // this is the 2nd last part |
461 | if(RemainingPulse > 255) // this is the 2nd last part |
443 | { |
462 | { |
444 | if((RemainingPulse - 255) < IRS_RUNTIME) |
463 | if((RemainingPulse - 255) < IRS_RUNTIME) |
445 | { |
464 | { |
446 | OCR2A = 255 - IRS_RUNTIME; |
465 | OCR2A = 255 - IRS_RUNTIME; |
447 | RemainingPulse -= 255 - IRS_RUNTIME; |
466 | RemainingPulse -= 255 - IRS_RUNTIME; |
448 | 467 | ||
449 | } |
468 | } |
450 | else // last part > ISR_RUNTIME |
469 | else // last part > ISR_RUNTIME |
451 | { |
470 | { |
452 | OCR2A = 255; |
471 | OCR2A = 255; |
453 | RemainingPulse -= 255; |
472 | RemainingPulse -= 255; |
454 | } |
473 | } |
455 | } |
474 | } |
456 | else // this is the last part |
475 | else // this is the last part |
457 | { |
476 | { |
458 | OCR2A = RemainingPulse; |
477 | OCR2A = RemainingPulse; |
459 | RemainingPulse = 0; |
478 | RemainingPulse = 0; |
460 | PulseOutput = 0; // trigger to stop pulse |
479 | PulseOutput = 0; // trigger to stop pulse |
461 | } |
480 | } |
462 | } // EOF general pulse output generator |
481 | } // EOF general pulse output generator |
463 | } |
482 | } |
464 | 483 |