Rev 1229 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1229 | Rev 1242 | ||
---|---|---|---|
Line 11... | Line 11... | ||
11 | int ServoValue = 0; |
11 | int ServoValue = 0; |
Line 12... | Line 12... | ||
12 | 12 | ||
13 | volatile int16_t ServoNickValue = 0; |
13 | volatile int16_t ServoNickValue = 0; |
Line -... | Line 14... | ||
- | 14 | volatile int16_t ServoRollValue = 0; |
|
- | 15 | ||
- | 16 | // Arthur P: Added two variables for control of the shutter servo cycle. |
|
- | 17 | ||
- | 18 | volatile static unsigned int CameraShutterCycleCounter = 0; |
|
Line 14... | Line 19... | ||
14 | volatile int16_t ServoRollValue = 0; |
19 | volatile static unsigned int CameraShutterCycle = 0; |
15 | 20 | ||
16 | 21 | ||
17 | enum { |
22 | enum { |
Line 127... | Line 132... | ||
127 | /*****************************************************/ |
132 | /*****************************************************/ |
128 | // The timer 2 is used to generate the PWM at PD7 (J7) |
133 | // The timer 2 is used to generate the PWM at PD7 (J7) |
129 | // to control a camera servo for nick compensation. |
134 | // to control a camera servo for nick compensation. |
130 | void TIMER2_Init(void) |
135 | void TIMER2_Init(void) |
131 | { |
136 | { |
- | 137 | ||
132 | uint8_t sreg = SREG; |
138 | uint8_t sreg = SREG; |
Line 133... | Line 139... | ||
133 | 139 | ||
134 | // disable all interrupts before reconfiguration |
140 | // disable all interrupts before reconfiguration |
Line 174... | Line 180... | ||
174 | } |
180 | } |
Line 175... | Line 181... | ||
175 | 181 | ||
176 | //---------------------------- |
182 | //---------------------------- |
177 | void Timer_Init(void) |
183 | void Timer_Init(void) |
- | 184 | { |
|
178 | { |
185 | |
179 | tim_main = SetDelay(10); |
186 | tim_main = SetDelay(10); |
180 | TCCR0B = CK8; |
187 | TCCR0B = CK8; |
181 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
188 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
182 | OCR0A = 0; |
189 | OCR0A = 0; |
Line 216... | Line 223... | ||
216 | 223 | ||
217 | #define MULTIPLYER 4 |
224 | #define MULTIPLYER 4 |
218 | static int16_t ServoNickOffset = (255 / 2) * MULTIPLYER; // initial value near center positon |
225 | static int16_t ServoNickOffset = (255 / 2) * MULTIPLYER; // initial value near center positon |
Line -... | Line 226... | ||
- | 226 | static int16_t ServoRollOffset = (255 / 2) * MULTIPLYER; // initial value near center positon |
|
- | 227 | ||
- | 228 | // Arthur P: Added initialization of the CameraShutterCycle value here as this routine is only |
|
- | 229 | // called once. This retains all code changes in timer0.c. If parameter 6 > 0 then the user |
|
- | 230 | // has set a value for the cycle. CameraShuytterCycle == 5x Para6 to get approx 0.1sec increments. |
|
- | 231 | ||
- | 232 | // CameraShutterCycle = 5 * Parameter_UserParam6; |
|
- | 233 | CameraShutterCycle = Parameter_UserParam6; |
|
- | 234 | ||
219 | static int16_t ServoRollOffset = (255 / 2) * MULTIPLYER; // initial value near center positon |
235 | // Arthur P: Modified the code to scheck the value of parameter 8. If 128 or higher then a HEF4017 is |
- | 236 | // expected and will be used. Else J7 and J9 are seen as separate normal outputs. |
|
220 | 237 | // if((PlatinenVersion < 20) |
|
221 | // if((PlatinenVersion < 20) |
238 | |
222 | if((PlatinenVersion < 20) && (Parameter_UserParam8 < 128 )) |
239 | if((PlatinenVersion < 20) && (Parameter_UserParam8 < 128 )) |
223 | { |
240 | { |
224 | //--------------------------- |
241 | //--------------------------- |
Line 318... | Line 335... | ||
318 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
335 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
319 | ServoNickValue /= MULTIPLYER; |
336 | ServoNickValue /= MULTIPLYER; |
320 | DebugOut.Analog[20] = ServoNickValue; |
337 | DebugOut.Analog[20] = ServoNickValue; |
321 | break; |
338 | break; |
322 | case 2: // Roll Compensation Servo |
339 | case 2: // Roll Compensation Servo |
- | 340 | // Arthur P: Modified the code here to allow the user to either continue with the default |
|
- | 341 | // offset value of 80, or set a different offset using parameter 7. I.e. if |
|
- | 342 | // parameter 7 == 0 then the default is used, but if a value > 0 is entered then |
|
- | 343 | // that value is used. |
|
- | 344 | if(Parameter_UserParam7==0) |
|
- | 345 | { |
|
323 | ServoRollOffset = (ServoRollOffset * 3 + (int16_t) 80 * MULTIPLYER) / 4; // lowpass offset |
346 | ServoRollOffset = (ServoRollOffset * 3 + (int16_t) 80 * MULTIPLYER) / 4; // lowpass offset |
- | 347 | } |
|
- | 348 | else |
|
- | 349 | { |
|
- | 350 | ServoRollOffset = (ServoRollOffset * 3 + (int16_t) Parameter_UserParam7 * MULTIPLYER) / 4; |
|
- | 351 | } |
|
324 | ServoRollValue = ServoRollOffset; // offset (Range from 0 to 255 * 3 = 765) |
352 | ServoRollValue = ServoRollOffset; // offset (Range from 0 to 255 * 3 = 765) |
325 | //if(EE_Parameter.ServoRollCompInvert & 0x01) |
353 | //if(EE_Parameter.ServoRollCompInvert & 0x01) |
326 | if(Parameter_UserParam8 & 0x40) |
354 | if(Parameter_UserParam8 & 0x40) |
327 | { // inverting movement of servo if 64 has been added to User Parameter8 |
355 | { // Arthur P: Inverting movement of servo if 64 has been added to User Parameter8 |
328 | ServoRollValue += (int16_t)( ( (int32_t) 50 * MULTIPLYER * (IntegralRoll / 128L ) ) / (256L) ); |
356 | ServoRollValue += (int16_t)( ( (int32_t) 50 * MULTIPLYER * (IntegralRoll / 128L ) ) / (256L) ); |
329 | } |
357 | } |
330 | /**/ else |
358 | /**/ else |
331 | { // non inverting movement of servo |
359 | { // non inverting movement of servo |
332 | ServoRollValue -= (int16_t)( ( (int32_t) 40 * MULTIPLYER * (IntegralRoll / 128L ) ) / (256L) ); |
360 | ServoRollValue -= (int16_t)( ( (int32_t) 40 * MULTIPLYER * (IntegralRoll / 128L ) ) / (256L) ); |
Line 367... | Line 395... | ||
367 | } |
395 | } |
368 | RemainingPulse += ServoRollValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
396 | RemainingPulse += ServoRollValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
369 | ServoRollValue /= MULTIPLYER; |
397 | ServoRollValue /= MULTIPLYER; |
370 | //DebugOut.Analog[20] = ServoRollValue; |
398 | //DebugOut.Analog[20] = ServoRollValue; |
371 | */ break; |
399 | */ break; |
- | 400 | case 3: // Arthur P: Shutter Servo including interval control over parameter 5 and 6. |
|
Line -... | Line 401... | ||
- | 401 | ||
- | 402 | ||
- | 403 | if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] < -32) |
|
- | 404 | { |
|
- | 405 | // Set servo to null position, turning camera off. |
|
- | 406 | RemainingPulse = MINSERVOPULSE; |
|
- | 407 | } |
|
- | 408 | else |
|
- | 409 | { |
|
- | 410 | if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] > 32) |
|
- | 411 | // Middle position on a 3 position switch which runs from -127 to +127 |
|
- | 412 | { |
|
- | 413 | ||
- | 414 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; |
|
- | 415 | } |
|
- | 416 | else |
|
- | 417 | { |
|
- | 418 | // Cycle shutter servo between on and off depending upon CameraShutterCycleCounter |
|
- | 419 | // If CameraShutterCylce < 50 then default to continuous shoot. |
|
- | 420 | if(CameraShutterCycle < 50 ) |
|
- | 421 | { |
|
- | 422 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; |
|
- | 423 | } |
|
- | 424 | else |
|
- | 425 | { |
|
- | 426 | if(CameraShutterCycleCounter == CameraShutterCycle) |
|
- | 427 | { |
|
- | 428 | // Shutter on |
|
- | 429 | CameraShutterCycleCounter = 0; |
|
- | 430 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; |
|
- | 431 | } |
|
- | 432 | else |
|
- | 433 | { |
|
- | 434 | // Leave on for at least 24 cycles or 0.25 seconds to allow |
|
- | 435 | // the camera to properly trigger, turn off if past 0.25 sec. |
|
- | 436 | // For now this is actually set via para5 to allow for a long enough |
|
- | 437 | // shutter pulse for different cameras. Once it is clear what value |
|
- | 438 | // works, this can be changed to a hardcoded value. |
|
- | 439 | if(CameraShutterCycleCounter>Parameter_UserParam5) |
|
- | 440 | { |
|
- | 441 | ||
- | 442 | RemainingPulse = MINSERVOPULSE; |
|
- | 443 | } |
|
- | 444 | CameraShutterCycleCounter++; |
|
- | 445 | } |
|
- | 446 | } |
|
- | 447 | } |
|
- | 448 | } |
|
- | 449 | break; |
|
372 | 450 | ||
373 | default: // other servo channels |
451 | default: // other servo channels |
374 | RemainingPulse += 2 * PPM_in[ServoIndex]; // add channel value, factor of 2 because timer 1 increments 3.2µs |
452 | RemainingPulse += 2 * PPM_in[ServoIndex]; // add channel value, factor of 2 because timer 1 increments 3.2µs |
375 | break; |
453 | break; |
376 | } |
454 | } |
377 | // range servo pulse width |
455 | // range servo pulse width |
378 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
456 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
379 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
457 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
- | 458 | // substract stop pulse width |
|
- | 459 | // Arthur P: I think the following line, correcting for the PPM sTOPPULSE does not apply for the |
|
- | 460 | // calculated pulses, or maybe not at all. Therefore I-m commenting it out to see what happens.... |
|
380 | // substract stop pulse width |
461 | // 090624 reactivated as rollservo correction can now be done over para7. |
381 | RemainingPulse -= PPM_STOPPULSE; |
462 | RemainingPulse -= PPM_STOPPULSE; |
382 | // accumulate time for correct sync gap |
463 | // accumulate time for correct sync gap |
383 | ServoFrameTime += RemainingPulse; |
464 | ServoFrameTime += RemainingPulse; |
384 | } |
465 | } |