Subversion Repositories FlightCtrl

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2050 holgerb 1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + www.MikroKopter.com
3
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// + Software Nutzungsbedingungen (english version: see below)
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
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.
9
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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.
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.
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.
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 
19
// + des Mitverschuldens offen.
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.
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
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.
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.
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Software LICENSING TERMS
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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 
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.
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
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
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
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
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.
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.
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.
49
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
50
// + #### END OF LICENSING TERMS ####
51
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
52
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53
 
1 ingob 54
#include "main.h"
1760 holgerb 55
#define MULTIPLYER 4
1 ingob 56
 
57
volatile unsigned int CountMilliseconds = 0;
58
volatile static unsigned int tim_main;
59
volatile unsigned char UpdateMotor = 0;
60
volatile unsigned int cntKompass = 0;
61
volatile unsigned int beeptime = 0;
1760 holgerb 62
volatile unsigned char SendSPI = 0, ServoActive = 0, CalculateServoSignals = 1;
63
uint16_t RemainingPulse = 0;
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
723 hbuss 66
 
173 holgerb 67
unsigned int BeepMuster = 0xffff;
1 ingob 68
 
1156 hbuss 69
volatile int16_t        ServoNickValue = 0;
70
volatile int16_t        ServoRollValue = 0;
71
 
72
 
1 ingob 73
enum {
74
  STOP             = 0,
75
  CK               = 1,
76
  CK8              = 2,
77
  CK64             = 3,
78
  CK256            = 4,
79
  CK1024           = 5,
80
  T0_FALLING_EDGE  = 6,
81
  T0_RISING_EDGE   = 7
82
};
83
 
84
 
1561 killagreg 85
ISR(TIMER0_OVF_vect)    // 9,7kHz
1 ingob 86
{
1643 holgerb 87
   static unsigned char cnt_1ms = 1,cnt = 0, compass_active = 0;
88
   unsigned char pieper_ein = 0;
723 hbuss 89
   if(SendSPI) SendSPI--;
1469 killagreg 90
   if(SpektrumTimer) SpektrumTimer--;
1 ingob 91
   if(!cnt--)
92
    {
1105 killagreg 93
     cnt = 9;
1643 holgerb 94
     CountMilliseconds++;
1 ingob 95
     cnt_1ms++;
96
     cnt_1ms %= 2;
1643 holgerb 97
 
1 ingob 98
     if(!cnt_1ms) UpdateMotor = 1;
1713 holgerb 99
         if(!(PINC & 0x10)) compass_active = 1;
1643 holgerb 100
 
1664 holgerb 101
     if(beeptime)
1 ingob 102
        {
1664 holgerb 103
        if(beeptime > 10) beeptime -= 10; else beeptime = 0;
1105 killagreg 104
        if(beeptime & BeepMuster)
173 holgerb 105
         {
106
          pieper_ein = 1;
107
         }
108
         else pieper_ein = 0;
1 ingob 109
        }
1105 killagreg 110
     else
1651 killagreg 111
      {
173 holgerb 112
       pieper_ein = 0;
113
       BeepMuster = 0xffff;
1105 killagreg 114
      }
173 holgerb 115
     if(pieper_ein)
116
        {
117
          if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker an PORTD.2
118
          else                      PORTC |= (1<<7); // Speaker an PORTC.7
119
        }
1105 killagreg 120
     else
173 holgerb 121
        {
122
         if(PlatinenVersion == 10) PORTD &= ~(1<<2);
123
         else                      PORTC &= ~(1<<7);
1105 killagreg 124
        }
1643 holgerb 125
        }
1916 holgerb 126
 if(compass_active && !NaviDataOkay && Parameter_GlobalConfig & CFG_KOMPASS_AKTIV)
1 ingob 127
 {
128
  if(PINC & 0x10)
129
   {
1643 holgerb 130
        if(++cntKompass > 1000) compass_active = 0;
1 ingob 131
   }
132
  else
133
   {
1105 killagreg 134
    if((cntKompass) && (cntKompass < 362))
135
    {
693 hbuss 136
     cntKompass += cntKompass / 41;
137
     if(cntKompass > 10) KompassValue = cntKompass - 10; else KompassValue = 0;
1941 holgerb 138
//     KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180;
1105 killagreg 139
    }
1 ingob 140
    cntKompass = 0;
1105 killagreg 141
   }
1 ingob 142
 }
143
}
144
 
