Rev 1242 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | #include "main.h" |
2 | |||
3 | volatile unsigned int CountMilliseconds = 0; |
||
4 | volatile static unsigned int tim_main; |
||
5 | volatile unsigned char UpdateMotor = 0; |
||
6 | volatile unsigned int cntKompass = 0; |
||
7 | volatile unsigned int beeptime = 0; |
||
1171 | hbuss | 8 | volatile unsigned char SendSPI = 0, ServoActive = 0; |
723 | hbuss | 9 | |
173 | holgerb | 10 | unsigned int BeepMuster = 0xffff; |
1105 | killagreg | 11 | int ServoValue = 0; |
1 | ingob | 12 | |
1156 | hbuss | 13 | volatile int16_t ServoNickValue = 0; |
14 | volatile int16_t ServoRollValue = 0; |
||
15 | |||
1242 | Arthur | 16 | // Arthur P: Added two variables for control of the shutter servo cycle. |
1156 | hbuss | 17 | |
1242 | Arthur | 18 | volatile static unsigned int CameraShutterCycleCounter = 0; |
19 | volatile static unsigned int CameraShutterCycle = 0; |
||
20 | |||
21 | |||
1 | ingob | 22 | enum { |
23 | STOP = 0, |
||
24 | CK = 1, |
||
25 | CK8 = 2, |
||
26 | CK64 = 3, |
||
27 | CK256 = 4, |
||
28 | CK1024 = 5, |
||
29 | T0_FALLING_EDGE = 6, |
||
30 | T0_RISING_EDGE = 7 |
||
31 | }; |
||
32 | |||
33 | |||
34 | SIGNAL (SIG_OVERFLOW0) // 8kHz |
||
35 | { |
||
36 | static unsigned char cnt_1ms = 1,cnt = 0; |
||
173 | holgerb | 37 | unsigned char pieper_ein = 0; |
1 | ingob | 38 | // TCNT0 -= 250;//TIMER_RELOAD_VALUE; |
723 | hbuss | 39 | if(SendSPI) SendSPI--; |
1 | ingob | 40 | if(!cnt--) |
41 | { |
||
1105 | killagreg | 42 | cnt = 9; |
1 | ingob | 43 | cnt_1ms++; |
44 | cnt_1ms %= 2; |
||
45 | if(!cnt_1ms) UpdateMotor = 1; |
||
46 | CountMilliseconds++; |
||
1105 | killagreg | 47 | } |
1 | ingob | 48 | |
49 | if(beeptime > 1) |
||
50 | { |
||
1105 | killagreg | 51 | beeptime--; |
52 | if(beeptime & BeepMuster) |
||
173 | holgerb | 53 | { |
54 | pieper_ein = 1; |
||
55 | } |
||
56 | else pieper_ein = 0; |
||
1 | ingob | 57 | } |
1105 | killagreg | 58 | else |
173 | holgerb | 59 | { |
60 | pieper_ein = 0; |
||
61 | BeepMuster = 0xffff; |
||
1105 | killagreg | 62 | } |
173 | holgerb | 63 | |
64 | |||
65 | if(pieper_ein) |
||
66 | { |
||
67 | if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker an PORTD.2 |
||
68 | else PORTC |= (1<<7); // Speaker an PORTC.7 |
||
69 | } |
||
1105 | killagreg | 70 | else |
173 | holgerb | 71 | { |
72 | if(PlatinenVersion == 10) PORTD &= ~(1<<2); |
||
73 | else PORTC &= ~(1<<7); |
||
1105 | killagreg | 74 | } |
75 | |||
1 | ingob | 76 | if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) |
77 | { |
||
78 | if(PINC & 0x10) |
||
79 | { |
||
1105 | killagreg | 80 | cntKompass++; |
1 | ingob | 81 | } |
82 | else |
||
83 | { |
||
1105 | killagreg | 84 | if((cntKompass) && (cntKompass < 362)) |
85 | { |
||
693 | hbuss | 86 | cntKompass += cntKompass / 41; |
87 | if(cntKompass > 10) KompassValue = cntKompass - 10; else KompassValue = 0; |
||
1105 | killagreg | 88 | } |
1 | ingob | 89 | // if(cntKompass < 10) cntKompass = 10; |
90 | // KompassValue = (unsigned long)((unsigned long)(cntKompass-10)*720L + 1L) / 703L; |
||
91 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
||
92 | cntKompass = 0; |
||
1105 | killagreg | 93 | } |
1 | ingob | 94 | } |
95 | } |
||
96 | |||
97 | |||
98 | // ----------------------------------------------------------------------- |
||
99 | |||
100 | unsigned int SetDelay (unsigned int t) |
||
101 | { |
||
102 | // TIMSK0 &= ~_BV(TOIE0); |
||
1105 | killagreg | 103 | return(CountMilliseconds + t + 1); |
1 | ingob | 104 | // TIMSK0 |= _BV(TOIE0); |
105 | } |
||
106 | |||
107 | // ----------------------------------------------------------------------- |
||
108 | char CheckDelay(unsigned int t) |
||
109 | { |
||
110 | // TIMSK0 &= ~_BV(TOIE0); |
||
111 | return(((t - CountMilliseconds) & 0x8000) >> 9); |
||
112 | // TIMSK0 |= _BV(TOIE0); |
||
113 | } |
||
114 | |||
115 | // ----------------------------------------------------------------------- |
||
116 | void Delay_ms(unsigned int w) |
||
117 | { |
||
118 | unsigned int akt; |
||
119 | akt = SetDelay(w); |
||
120 | while (!CheckDelay(akt)); |
||
121 | } |
||
122 | |||
395 | hbuss | 123 | void Delay_ms_Mess(unsigned int w) |
124 | { |
||
125 | unsigned int akt; |
||
126 | akt = SetDelay(w); |
||
1166 | hbuss | 127 | while (!CheckDelay(akt)) if(AdReady) {AdReady = 0; ANALOG_ON;} |
395 | hbuss | 128 | } |
129 | |||
1156 | hbuss | 130 | /*****************************************************/ |
131 | /* Initialize Timer 2 */ |
||
132 | /*****************************************************/ |
||
133 | // The timer 2 is used to generate the PWM at PD7 (J7) |
||
134 | // to control a camera servo for nick compensation. |
||
135 | void TIMER2_Init(void) |
||
910 | hbuss | 136 | { |
1242 | Arthur | 137 | |
1156 | hbuss | 138 | uint8_t sreg = SREG; |
139 | |||
140 | // disable all interrupts before reconfiguration |
||
141 | cli(); |
||
142 | |||
143 | // set PD7 as output of the PWM for nick servo |
||
144 | DDRD |= (1<<DDD7); |
||
145 | PORTD &= ~(1<<PORTD7); // set PD7 to low |
||
146 | |||
147 | DDRC |= (1<<DDC6); // set PC6 as output (Reset for HEF4017) |
||
1171 | hbuss | 148 | HEF4017R_ON; |
1156 | hbuss | 149 | // Timer/Counter 2 Control Register A |
150 | |||
151 | // Timer Mode is FastPWM with timer reload at OCR2A (Bits: WGM22 = 1, WGM21 = 1, WGM20 = 1) |
||
152 | // PD7: Normal port operation, OC2A disconnected, (Bits: COM2A1 = 0, COM2A0 = 0) |
||
153 | // PD6: Normal port operation, OC2B disconnected, (Bits: COM2B1 = 0, COM2B0 = 0) |
||
154 | TCCR2A &= ~((1<<COM2A1)|(1<<COM2A0)|(1<<COM2B1)|(1<<COM2B0)); |
||
155 | TCCR2A |= (1<<WGM21)|(1<<WGM20); |
||
156 | |||
157 | // Timer/Counter 2 Control Register B |
||
158 | |||
159 | // Set clock divider for timer 2 to SYSKLOCK/32 = 20MHz / 32 = 625 kHz |
||
160 | // The timer increments from 0x00 to 0xFF with an update rate of 625 kHz or 1.6 us |
||
161 | // hence the timer overflow interrupt frequency is 625 kHz / 256 = 2.44 kHz or 0.4096 ms |
||
162 | |||
163 | // divider 32 (Bits: CS022 = 0, CS21 = 1, CS20 = 1) |
||
164 | TCCR2B &= ~((1<<FOC2A)|(1<<FOC2B)|(1<<CS22)); |
||
165 | TCCR2B |= (1<<CS21)|(1<<CS20)|(1<<WGM22); |
||
166 | |||
167 | // Initialize the Timer/Counter 2 Register |
||
168 | TCNT2 = 0; |
||
169 | |||
170 | // Initialize the Output Compare Register A used for PWM generation on port PD7. |
||
171 | OCR2A = 255; |
||
172 | TCCR2A |= (1<<COM2A1); // set or clear at compare match depends on value of COM2A0 |
||
173 | |||
174 | // Timer/Counter 2 Interrupt Mask Register |
||
175 | // Enable timer output compare match A Interrupt only |
||
176 | TIMSK2 &= ~((1<<OCIE2B)|(1<<TOIE2)); |
||
177 | TIMSK2 |= (1<<OCIE2A); |
||
178 | |||
179 | SREG = sreg; |
||
910 | hbuss | 180 | } |
181 | |||
1156 | hbuss | 182 | //---------------------------- |
183 | void Timer_Init(void) |
||
1 | ingob | 184 | { |
1242 | Arthur | 185 | |
1156 | hbuss | 186 | tim_main = SetDelay(10); |
187 | TCCR0B = CK8; |
||
188 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
||
189 | OCR0A = 0; |
||
190 | OCR0B = 120; |
||
191 | TCNT0 = (unsigned char)-TIMER_RELOAD_VALUE; // reload |
||
192 | //OCR1 = 0x00; |
||
1105 | killagreg | 193 | |
1156 | hbuss | 194 | TIMSK0 |= _BV(TOIE0); |
195 | } |
||
196 | |||
197 | |||
198 | /*****************************************************/ |
||
199 | /* Control Servo Position */ |
||
200 | /*****************************************************/ |
||
201 | |||
202 | ISR(TIMER2_COMPA_vect) |
||
203 | { |
||
204 | |||
205 | // frame len 22.5 ms = 14063 * 1.6 us |
||
206 | // stop pulse: 0.3 ms = 188 * 1.6 us |
||
207 | // min servo pulse: 0.6 ms = 375 * 1.6 us |
||
208 | // max servo pulse: 2.4 ms = 1500 * 1.6 us |
||
209 | // resolution: 1500 - 375 = 1125 steps |
||
210 | |||
211 | #define IRS_RUNTIME 127 |
||
212 | #define PPM_STOPPULSE 188 |
||
213 | // #define PPM_FRAMELEN (14063 |
||
1171 | hbuss | 214 | #define PPM_FRAMELEN (1757 * EE_Parameter.ServoNickRefresh) |
1156 | hbuss | 215 | #define MINSERVOPULSE 375 |
216 | #define MAXSERVOPULSE 1500 |
||
217 | #define SERVORANGE (MAXSERVOPULSE - MINSERVOPULSE) |
||
218 | |||
219 | static uint8_t PulseOutput = 0; |
||
220 | static uint16_t RemainingPulse = 0; |
||
221 | static uint16_t ServoFrameTime = 0; |
||
222 | static uint8_t ServoIndex = 0; |
||
223 | |||
224 | #define MULTIPLYER 4 |
||
225 | static int16_t ServoNickOffset = (255 / 2) * MULTIPLYER; // initial value near center positon |
||
1224 | hbuss | 226 | static int16_t ServoRollOffset = (255 / 2) * MULTIPLYER; // initial value near center positon |
1156 | hbuss | 227 | |
1242 | Arthur | 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. |
||
1265 | Arthur | 231 | // 090807: Arthur P.: Removed the shutter cycle parts as they may be impacting timing loops. |
1242 | Arthur | 232 | // CameraShutterCycle = 5 * Parameter_UserParam6; |
1265 | Arthur | 233 | // CameraShutterCycle = Parameter_UserParam6; |
1242 | Arthur | 234 | |
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. |
||
1229 | Arthur | 237 | // if((PlatinenVersion < 20) |
1242 | Arthur | 238 | |
1229 | Arthur | 239 | if((PlatinenVersion < 20) && (Parameter_UserParam8 < 128 )) |
1156 | hbuss | 240 | { |
241 | //--------------------------- |
||
242 | // Nick servo state machine |
||
243 | //--------------------------- |
||
244 | if(!PulseOutput) // pulse output complete |
||
245 | { |
||
246 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
||
247 | { |
||
248 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
||
249 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
||
250 | |||
251 | ServoNickOffset = (ServoNickOffset * 3 + (int16_t)Parameter_ServoNickControl * MULTIPLYER) / 4; // lowpass offset |
||
252 | ServoNickValue = ServoNickOffset; // offset (Range from 0 to 255 * 3 = 765) |
||
253 | if(EE_Parameter.ServoNickCompInvert & 0x01) |
||
254 | { // inverting movement of servo |
||
255 | ServoNickValue += (int16_t)( ( (int32_t)EE_Parameter.ServoNickComp * MULTIPLYER * (IntegralNick / 128L ) ) / (256L) ); |
||
256 | } |
||
257 | else |
||
258 | { // non inverting movement of servo |
||
259 | ServoNickValue -= (int16_t)( ( (int32_t)EE_Parameter.ServoNickComp * MULTIPLYER * (IntegralNick / 128L ) ) / (256L) ); |
||
260 | } |
||
261 | // limit servo value to its parameter range definition |
||
262 | if(ServoNickValue < ((int16_t)EE_Parameter.ServoNickMin * MULTIPLYER) ) |
||
263 | { |
||
264 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMin * MULTIPLYER; |
||
265 | } |
||
266 | else |
||
267 | if(ServoNickValue > ((int16_t)EE_Parameter.ServoNickMax * MULTIPLYER) ) |
||
268 | { |
||
269 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMax * MULTIPLYER; |
||
270 | } |
||
271 | |||
272 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
||
273 | |||
274 | ServoNickValue /= MULTIPLYER; |
||
275 | DebugOut.Analog[20] = ServoNickValue; |
||
276 | |||
277 | // range servo pulse width |
||
278 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
||
279 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
||
280 | // accumulate time for correct update rate |
||
281 | ServoFrameTime = RemainingPulse; |
||
282 | } |
||
283 | else // we had a high pulse |
||
284 | { |
||
285 | TCCR2A |= (1<<COM2A0); // make a low pulse |
||
286 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; |
||
287 | } |
||
288 | // set pulse output active |
||
289 | PulseOutput = 1; |
||
290 | } |
||
291 | } // EOF Nick servo state machine |
||
292 | else |
||
293 | { |
||
294 | //----------------------------------------------------- |
||
295 | // PPM state machine, onboard demultiplexed by HEF4017 |
||
296 | //----------------------------------------------------- |
||
297 | if(!PulseOutput) // pulse output complete |
||
298 | { |
||
299 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
||
300 | { |
||
301 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
||
302 | |||
303 | if(ServoIndex == 0) // if we are at the sync gap |
||
304 | { |
||
305 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; // generate sync gap by filling time to full frame time |
||
306 | ServoFrameTime = 0; // reset servo frame time |
||
307 | HEF4017R_ON; // enable HEF4017 reset |
||
308 | } |
||
309 | else // servo channels |
||
310 | { |
||
311 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
||
312 | switch(ServoIndex) // map servo channels |
||
313 | { |
||
314 | case 1: // Nick Compensation Servo |
||
315 | ServoNickOffset = (ServoNickOffset * 3 + (int16_t)Parameter_ServoNickControl * MULTIPLYER) / 4; // lowpass offset |
||
316 | ServoNickValue = ServoNickOffset; // offset (Range from 0 to 255 * 3 = 765) |
||
317 | if(EE_Parameter.ServoNickCompInvert & 0x01) |
||
318 | { // inverting movement of servo |
||
319 | ServoNickValue += (int16_t)( ( (int32_t)EE_Parameter.ServoNickComp * MULTIPLYER * (IntegralNick / 128L ) ) / (256L) ); |
||
320 | } |
||
321 | else |
||
322 | { // non inverting movement of servo |
||
323 | ServoNickValue -= (int16_t)( ( (int32_t)EE_Parameter.ServoNickComp * MULTIPLYER * (IntegralNick / 128L ) ) / (256L) ); |
||
324 | } |
||
325 | // limit servo value to its parameter range definition |
||
326 | if(ServoNickValue < ((int16_t)EE_Parameter.ServoNickMin * MULTIPLYER) ) |
||
327 | { |
||
328 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMin * MULTIPLYER; |
||
329 | } |
||
330 | else |
||
331 | if(ServoNickValue > ((int16_t)EE_Parameter.ServoNickMax * MULTIPLYER) ) |
||
332 | { |
||
333 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMax * MULTIPLYER; |
||
334 | } |
||
335 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
||
336 | ServoNickValue /= MULTIPLYER; |
||
337 | DebugOut.Analog[20] = ServoNickValue; |
||
338 | break; |
||
1224 | hbuss | 339 | case 2: // Roll Compensation Servo |
1242 | Arthur | 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 | { |
||
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 | } |
||
1224 | hbuss | 352 | ServoRollValue = ServoRollOffset; // offset (Range from 0 to 255 * 3 = 765) |
353 | //if(EE_Parameter.ServoRollCompInvert & 0x01) |
||
1229 | Arthur | 354 | if(Parameter_UserParam8 & 0x40) |
1242 | Arthur | 355 | { // Arthur P: Inverting movement of servo if 64 has been added to User Parameter8 |
1229 | Arthur | 356 | ServoRollValue += (int16_t)( ( (int32_t) 50 * MULTIPLYER * (IntegralRoll / 128L ) ) / (256L) ); |
1224 | hbuss | 357 | } |
1229 | Arthur | 358 | /**/ else |
1224 | hbuss | 359 | { // non inverting movement of servo |
360 | ServoRollValue -= (int16_t)( ( (int32_t) 40 * MULTIPLYER * (IntegralRoll / 128L ) ) / (256L) ); |
||
361 | } |
||
1229 | Arthur | 362 | /**/ // limit servo value to its parameter range definition |
1224 | hbuss | 363 | if(ServoRollValue < ((int16_t)EE_Parameter.ServoNickMin * MULTIPLYER) ) |
364 | { |
||
365 | ServoRollValue = (int16_t)EE_Parameter.ServoNickMin * MULTIPLYER; |
||
366 | } |
||
367 | else |
||
368 | if(ServoRollValue > ((int16_t)EE_Parameter.ServoNickMax * MULTIPLYER) ) |
||
369 | { |
||
370 | ServoRollValue = (int16_t)EE_Parameter.ServoNickMax * MULTIPLYER; |
||
371 | } |
||
372 | RemainingPulse += ServoRollValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
||
373 | ServoRollValue /= MULTIPLYER; |
||
374 | //DebugOut.Analog[20] = ServoRollValue; |
||
1156 | hbuss | 375 | |
1224 | hbuss | 376 | /* ServoRollOffset = (ServoRollOffset * 3 + (int16_t)Parameter_ServoRollControl * MULTIPLYER) / 4; // lowpass offset |
377 | ServoRollValue = ServoRollOffset; // offset (Range from 0 to 255 * 3 = 765) |
||
378 | if(EE_Parameter.ServoRollCompInvert & 0x01) |
||
379 | { // inverting movement of servo |
||
380 | ServoRollValue += (int16_t)( ( (int32_t)EE_Parameter.ServoNickComp * MULTIPLYER * (IntegralNick / 128L ) ) / (256L) ); |
||
381 | } |
||
382 | else |
||
383 | { // non inverting movement of servo |
||
384 | ServoRollValue -= (int16_t)( ( (int32_t)EE_Parameter.ServoNickComp * MULTIPLYER * (IntegralNick / 128L ) ) / (256L) ); |
||
385 | } |
||
386 | // limit servo value to its parameter range definition |
||
387 | if(ServoRollValue < ((int16_t)EE_Parameter.ServoRollMin * MULTIPLYER) ) |
||
388 | { |
||
389 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMin * MULTIPLYER; |
||
390 | } |
||
391 | else |
||
392 | if(ServoRollValue > ((int16_t)EE_Parameter.ServoRollMax * MULTIPLYER) ) |
||
393 | { |
||
394 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMax * MULTIPLYER; |
||
395 | } |
||
396 | RemainingPulse += ServoRollValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
||
397 | ServoRollValue /= MULTIPLYER; |
||
398 | //DebugOut.Analog[20] = ServoRollValue; |
||
399 | */ break; |
||
1242 | Arthur | 400 | case 3: // Arthur P: Shutter Servo including interval control over parameter 5 and 6. |
1224 | hbuss | 401 | |
1242 | Arthur | 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 | { |
||
1265 | Arthur | 410 | // 090807: Arthur P.: Removed the shutter cycle parts as they may be impacting timing loops. |
411 | // if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] > 32) |
||
1242 | Arthur | 412 | // Middle position on a 3 position switch which runs from -127 to +127 |
1265 | Arthur | 413 | // { |
1242 | Arthur | 414 | |
415 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; |
||
1265 | Arthur | 416 | // } |
417 | // else |
||
418 | // { |
||
419 | // Cycle shutter servo between on and off depending upon CameraShutterCycleCounter |
||
1242 | Arthur | 420 | // If CameraShutterCylce < 50 then default to continuous shoot. |
1265 | Arthur | 421 | //if(CameraShutterCycle < 50 ) |
422 | // { |
||
1242 | Arthur | 423 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; |
1265 | Arthur | 424 | // } |
425 | // else |
||
426 | // { |
||
427 | // if(CameraShutterCycleCounter == CameraShutterCycle) |
||
428 | // { |
||
1242 | Arthur | 429 | // Shutter on |
1265 | Arthur | 430 | // CameraShutterCycleCounter = 0; |
431 | // RemainingPulse = MINSERVOPULSE + SERVORANGE/2; |
||
432 | // } |
||
433 | // else |
||
434 | // { |
||
1242 | Arthur | 435 | // Leave on for at least 24 cycles or 0.25 seconds to allow |
436 | // the camera to properly trigger, turn off if past 0.25 sec. |
||
437 | // For now this is actually set via para5 to allow for a long enough |
||
438 | // shutter pulse for different cameras. Once it is clear what value |
||
439 | // works, this can be changed to a hardcoded value. |
||
1265 | Arthur | 440 | // if(CameraShutterCycleCounter>Parameter_UserParam5) |
441 | // { |
||
1242 | Arthur | 442 | |
1265 | Arthur | 443 | // RemainingPulse = MINSERVOPULSE; |
444 | // } |
||
445 | // CameraShutterCycleCounter++; |
||
446 | // } |
||
447 | // } |
||
448 | // } |
||
1242 | Arthur | 449 | } |
450 | break; |
||
1265 | Arthur | 451 | // 090807 Arthur P: Removed the output of the remaining channels as this just eats time and probably |
452 | // does not have much of a function. Better to add specific outputs as needed. |
||
453 | // default: // other servo channels |
||
454 | // RemainingPulse += 2 * PPM_in[ServoIndex]; // add channel value, factor of 2 because timer 1 increments 3.2µs |
||
455 | // break; |
||
1156 | hbuss | 456 | } |
457 | // range servo pulse width |
||
458 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
||
459 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
||
460 | // substract stop pulse width |
||
1242 | Arthur | 461 | // Arthur P: I think the following line, correcting for the PPM sTOPPULSE does not apply for the |
462 | // calculated pulses, or maybe not at all. Therefore I-m commenting it out to see what happens.... |
||
463 | // 090624 reactivated as rollservo correction can now be done over para7. |
||
1156 | hbuss | 464 | RemainingPulse -= PPM_STOPPULSE; |
465 | // accumulate time for correct sync gap |
||
466 | ServoFrameTime += RemainingPulse; |
||
467 | } |
||
468 | } |
||
469 | else // we had a high pulse |
||
470 | { |
||
471 | TCCR2A |= (1<<COM2A0); // make a low pulse |
||
472 | // set pulsewidth to stop pulse width |
||
473 | RemainingPulse = PPM_STOPPULSE; |
||
474 | // accumulate time for correct sync gap |
||
475 | ServoFrameTime += RemainingPulse; |
||
1171 | hbuss | 476 | if(ServoActive && SenderOkay > 180) HEF4017R_OFF; // disable HEF4017 reset |
1156 | hbuss | 477 | ServoIndex++; // change to next servo channel |
478 | if(ServoIndex > EE_Parameter.ServoNickRefresh) ServoIndex = 0; // reset to the sync gap |
||
479 | } |
||
480 | // set pulse output active |
||
481 | PulseOutput = 1; |
||
482 | } |
||
483 | } // EOF PPM state machine |
||
484 | |||
485 | // General pulse output generator |
||
486 | if(RemainingPulse > (255 + IRS_RUNTIME)) |
||
487 | { |
||
488 | OCR2A = 255; |
||
489 | RemainingPulse -= 255; |
||
910 | hbuss | 490 | } |
1156 | hbuss | 491 | else |
492 | { |
||
493 | if(RemainingPulse > 255) // this is the 2nd last part |
||
494 | { |
||
495 | if((RemainingPulse - 255) < IRS_RUNTIME) |
||
496 | { |
||
497 | OCR2A = 255 - IRS_RUNTIME; |
||
498 | RemainingPulse -= 255 - IRS_RUNTIME; |
||
499 | |||
500 | } |
||
501 | else // last part > ISR_RUNTIME |
||
502 | { |
||
503 | OCR2A = 255; |
||
504 | RemainingPulse -= 255; |
||
505 | } |
||
506 | } |
||
507 | else // this is the last part |
||
508 | { |
||
509 | OCR2A = RemainingPulse; |
||
510 | RemainingPulse = 0; |
||
511 | PulseOutput = 0; // trigger to stop pulse |
||
512 | } |
||
513 | } // EOF general pulse output generator |
||
1111 | hbuss | 514 | } |