Subversion Repositories FlightCtrl

Rev

Rev 2133 | Rev 2139 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2133 Rev 2135
Line 7... Line 7...
7
#include "timer2.h"
7
#include "timer2.h"
Line 8... Line 8...
8
 
8
 
Line 9... Line 9...
9
// #define COARSERESOLUTION 1
9
// #define COARSERESOLUTION 1
10
 
10
 
11
#ifdef COARSERESOLUTION
11
#ifdef COARSERESOLUTION
12
#define NEUTRAL_PULSELENGTH 938
12
#define NEUTRAL_PULSELENGTH ((int16_t)(F_CPU/32000*1.5f + 0.5f))
13
#define STABILIZATION_LOG_DIVIDER 6
13
#define STABILIZATION_LOG_DIVIDER 6
14
#define SERVOLIMIT 500
14
#define SERVOLIMIT ((int16_t)(F_CPU/32000*0.8f + 0.5f))
Line 15... Line 15...
15
#define SCALE_FACTOR 4
15
#define SCALE_FACTOR 4
16
#define CS2 ((1<<CS21)|(1<<CS20))
16
#define CS2 ((1<<CS21)|(1<<CS20))
17
 
17
 
18
#else
18
#else
19
#define NEUTRAL_PULSELENGTH 3750
19
#define NEUTRAL_PULSELENGTH ((int16_t)(F_CPU/8000.0f * 1.5f + 0.5f))
20
#define STABILIZATION_LOG_DIVIDER 4
20
#define STABILIZATION_LOG_DIVIDER 4
21
#define SERVOLIMIT 2000
21
#define SERVOLIMIT ((int16_t)(F_CPU/8000.0f * 0.8f + 0.5f))
Line 22... Line 22...
22
#define SCALE_FACTOR 16
22
#define SCALE_FACTOR 16
23
#define CS2 (1<<CS21)
23
#define CS2 (1<<CS21)
24
#endif
24
#endif
Line 25... Line 25...
25
 
25
 
26
#define FRAMELEN ((NEUTRAL_PULSELENGTH + SERVOLIMIT) * staticParams.servoCount + 128)
26
#define FRAMELENGTH ((uint16_t)(NEUTRAL_PULSELENGTH + SERVOLIMIT) * (uint16_t)staticParams.servoCount + 128)
Line 41... Line 41...
41
    uint8_t sreg = SREG;
41
    uint8_t sreg = SREG;
Line 42... Line 42...
42
 
42
 
43
    // disable all interrupts before reconfiguration
43
    // disable all interrupts before reconfiguration
Line 44... Line 44...
44
    cli();
44
    cli();
45
 
45
 
46
    // set PD7 as output of the PWM for pitch servo
46
    // set PD7 as output of the 4017 clk
Line 47... Line 47...
47
    DDRB |= (1 << DDB3);
47
    DDRB |= (1 << DDB3);
48
    PORTB &= ~(1 << PORTB3); // set PD7 to low
48
    PORTB &= ~(1 << PORTB3); // set PD7 to low
Line 167... Line 167...
167
      // There are more signals to output.
167
      // There are more signals to output.
168
      sumOfPulseTimes += (remainingPulseTime = servoValues[servoIndex]);
168
      sumOfPulseTimes += (remainingPulseTime = servoValues[servoIndex]);
169
      servoIndex++;
169
      servoIndex++;
170
    } else {
170
    } else {
171
      // There are no more signals. Reset the counter and make this pulse cover the missing frame time.
171
      // There are no more signals. Reset the counter and make this pulse cover the missing frame time.
172
      remainingPulseTime = FRAMELEN - sumOfPulseTimes;
172
      remainingPulseTime = FRAMELENGTH - sumOfPulseTimes;
173
      sumOfPulseTimes = servoIndex = 0;
173
      sumOfPulseTimes = servoIndex = 0;
174
      recalculateServoTimes = 1;
174
      recalculateServoTimes = 1;
175
      HEF4017R_ON;
175
      HEF4017R_ON;
176
    }
176
    }
177
  }
177
  }