145
 
146
// -----------------------------------------------------------------------
2090 holgerb 147
unsigned int SetDelay(unsigned int t)
1 ingob 148
{
149
//  TIMSK0 &= ~_BV(TOIE0);
1105 killagreg 150
  return(CountMilliseconds + t + 1);
1 ingob 151
//  TIMSK0 |= _BV(TOIE0);
152
}
153
 
154
// -----------------------------------------------------------------------
155
char CheckDelay(unsigned int t)
156
{
157
//  TIMSK0 &= ~_BV(TOIE0);
158
  return(((t - CountMilliseconds) & 0x8000) >> 9);
159
//  TIMSK0 |= _BV(TOIE0);
160
}
161
 
162
// -----------------------------------------------------------------------
163
void Delay_ms(unsigned int w)
164
{
165
 unsigned int akt;
166
 akt = SetDelay(w);
167
 while (!CheckDelay(akt));
168
}
169
 
395 hbuss 170
void Delay_ms_Mess(unsigned int w)
171
{
172
 unsigned int akt;
173
 akt = SetDelay(w);
1166 hbuss 174
 while (!CheckDelay(akt)) if(AdReady) {AdReady = 0; ANALOG_ON;}
395 hbuss 175
}
176
 
1156 hbuss 177
/*****************************************************/
178
/*              Initialize Timer 2                   */
179
/*****************************************************/
180
// The timer 2 is used to generate the PWM at PD7 (J7)
181
// to control a camera servo for nick compensation.
182
void TIMER2_Init(void)
910 hbuss 183
{
1156 hbuss 184
        uint8_t sreg = SREG;
185
 
186
        // disable all interrupts before reconfiguration
187
        cli();
1469 killagreg 188
 
1156 hbuss 189
        PORTD &= ~(1<<PORTD7);  // set PD7 to low
190
 
191
        DDRC  |= (1<<DDC6);     // set PC6 as output (Reset for HEF4017)
1171 hbuss 192
    HEF4017R_ON;
1156 hbuss 193
        // Timer/Counter 2 Control Register A
194
 
195
        // 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)
197
    // PD6: Normal port operation, OC2B disconnected, (Bits: COM2B1 = 0, COM2B0 = 0)
198
        TCCR2A &= ~((1<<COM2A1)|(1<<COM2A0)|(1<<COM2B1)|(1<<COM2B0));
199
    TCCR2A |= (1<<WGM21)|(1<<WGM20);
200
 
201
    // Timer/Counter 2 Control Register B
202
 
203
        // 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
205
        // hence the timer overflow interrupt frequency is 625 kHz / 256 = 2.44 kHz or 0.4096 ms
206
 
207
    // divider 32 (Bits: CS022 = 0, CS21 = 1, CS20 = 1)
208
        TCCR2B &= ~((1<<FOC2A)|(1<<FOC2B)|(1<<CS22));
209
    TCCR2B |= (1<<CS21)|(1<<CS20)|(1<<WGM22);
210
 
211
        // Initialize the Timer/Counter 2 Register
212
    TCNT2 = 0;
213
 
214
        // Initialize the Output Compare Register A used for PWM generation on port PD7.
215
        OCR2A = 255;
216
        TCCR2A |= (1<<COM2A1); // set or clear at compare match depends on value of COM2A0
217
 
218
        // Timer/Counter 2 Interrupt Mask Register
219
        // Enable timer output compare match A Interrupt only
220
        TIMSK2 &= ~((1<<OCIE2B)|(1<<TOIE2));
221
        TIMSK2 |= (1<<OCIE2A);
222
 
223
    SREG = sreg;
910 hbuss 224
}
225
 
