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