Rev 2125 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2125 | 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) |
27 | #define MIN_PULSELENGTH (NEUTRAL_PULSELENGTH - SERVOLIMIT) |
27 | #define MIN_PULSELENGTH (NEUTRAL_PULSELENGTH - SERVOLIMIT) |
Line 28... | Line 28... | ||
28 | #define MAX_PULSELENGTH (NEUTRAL_PULSELENGTH + SERVOLIMIT) |
28 | #define MAX_PULSELENGTH (NEUTRAL_PULSELENGTH + SERVOLIMIT) |
29 | 29 | ||
Line 30... | Line -... | ||
30 | volatile uint8_t recalculateServoTimes = 0; |
- | |
31 | volatile uint16_t servoValues[MAX_SERVOS]; |
- | |
32 | volatile uint16_t previousManualValues[2]; |
- | |
33 | 30 | volatile uint8_t recalculateServoTimes = 0; |
|
34 | #define HEF4017R_ON PORTC |= (1<<PORTC6) |
31 | volatile uint16_t servoValues[MAX_SERVOS]; |
35 | #define HEF4017R_OFF PORTC &= ~(1<<PORTC6) |
32 | volatile uint16_t previousManualValues[2]; |
36 | 33 | ||
37 | //#define HEF4017R_ON ; |
34 | #define HEF4017R_ON PORTC |= (1<<PORTC6) |
Line 169... | Line 166... | ||
169 | // There are more signals to output. |
166 | // There are more signals to output. |
170 | sumOfPulseTimes += (remainingPulseTime = servoValues[servoIndex]); |
167 | sumOfPulseTimes += (remainingPulseTime = servoValues[servoIndex]); |
171 | servoIndex++; |
168 | servoIndex++; |
172 | } else { |
169 | } else { |
173 | // There are no more signals. Reset the counter and make this pulse cover the missing frame time. |
170 | // There are no more signals. Reset the counter and make this pulse cover the missing frame time. |
174 | remainingPulseTime = FRAMELEN - sumOfPulseTimes; |
171 | remainingPulseTime = FRAMELENGTH - sumOfPulseTimes; |
175 | sumOfPulseTimes = servoIndex = 0; |
172 | sumOfPulseTimes = servoIndex = 0; |
176 | recalculateServoTimes = 1; |
173 | recalculateServoTimes = 1; |
177 | HEF4017R_ON; |
174 | HEF4017R_ON; |
178 | } |
175 | } |
179 | } |
176 | } |