1156 hbuss 226
//----------------------------
227
void Timer_Init(void)
1 ingob 228
{
1156 hbuss 229
    tim_main = SetDelay(10);
230
    TCCR0B = CK8;
231
    TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM
232
    OCR0A =  0;
1638 holgerb 233
    OCR0B = 180;
1156 hbuss 234
    TCNT0 = (unsigned char)-TIMER_RELOAD_VALUE;  // reload
235
    //OCR1  = 0x00;
236
    TIMSK0 |= _BV(TOIE0);
237
}
238
 
239
 
240
/*****************************************************/
241
/*              Control Servo Position               */
242
/*****************************************************/
243
 
1760 holgerb 244
 
245
void CalculateServo(void)
246
{
1771 holgerb 247
 signed char cosinus, sinus;
248
 signed long nick, roll;
1760 holgerb 249
 
250
        cosinus = sintab[EE_Parameter.CamOrientation + 6];
251
        sinus = sintab[EE_Parameter.CamOrientation];
252
 
253
  if(CalculateServoSignals == 1)
254
   {
1763 killagreg 255
                nick = (cosinus * IntegralNick) / 128L - (sinus * IntegralRoll) / 128L;
1848 holgerb 256
        nick -= POI_KameraNick * 7;
1763 killagreg 257
                nick = ((long)EE_Parameter.ServoNickComp * nick) / 512L;
2010 holgerb 258
                // offset (Range from 0 to 255 * 3 = 765)
1763 killagreg 259
                ServoNickOffset += ((int16_t)Parameter_ServoNickControl * (MULTIPLYER*16) - ServoNickOffset) / EE_Parameter.ServoManualControlSpeed;
2010 holgerb 260
                if(EE_Parameter.ServoCompInvert & 0x01) // inverting movement of servo
261
                {      
262
                        nick = ServoNickOffset / 16 + nick;
1763 killagreg 263
                }
264
                else
2010 holgerb 265
                {       // inverting movement of servo
266
                        nick = ServoNickOffset / 16 - nick;
1763 killagreg 267
                }
2012 holgerb 268
                if(EE_Parameter.ServoFilterNick) ServoNickValue = ((ServoNickValue * EE_Parameter.ServoFilterNick) + nick) / (EE_Parameter.ServoFilterNick + 1);
2010 holgerb 269
                else                     ServoNickValue = nick;
1763 killagreg 270
                // limit servo value to its parameter range definition
2040 holgerb 271
                if(ServoNickValue < ((int16_t)EE_Parameter.ServoNickMin * MULTIPLYER))
1763 killagreg 272
                {
273
                        ServoNickValue = (int16_t)EE_Parameter.ServoNickMin * MULTIPLYER;
274
                }
275
                else
2040 holgerb 276
                if(ServoNickValue > ((int16_t)EE_Parameter.ServoNickMax * MULTIPLYER))
1763 killagreg 277
                {
278
                        ServoNickValue = (int16_t)EE_Parameter.ServoNickMax * MULTIPLYER;
279
                }
280
                if(PlatinenVersion < 20) CalculateServoSignals = 0; else CalculateServoSignals++;
1760 holgerb 281
        }
282
        else
283
        {
1763 killagreg 284
        roll = (cosinus * IntegralRoll) / 128L + (sinus * IntegralNick) / 128L;
285
        roll = ((long)EE_Parameter.ServoRollComp * roll) / 512L;
286
                ServoRollOffset += ((int16_t)Parameter_ServoRollControl * (MULTIPLYER*16) - ServoRollOffset) / EE_Parameter.ServoManualControlSpeed;
287
                if(EE_Parameter.ServoCompInvert & 0x02)
288
                {       // inverting movement of servo
2010 holgerb 289
                        roll = ServoRollOffset / 16 + roll;
1763 killagreg 290
                }
291
                else
2010 holgerb 292
                {       // inverting movement of servo
293
                        roll = ServoRollOffset / 16 - roll;
1763 killagreg 294
                }
2012 holgerb 295
                if(EE_Parameter.ServoFilterRoll) ServoRollValue = ((ServoRollValue * EE_Parameter.ServoFilterRoll) + roll) / (EE_Parameter.ServoFilterRoll + 1);
2010 holgerb 296
                else                     ServoRollValue = roll;
1763 killagreg 297
                // limit servo value to its parameter range definition
2040 holgerb 298
                if(ServoRollValue < ((int16_t)EE_Parameter.ServoRollMin * MULTIPLYER))
1763 killagreg 299
                {
300
                        ServoRollValue = (int16_t)EE_Parameter.ServoRollMin * MULTIPLYER;
301
                }
302
                else
2040 holgerb 303
                if(ServoRollValue > ((int16_t)EE_Parameter.ServoRollMax * MULTIPLYER))
1763 killagreg 304
                {
305
                        ServoRollValue = (int16_t)EE_Parameter.ServoRollMax * MULTIPLYER;
306
                }
307
                CalculateServoSignals = 0;
1760 holgerb 308
        }
309
}
310
 
