Rev 1812 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1813 | - | 1 | /****************************************************************************************************************** |
2 | V0.82b-Arthur-P 2010-12-18 |
||
3 | ------------------------------------------------------------------------------------------------------------------ |
||
4 | Version includes only support for external HEF4017 for FC1.x hardware, NOT for Twi2Ppm converters for ESCs. |
||
5 | |||
6 | 2010-12-18 Transferred changes to v.0.82b-Arthur-P |
||
7 | 20100917: Transferred changes to v0.80g-Arthur-P. |
||
8 | Arthur P. Modified to use several parameters for servo control: |
||
9 | User_Parameter4: |
||
10 | User_Parameter5: |
||
11 | User_Parameter6: |
||
12 | User_Parameter7: |
||
13 | User_Parameter8: Use external HEF4017 if bit 8 is set (>127). The remaining 7 bits are used |
||
14 | for the shutter cycle counter: the value is multiplied by 5 programmatically, |
||
15 | resulting in steps of approx. 0.1sec. Minimum value to start using the |
||
16 | interval timer is 10 (approx. 1 sec, or countervalue of 50). Note that this |
||
17 | was originally done through user para 6. |
||
18 | ******************************************************************************************************************/ |
||
1 | ingob | 19 | #include "main.h" |
1760 | holgerb | 20 | #define MULTIPLYER 4 |
1 | ingob | 21 | |
22 | volatile unsigned int CountMilliseconds = 0; |
||
23 | volatile static unsigned int tim_main; |
||
24 | volatile unsigned char UpdateMotor = 0; |
||
25 | volatile unsigned int cntKompass = 0; |
||
26 | volatile unsigned int beeptime = 0; |
||
1760 | holgerb | 27 | volatile unsigned char SendSPI = 0, ServoActive = 0, CalculateServoSignals = 1; |
28 | uint16_t RemainingPulse = 0; |
||
29 | volatile int16_t ServoNickOffset = (255 / 2) * MULTIPLYER * 16; // initial value near center positon |
||
30 | volatile int16_t ServoRollOffset = (255 / 2) * MULTIPLYER * 16; // initial value near center positon |
||
723 | hbuss | 31 | |
173 | holgerb | 32 | unsigned int BeepMuster = 0xffff; |
1 | ingob | 33 | |
1156 | hbuss | 34 | volatile int16_t ServoNickValue = 0; |
35 | volatile int16_t ServoRollValue = 0; |
||
36 | |||
1813 | - | 37 | /****************************************************************************************************************** |
38 | Arthur P: Added two variables for control of the shutter servo cycle. |
||
39 | 091114 Inserted same changes into v.0.76g code. |
||
40 | 091114 Inactivated the following two lines as the shutter interval funtion is not |
||
41 | used at the moment. |
||
42 | 20100804 Reactivated to be able to choose slower shutter rate than normal for |
||
43 | Panasonic FX150 in continuous mode. |
||
44 | ******************************************************************************************************************/ |
||
1156 | hbuss | 45 | |
1813 | - | 46 | volatile static unsigned int CameraShutterCycleCounter = 0; |
47 | volatile static unsigned int CameraShutterCycle = 0; |
||
48 | volatile static unsigned int CameraShutterCycleOnCount = 20; // Leave the shutter on for at least |
||
49 | // 20 cycles or approx. 0.2 seconds. |
||
50 | /****************************************************************************************************************** |
||
51 | Arthur P: End of changes to variables section of timer0.c. |
||
52 | ******************************************************************************************************************/ |
||
53 | |||
54 | |||
1 | ingob | 55 | enum { |
56 | STOP = 0, |
||
57 | CK = 1, |
||
58 | CK8 = 2, |
||
59 | CK64 = 3, |
||
60 | CK256 = 4, |
||
61 | CK1024 = 5, |
||
62 | T0_FALLING_EDGE = 6, |
||
63 | T0_RISING_EDGE = 7 |
||
64 | }; |
||
65 | |||
66 | |||
1561 | killagreg | 67 | ISR(TIMER0_OVF_vect) // 9,7kHz |
1 | ingob | 68 | { |
1643 | holgerb | 69 | static unsigned char cnt_1ms = 1,cnt = 0, compass_active = 0; |
70 | unsigned char pieper_ein = 0; |
||
723 | hbuss | 71 | if(SendSPI) SendSPI--; |
1469 | killagreg | 72 | if(SpektrumTimer) SpektrumTimer--; |
1 | ingob | 73 | if(!cnt--) |
74 | { |
||
1105 | killagreg | 75 | cnt = 9; |
1643 | holgerb | 76 | CountMilliseconds++; |
1 | ingob | 77 | cnt_1ms++; |
78 | cnt_1ms %= 2; |
||
1643 | holgerb | 79 | |
1 | ingob | 80 | if(!cnt_1ms) UpdateMotor = 1; |
1713 | holgerb | 81 | if(!(PINC & 0x10)) compass_active = 1; |
1643 | holgerb | 82 | |
1664 | holgerb | 83 | if(beeptime) |
1 | ingob | 84 | { |
1664 | holgerb | 85 | if(beeptime > 10) beeptime -= 10; else beeptime = 0; |
1105 | killagreg | 86 | if(beeptime & BeepMuster) |
173 | holgerb | 87 | { |
88 | pieper_ein = 1; |
||
89 | } |
||
90 | else pieper_ein = 0; |
||
1 | ingob | 91 | } |
1105 | killagreg | 92 | else |
1651 | killagreg | 93 | { |
173 | holgerb | 94 | pieper_ein = 0; |
95 | BeepMuster = 0xffff; |
||
1105 | killagreg | 96 | } |
173 | holgerb | 97 | if(pieper_ein) |
98 | { |
||
99 | if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker an PORTD.2 |
||
100 | else PORTC |= (1<<7); // Speaker an PORTC.7 |
||
101 | } |
||
1105 | killagreg | 102 | else |
173 | holgerb | 103 | { |
104 | if(PlatinenVersion == 10) PORTD &= ~(1<<2); |
||
105 | else PORTC &= ~(1<<7); |
||
1105 | killagreg | 106 | } |
1643 | holgerb | 107 | } |
108 | if(compass_active && !NaviDataOkay && EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) |
||
1 | ingob | 109 | { |
110 | if(PINC & 0x10) |
||
111 | { |
||
1643 | holgerb | 112 | if(++cntKompass > 1000) compass_active = 0; |
1 | ingob | 113 | } |
114 | else |
||
115 | { |
||
1105 | killagreg | 116 | if((cntKompass) && (cntKompass < 362)) |
117 | { |
||
693 | hbuss | 118 | cntKompass += cntKompass / 41; |
119 | if(cntKompass > 10) KompassValue = cntKompass - 10; else KompassValue = 0; |
||
1469 | killagreg | 120 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
1105 | killagreg | 121 | } |
1 | ingob | 122 | cntKompass = 0; |
1105 | killagreg | 123 | } |
1 | ingob | 124 | } |
125 | } |
||
126 | |||
127 | |||
128 | // ----------------------------------------------------------------------- |
||
129 | unsigned int SetDelay (unsigned int t) |
||
130 | { |
||
131 | // TIMSK0 &= ~_BV(TOIE0); |
||
1105 | killagreg | 132 | return(CountMilliseconds + t + 1); |
1 | ingob | 133 | // TIMSK0 |= _BV(TOIE0); |
134 | } |
||
135 | |||
136 | // ----------------------------------------------------------------------- |
||
137 | char CheckDelay(unsigned int t) |
||
138 | { |
||
139 | // TIMSK0 &= ~_BV(TOIE0); |
||
140 | return(((t - CountMilliseconds) & 0x8000) >> 9); |
||
141 | // TIMSK0 |= _BV(TOIE0); |
||
142 | } |
||
143 | |||
144 | // ----------------------------------------------------------------------- |
||
145 | void Delay_ms(unsigned int w) |
||
146 | { |
||
147 | unsigned int akt; |
||
148 | akt = SetDelay(w); |
||
149 | while (!CheckDelay(akt)); |
||
150 | } |
||
151 | |||
395 | hbuss | 152 | void Delay_ms_Mess(unsigned int w) |
153 | { |
||
154 | unsigned int akt; |
||
155 | akt = SetDelay(w); |
||
1166 | hbuss | 156 | while (!CheckDelay(akt)) if(AdReady) {AdReady = 0; ANALOG_ON;} |
395 | hbuss | 157 | } |
158 | |||
1156 | hbuss | 159 | /*****************************************************/ |
160 | /* Initialize Timer 2 */ |
||
161 | /*****************************************************/ |
||
162 | // The timer 2 is used to generate the PWM at PD7 (J7) |
||
163 | // to control a camera servo for nick compensation. |
||
164 | void TIMER2_Init(void) |
||
910 | hbuss | 165 | { |
1156 | hbuss | 166 | uint8_t sreg = SREG; |
167 | |||
1813 | - | 168 | /****************************************************************************************************************** |
169 | Arthur P: Added initialization of the CameraShutterCycle value here as this routine is only |
||
170 | called once. This retains all code changes in timer0.c. If (parameter 8 & 127) > 0 then the user |
||
171 | has set a value for the cycle. CameraShuytterCycle == 5x (Para8 & 127) to get approx 0.1sec increments. |
||
172 | 090807: Arthur P.: Removed the shutter cycle parts as they may be impacting timing loops. |
||
173 | 20100804 Arthur P.: Reactivate shutter cycle counters. Modified to use the lower 7 bits of |
||
174 | user parameter 8 (bit 8 is used for enabling the external HEF4017). |
||
175 | CameraShutterCycle = Parameter_UserParam6; |
||
176 | ******************************************************************************************************************/ |
||
177 | |||
178 | CameraShutterCycle = 5 * (Parameter_UserParam8 & 127); |
||
179 | |||
180 | /****************************************************************************************************************** |
||
181 | Arthur P: End of changes to Timer2 function. |
||
182 | ******************************************************************************************************************/ |
||
183 | |||
184 | |||
1156 | hbuss | 185 | // disable all interrupts before reconfiguration |
186 | cli(); |
||
1469 | killagreg | 187 | |
1156 | hbuss | 188 | PORTD &= ~(1<<PORTD7); // set PD7 to low |
189 | |||
190 | DDRC |= (1<<DDC6); // set PC6 as output (Reset for HEF4017) |
||
1171 | hbuss | 191 | HEF4017R_ON; |
1156 | hbuss | 192 | // Timer/Counter 2 Control Register A |
193 | |||
194 | // Timer Mode is FastPWM with timer reload at OCR2A (Bits: WGM22 = 1, WGM21 = 1, WGM20 = 1) |
||
195 | // PD7: Normal port operation, OC2A disconnected, (Bits: COM2A1 = 0, COM2A0 = 0) |
||
196 | // PD6: Normal port operation, OC2B disconnected, (Bits: COM2B1 = 0, COM2B0 = 0) |
||
197 | TCCR2A &= ~((1<<COM2A1)|(1<<COM2A0)|(1<<COM2B1)|(1<<COM2B0)); |
||
198 | TCCR2A |= (1<<WGM21)|(1<<WGM20); |
||
199 | |||
200 | // Timer/Counter 2 Control Register B |
||
201 | |||
202 | // Set clock divider for timer 2 to SYSKLOCK/32 = 20MHz / 32 = 625 kHz |
||
203 | // The timer increments from 0x00 to 0xFF with an update rate of 625 kHz or 1.6 us |
||
204 | // hence the timer overflow interrupt frequency is 625 kHz / 256 = 2.44 kHz or 0.4096 ms |
||
205 | |||
206 | // divider 32 (Bits: CS022 = 0, CS21 = 1, CS20 = 1) |
||
207 | TCCR2B &= ~((1<<FOC2A)|(1<<FOC2B)|(1<<CS22)); |
||
208 | TCCR2B |= (1<<CS21)|(1<<CS20)|(1<<WGM22); |
||
209 | |||
210 | // Initialize the Timer/Counter 2 Register |
||
211 | TCNT2 = 0; |
||
212 | |||
213 | // Initialize the Output Compare Register A used for PWM generation on port PD7. |
||
214 | OCR2A = 255; |
||
215 | TCCR2A |= (1<<COM2A1); // set or clear at compare match depends on value of COM2A0 |
||
216 | |||
217 | // Timer/Counter 2 Interrupt Mask Register |
||
218 | // Enable timer output compare match A Interrupt only |
||
219 | TIMSK2 &= ~((1<<OCIE2B)|(1<<TOIE2)); |
||
220 | TIMSK2 |= (1<<OCIE2A); |
||
221 | |||
222 | SREG = sreg; |
||
910 | hbuss | 223 | } |
224 | |||
1156 | hbuss | 225 | //---------------------------- |
226 | void Timer_Init(void) |
||
1 | ingob | 227 | { |
1156 | hbuss | 228 | tim_main = SetDelay(10); |
229 | TCCR0B = CK8; |
||
230 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
||
231 | OCR0A = 0; |
||
1638 | holgerb | 232 | OCR0B = 180; |
1156 | hbuss | 233 | TCNT0 = (unsigned char)-TIMER_RELOAD_VALUE; // reload |
234 | //OCR1 = 0x00; |
||
235 | TIMSK0 |= _BV(TOIE0); |
||
236 | } |
||
237 | |||
238 | |||
239 | /*****************************************************/ |
||
240 | /* Control Servo Position */ |
||
241 | /*****************************************************/ |
||
242 | |||
1760 | holgerb | 243 | |
244 | void CalculateServo(void) |
||
245 | { |
||
1771 | holgerb | 246 | signed char cosinus, sinus; |
247 | signed long nick, roll; |
||
1760 | holgerb | 248 | |
249 | cosinus = sintab[EE_Parameter.CamOrientation + 6]; |
||
250 | sinus = sintab[EE_Parameter.CamOrientation]; |
||
251 | |||
252 | if(CalculateServoSignals == 1) |
||
253 | { |
||
1763 | killagreg | 254 | nick = (cosinus * IntegralNick) / 128L - (sinus * IntegralRoll) / 128L; |
255 | nick = ((long)EE_Parameter.ServoNickComp * nick) / 512L; |
||
256 | ServoNickOffset += ((int16_t)Parameter_ServoNickControl * (MULTIPLYER*16) - ServoNickOffset) / EE_Parameter.ServoManualControlSpeed; |
||
257 | ServoNickValue = ServoNickOffset / 16; // offset (Range from 0 to 255 * 3 = 765) |
||
258 | if(EE_Parameter.ServoCompInvert & 0x01) |
||
259 | { // inverting movement of servo |
||
260 | ServoNickValue += nick;//(int16_t)( ( (int32_t)EE_Parameter.ServoNickComp * nick) / (256L) ); |
||
261 | } |
||
262 | else |
||
263 | { // non inverting movement of servo |
||
264 | ServoNickValue -= nick; |
||
265 | } |
||
266 | // limit servo value to its parameter range definition |
||
267 | if(ServoNickValue < ((int16_t)EE_Parameter.ServoNickMin * MULTIPLYER) ) |
||
268 | { |
||
269 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMin * MULTIPLYER; |
||
270 | } |
||
271 | else |
||
272 | if(ServoNickValue > ((int16_t)EE_Parameter.ServoNickMax * MULTIPLYER) ) |
||
273 | { |
||
274 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMax * MULTIPLYER; |
||
275 | } |
||
276 | if(PlatinenVersion < 20) CalculateServoSignals = 0; else CalculateServoSignals++; |
||
1760 | holgerb | 277 | } |
278 | else |
||
279 | { |
||
1763 | killagreg | 280 | roll = (cosinus * IntegralRoll) / 128L + (sinus * IntegralNick) / 128L; |
281 | roll = ((long)EE_Parameter.ServoRollComp * roll) / 512L; |
||
282 | ServoRollOffset += ((int16_t)Parameter_ServoRollControl * (MULTIPLYER*16) - ServoRollOffset) / EE_Parameter.ServoManualControlSpeed; |
||
283 | ServoRollValue = ServoRollOffset/16; // offset (Range from 0 to 255 * 3 = 765) |
||
284 | if(EE_Parameter.ServoCompInvert & 0x02) |
||
285 | { // inverting movement of servo |
||
286 | ServoRollValue += roll; |
||
287 | } |
||
288 | else |
||
289 | { // non inverting movement of servo |
||
290 | ServoRollValue -= roll; |
||
291 | } |
||
292 | // limit servo value to its parameter range definition |
||
293 | if(ServoRollValue < ((int16_t)EE_Parameter.ServoRollMin * MULTIPLYER) ) |
||
294 | { |
||
295 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMin * MULTIPLYER; |
||
296 | } |
||
297 | else |
||
298 | if(ServoRollValue > ((int16_t)EE_Parameter.ServoRollMax * MULTIPLYER) ) |
||
299 | { |
||
300 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMax * MULTIPLYER; |
||
301 | } |
||
302 | CalculateServoSignals = 0; |
||
1760 | holgerb | 303 | } |
304 | } |
||
305 | |||
1156 | hbuss | 306 | ISR(TIMER2_COMPA_vect) |
307 | { |
||
308 | // frame len 22.5 ms = 14063 * 1.6 us |
||
309 | // stop pulse: 0.3 ms = 188 * 1.6 us |
||
310 | // min servo pulse: 0.6 ms = 375 * 1.6 us |
||
311 | // max servo pulse: 2.4 ms = 1500 * 1.6 us |
||
312 | // resolution: 1500 - 375 = 1125 steps |
||
313 | |||
314 | #define IRS_RUNTIME 127 |
||
315 | #define PPM_STOPPULSE 188 |
||
1171 | hbuss | 316 | #define PPM_FRAMELEN (1757 * EE_Parameter.ServoNickRefresh) |
1156 | hbuss | 317 | #define MINSERVOPULSE 375 |
318 | #define MAXSERVOPULSE 1500 |
||
319 | #define SERVORANGE (MAXSERVOPULSE - MINSERVOPULSE) |
||
320 | |||
321 | static uint8_t PulseOutput = 0; |
||
322 | static uint16_t ServoFrameTime = 0; |
||
323 | static uint8_t ServoIndex = 0; |
||
324 | |||
325 | |||
1813 | - | 326 | /****************************************************************************************************************** |
327 | Arthur P: Modified the code to check the value of parameter 8. If 128 or higher then a HEF4017 is |
||
328 | expected and will be used. Else J7 and J9 are seen as separate normal outputs. |
||
329 | if((PlatinenVersion < 20) |
||
330 | 091114. Inserted same changes into v.0.76g code. |
||
331 | 20100802 Inserted same changes into v.0.80d code. |
||
332 | ******************************************************************************************************************/ |
||
333 | |||
334 | // if(PlatinenVersion < 20) |
||
335 | |||
336 | if((PlatinenVersion < 20) && (Parameter_UserParam8 < 128 )) |
||
337 | /****************************************************************************************************************** |
||
338 | Arthur P: End of modification ot if statement. |
||
339 | ******************************************************************************************************************/ |
||
340 | |||
1156 | hbuss | 341 | { |
342 | //--------------------------- |
||
343 | // Nick servo state machine |
||
344 | //--------------------------- |
||
345 | if(!PulseOutput) // pulse output complete |
||
346 | { |
||
347 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
||
348 | { |
||
349 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
||
350 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
||
351 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
||
352 | // range servo pulse width |
||
353 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
||
354 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
||
355 | // accumulate time for correct update rate |
||
356 | ServoFrameTime = RemainingPulse; |
||
357 | } |
||
358 | else // we had a high pulse |
||
359 | { |
||
360 | TCCR2A |= (1<<COM2A0); // make a low pulse |
||
361 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; |
||
1763 | killagreg | 362 | CalculateServoSignals = 1; |
1156 | hbuss | 363 | } |
364 | // set pulse output active |
||
365 | PulseOutput = 1; |
||
366 | } |
||
367 | } // EOF Nick servo state machine |
||
368 | else |
||
369 | { |
||
370 | //----------------------------------------------------- |
||
371 | // PPM state machine, onboard demultiplexed by HEF4017 |
||
372 | //----------------------------------------------------- |
||
373 | if(!PulseOutput) // pulse output complete |
||
374 | { |
||
375 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
||
376 | { |
||
377 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
||
378 | |||
379 | if(ServoIndex == 0) // if we are at the sync gap |
||
380 | { |
||
381 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; // generate sync gap by filling time to full frame time |
||
382 | ServoFrameTime = 0; // reset servo frame time |
||
383 | HEF4017R_ON; // enable HEF4017 reset |
||
384 | } |
||
385 | else // servo channels |
||
386 | { |
||
387 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
||
388 | switch(ServoIndex) // map servo channels |
||
389 | { |
||
390 | case 1: // Nick Compensation Servo |
||
391 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
||
392 | break; |
||
1224 | hbuss | 393 | case 2: // Roll Compensation Servo |
394 | RemainingPulse += ServoRollValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
||
1232 | hbuss | 395 | break; |
1813 | - | 396 | /****************************************************************************************************************** |
397 | Arthur P: Shutter Servo including interval control over parameter 5 and 6. |
||
398 | 091114 Inserted same modification into v.0.76g code, removing previously REM-ed out modified parts. |
||
399 | 20100802 Inserted same modification into v.0.76g code, removing previously REM-ed out modified parts. |
||
400 | Modified to use lower 7 bits of user parameter 7. |
||
401 | ******************************************************************************************************************/ |
||
1565 | killagreg | 402 | case 3: |
1813 | - | 403 | // RemainingPulse += ((int16_t)Parameter_Servo3 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
404 | // break; |
||
405 | |||
406 | |||
407 | if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] < -32) |
||
408 | { |
||
409 | // Set servo to null position, turning camera off. |
||
410 | RemainingPulse = MINSERVOPULSE; |
||
411 | } |
||
412 | else |
||
413 | { |
||
414 | // 090807: Arthur P.: Removed the shutter cycle parts as they may be impacting timing loops. |
||
415 | // 20100804 Reactived shutter interval timer capability. |
||
416 | if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] > 32) |
||
417 | // Top position on a 3 position switch which runs from -127 to +127 |
||
418 | { |
||
419 | |||
420 | RemainingPulse = MINSERVOPULSE + SERVORANGE; |
||
421 | } |
||
422 | else |
||
423 | { |
||
424 | // Cycle shutter servo between 50% on and off depending upon CameraShutterCycleCounter |
||
425 | // If CameraShutterCylce < 50 then default to continuous shoot. |
||
426 | if(CameraShutterCycle < 50 ) // == 5x the minimum value of userpara8 lower 7 bits |
||
427 | { |
||
428 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; |
||
429 | } |
||
430 | else |
||
431 | { |
||
432 | if(CameraShutterCycleCounter == CameraShutterCycle) |
||
433 | { |
||
434 | // Shutter on |
||
435 | CameraShutterCycleCounter = 0; |
||
436 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; |
||
437 | } |
||
438 | else |
||
439 | { |
||
440 | // Leave on for at least 20 cycles or 0.2 seconds to allow |
||
441 | // the camera to properly trigger, turn off if past 0.2 sec. |
||
442 | // For now this is actually set via para5 to allow for a long enough |
||
443 | // shutter pulse for different cameras. Once it is clear what value |
||
444 | // works, this can be changed to a hardcoded value. |
||
445 | CameraShutterCycleCounter++; |
||
446 | if(CameraShutterCycleCounter == CameraShutterCycleOnCount) |
||
447 | { |
||
448 | // Shutter off |
||
449 | RemainingPulse = MINSERVOPULSE; |
||
450 | } |
||
451 | } |
||
452 | } |
||
453 | } |
||
454 | } |
||
1403 | hbuss | 455 | break; |
1813 | - | 456 | /****************************************************************************************************************** |
457 | Arthur P: End of modified shutter servo control (via HEF4017) and of modifications to timer0.c. |
||
458 | ******************************************************************************************************************/ |
||
459 | |||
1543 | killagreg | 460 | case 4: |
1565 | killagreg | 461 | RemainingPulse += ((int16_t)Parameter_Servo4 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
1403 | hbuss | 462 | break; |
1543 | killagreg | 463 | case 5: |
1565 | killagreg | 464 | RemainingPulse += ((int16_t)Parameter_Servo5 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
1403 | hbuss | 465 | break; |
1156 | hbuss | 466 | default: // other servo channels |
467 | RemainingPulse += 2 * PPM_in[ServoIndex]; // add channel value, factor of 2 because timer 1 increments 3.2µs |
||
468 | break; |
||
469 | } |
||
470 | // range servo pulse width |
||
471 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
||
472 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
||
473 | // substract stop pulse width |
||
474 | RemainingPulse -= PPM_STOPPULSE; |
||
475 | // accumulate time for correct sync gap |
||
476 | ServoFrameTime += RemainingPulse; |
||
477 | } |
||
478 | } |
||
479 | else // we had a high pulse |
||
480 | { |
||
481 | TCCR2A |= (1<<COM2A0); // make a low pulse |
||
482 | // set pulsewidth to stop pulse width |
||
483 | RemainingPulse = PPM_STOPPULSE; |
||
484 | // accumulate time for correct sync gap |
||
485 | ServoFrameTime += RemainingPulse; |
||
1771 | holgerb | 486 | if((ServoActive && SenderOkay > 50) || ServoActive == 2) HEF4017R_OFF; // disable HEF4017 reset |
1232 | hbuss | 487 | else HEF4017R_ON; |
1156 | hbuss | 488 | ServoIndex++; // change to next servo channel |
1763 | killagreg | 489 | if(ServoIndex > EE_Parameter.ServoNickRefresh) |
490 | { |
||
491 | CalculateServoSignals = 1; |
||
1760 | holgerb | 492 | ServoIndex = 0; // reset to the sync gap |
493 | } |
||
1156 | hbuss | 494 | } |
495 | // set pulse output active |
||
496 | PulseOutput = 1; |
||
497 | } |
||
498 | } // EOF PPM state machine |
||
499 | |||
500 | // General pulse output generator |
||
501 | if(RemainingPulse > (255 + IRS_RUNTIME)) |
||
502 | { |
||
503 | OCR2A = 255; |
||
504 | RemainingPulse -= 255; |
||
910 | hbuss | 505 | } |
1156 | hbuss | 506 | else |
507 | { |
||
508 | if(RemainingPulse > 255) // this is the 2nd last part |
||
509 | { |
||
510 | if((RemainingPulse - 255) < IRS_RUNTIME) |
||
511 | { |
||
512 | OCR2A = 255 - IRS_RUNTIME; |
||
513 | RemainingPulse -= 255 - IRS_RUNTIME; |
||
514 | |||
515 | } |
||
516 | else // last part > ISR_RUNTIME |
||
517 | { |
||
518 | OCR2A = 255; |
||
519 | RemainingPulse -= 255; |
||
520 | } |
||
521 | } |
||
522 | else // this is the last part |
||
523 | { |
||
524 | OCR2A = RemainingPulse; |
||
525 | RemainingPulse = 0; |
||
526 | PulseOutput = 0; // trigger to stop pulse |
||
527 | } |
||
528 | } // EOF general pulse output generator |
||
1111 | hbuss | 529 | } |