1156 hbuss 311
ISR(TIMER2_COMPA_vect)
312
{
313
        // frame len 22.5 ms = 14063 * 1.6 us
314
        // stop pulse: 0.3 ms = 188 * 1.6 us
315
        // min servo pulse: 0.6 ms =  375 * 1.6 us
316
        // max servo pulse: 2.4 ms = 1500 * 1.6 us
317
        // resolution: 1500 - 375 = 1125 steps
318
 
319
        #define IRS_RUNTIME 127
320
        #define PPM_STOPPULSE 188
1171 hbuss 321
    #define PPM_FRAMELEN (1757 * EE_Parameter.ServoNickRefresh)
1156 hbuss 322
        #define MINSERVOPULSE 375
323
        #define MAXSERVOPULSE 1500
324
        #define SERVORANGE (MAXSERVOPULSE - MINSERVOPULSE)
325
 
326
        static uint8_t  PulseOutput = 0;
327
        static uint16_t ServoFrameTime = 0;
328
        static uint8_t  ServoIndex = 0;
329
 
330
 
331
        if(PlatinenVersion < 20)
332
        {
333
                //---------------------------
334
                // Nick servo state machine
335
                //---------------------------
336
                if(!PulseOutput) // pulse output complete
337
                {
338
                        if(TCCR2A & (1<<COM2A0)) // we had a low pulse
339
                        {
340
                                TCCR2A &= ~(1<<COM2A0);// make a high pulse
341
                                RemainingPulse  = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms
342
                                RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position
343
                                // range servo pulse width
344
                                if(RemainingPulse > MAXSERVOPULSE )                     RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit
345
                                else if(RemainingPulse < MINSERVOPULSE )        RemainingPulse = MINSERVOPULSE; // lower servo pulse limit
346
                                // accumulate time for correct update rate
347
                                ServoFrameTime = RemainingPulse;
348
                        }
349
                        else // we had a high pulse
350
                        {
351
                                TCCR2A |= (1<<COM2A0); // make a low pulse
352
                                RemainingPulse = PPM_FRAMELEN - ServoFrameTime;
1763 killagreg 353
                                CalculateServoSignals = 1;
1156 hbuss 354
                        }
355
                        // set pulse output active
356
                        PulseOutput = 1;
357
                }
358
        } // EOF Nick servo state machine
359
        else
360
        {
361
                //-----------------------------------------------------
362
                // PPM state machine, onboard demultiplexed by HEF4017
363
                //-----------------------------------------------------
364
                if(!PulseOutput) // pulse output complete
365
                {
366
                        if(TCCR2A & (1<<COM2A0)) // we had a low pulse
367
                        {
368
                                TCCR2A &= ~(1<<COM2A0);// make a high pulse
369
 
370
                                if(ServoIndex == 0) // if we are at the sync gap
371
                                {
372
                                        RemainingPulse = PPM_FRAMELEN - ServoFrameTime; // generate sync gap by filling time to full frame time
373
                                        ServoFrameTime = 0; // reset servo frame time
374
                                        HEF4017R_ON; // enable HEF4017 reset
375
                                }
376
                                else // servo channels
377
                                {
378
                                        RemainingPulse  = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms
379
                                        switch(ServoIndex) // map servo channels
380
                                        {
381
                                                case 1: // Nick Compensation Servo
382
                                                        RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position
383
                                                        break;
1224 hbuss 384
                                         case 2: // Roll Compensation Servo
385
                                                        RemainingPulse += ServoRollValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position
1232 hbuss 386
                                                        break;
1565 killagreg 387
                                         case 3:
388
                                                        RemainingPulse += ((int16_t)Parameter_Servo3 * MULTIPLYER) - (256 / 2) * MULTIPLYER;
1403 hbuss 389
                                                        break;
1543 killagreg 390
                                         case 4:
1565 killagreg 391
                                                        RemainingPulse += ((int16_t)Parameter_Servo4 * MULTIPLYER) - (256 / 2) * MULTIPLYER;
1403 hbuss 392
                                                        break;
1543 killagreg 393
                                         case 5:
1565 killagreg 394
                                                        RemainingPulse += ((int16_t)Parameter_Servo5 * MULTIPLYER) - (256 / 2) * MULTIPLYER;
1403 hbuss 395
                                                        break;
1156 hbuss 396
                                                default: // other servo channels
397
                                                        RemainingPulse += 2 * PPM_in[ServoIndex]; // add channel value, factor of 2 because timer 1 increments 3.2µs
398
                                                        break;
399
                                        }
400
                                        // range servo pulse width
401
                                        if(RemainingPulse > MAXSERVOPULSE )                     RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit
402
                                        else if(RemainingPulse < MINSERVOPULSE )        RemainingPulse = MINSERVOPULSE; // lower servo pulse limit
403
                                        // substract stop pulse width
404
                                        RemainingPulse -= PPM_STOPPULSE;
405
                                        // accumulate time for correct sync gap
406
                                        ServoFrameTime += RemainingPulse;
407
                                }
408
                        }
409
                        else // we had a high pulse
410
                        {
411
                                TCCR2A |= (1<<COM2A0); // make a low pulse
412
                                // set pulsewidth to stop pulse width
413
                                RemainingPulse = PPM_STOPPULSE;
414
                                // accumulate time for correct sync gap
415
                                ServoFrameTime += RemainingPulse;
1916 holgerb 416
                                if((ServoActive && SenderOkay) || ServoActive == 2) HEF4017R_OFF; // disable HEF4017 reset
1232 hbuss 417
                                else HEF4017R_ON;
1156 hbuss 418
                                ServoIndex++; // change to next servo channel
1763 killagreg 419
                                if(ServoIndex > EE_Parameter.ServoNickRefresh)
420
                                  {
421
                                    CalculateServoSignals = 1;
1760 holgerb 422
                                        ServoIndex = 0; // reset to the sync gap
423
                                  }
1156 hbuss 424
                        }
425
                        // set pulse output active
426
                        PulseOutput = 1;
427
                }
428
        } // EOF PPM state machine
429
 
430
        // General pulse output generator
431
        if(RemainingPulse > (255 + IRS_RUNTIME))
432
        {
433
                OCR2A = 255;
434
                RemainingPulse -= 255;
910 hbuss 435
        }
1156 hbuss 436
        else
437
        {
438
                if(RemainingPulse > 255) // this is the 2nd last part
439
                {
440
                        if((RemainingPulse - 255) < IRS_RUNTIME)
441
                        {
442
                                OCR2A = 255 - IRS_RUNTIME;
443
                                RemainingPulse -= 255 - IRS_RUNTIME;
444
 
445
                        }
446
                        else // last part > ISR_RUNTIME
447
                        {
448
                                OCR2A = 255;
449
                                RemainingPulse -= 255;
450
                        }
451
                }
452
                else // this is the last part
453
                {
454
                        OCR2A = RemainingPulse;
455
                        RemainingPulse = 0;
456
                        PulseOutput = 0; // trigger to stop pulse
457
                }
458
        } // EOF general pulse output generator
1111 hbuss 459
}