Rev 1984 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | #include "main.h" |
1760 | holgerb | 2 | #define MULTIPLYER 4 |
1 | ingob | 3 | |
4 | volatile unsigned int CountMilliseconds = 0; |
||
5 | volatile static unsigned int tim_main; |
||
6 | volatile unsigned char UpdateMotor = 0; |
||
7 | volatile unsigned int cntKompass = 0; |
||
8 | volatile unsigned int beeptime = 0; |
||
1760 | holgerb | 9 | volatile unsigned char SendSPI = 0, ServoActive = 0, CalculateServoSignals = 1; |
10 | uint16_t RemainingPulse = 0; |
||
11 | volatile int16_t ServoNickOffset = (255 / 2) * MULTIPLYER * 16; // initial value near center positon |
||
12 | volatile int16_t ServoRollOffset = (255 / 2) * MULTIPLYER * 16; // initial value near center positon |
||
2013 | - | 13 | volatile int16_t ServoPanOffset = (255 / 2) * MULTIPLYER * 16; // MartinR: für Pan-Funktion |
723 | hbuss | 14 | |
173 | holgerb | 15 | unsigned int BeepMuster = 0xffff; |
1 | ingob | 16 | |
1156 | hbuss | 17 | volatile int16_t ServoNickValue = 0; |
18 | volatile int16_t ServoRollValue = 0; |
||
2013 | - | 19 | volatile int16_t ServoPanValue = 0; // MartinR : für PAN-Funktion |
1156 | hbuss | 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 | |||
1561 | killagreg | 34 | ISR(TIMER0_OVF_vect) // 9,7kHz |
1 | ingob | 35 | { |
1643 | holgerb | 36 | static unsigned char cnt_1ms = 1,cnt = 0, compass_active = 0; |
37 | unsigned char pieper_ein = 0; |
||
723 | hbuss | 38 | if(SendSPI) SendSPI--; |
1469 | killagreg | 39 | if(SpektrumTimer) SpektrumTimer--; |
1 | ingob | 40 | if(!cnt--) |
41 | { |
||
1105 | killagreg | 42 | cnt = 9; |
1643 | holgerb | 43 | CountMilliseconds++; |
1 | ingob | 44 | cnt_1ms++; |
45 | cnt_1ms %= 2; |
||
1643 | holgerb | 46 | |
1 | ingob | 47 | if(!cnt_1ms) UpdateMotor = 1; |
1713 | holgerb | 48 | if(!(PINC & 0x10)) compass_active = 1; |
1643 | holgerb | 49 | |
1664 | holgerb | 50 | if(beeptime) |
1 | ingob | 51 | { |
1664 | holgerb | 52 | if(beeptime > 10) beeptime -= 10; else beeptime = 0; |
1105 | killagreg | 53 | if(beeptime & BeepMuster) |
173 | holgerb | 54 | { |
55 | pieper_ein = 1; |
||
56 | } |
||
57 | else pieper_ein = 0; |
||
1 | ingob | 58 | } |
1105 | killagreg | 59 | else |
1651 | killagreg | 60 | { |
173 | holgerb | 61 | pieper_ein = 0; |
62 | BeepMuster = 0xffff; |
||
1105 | killagreg | 63 | } |
173 | holgerb | 64 | if(pieper_ein) |
65 | { |
||
66 | if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker an PORTD.2 |
||
67 | else PORTC |= (1<<7); // Speaker an PORTC.7 |
||
68 | } |
||
1105 | killagreg | 69 | else |
173 | holgerb | 70 | { |
71 | if(PlatinenVersion == 10) PORTD &= ~(1<<2); |
||
72 | else PORTC &= ~(1<<7); |
||
1105 | killagreg | 73 | } |
1643 | holgerb | 74 | } |
1916 | holgerb | 75 | if(compass_active && !NaviDataOkay && Parameter_GlobalConfig & CFG_KOMPASS_AKTIV) |
1 | ingob | 76 | { |
77 | if(PINC & 0x10) |
||
78 | { |
||
1643 | holgerb | 79 | if(++cntKompass > 1000) compass_active = 0; |
1 | ingob | 80 | } |
81 | else |
||
82 | { |
||
1105 | killagreg | 83 | if((cntKompass) && (cntKompass < 362)) |
84 | { |
||
693 | hbuss | 85 | cntKompass += cntKompass / 41; |
86 | if(cntKompass > 10) KompassValue = cntKompass - 10; else KompassValue = 0; |
||
1941 | holgerb | 87 | // KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
1105 | killagreg | 88 | } |
1 | ingob | 89 | cntKompass = 0; |
1105 | killagreg | 90 | } |
1 | ingob | 91 | } |
92 | } |
||
93 | |||
94 | |||
95 | // ----------------------------------------------------------------------- |
||
96 | unsigned int SetDelay (unsigned int t) |
||
97 | { |
||
98 | // TIMSK0 &= ~_BV(TOIE0); |
||
1105 | killagreg | 99 | return(CountMilliseconds + t + 1); |
1 | ingob | 100 | // TIMSK0 |= _BV(TOIE0); |
101 | } |
||
102 | |||
103 | // ----------------------------------------------------------------------- |
||
104 | char CheckDelay(unsigned int t) |
||
105 | { |
||
106 | // TIMSK0 &= ~_BV(TOIE0); |
||
107 | return(((t - CountMilliseconds) & 0x8000) >> 9); |
||
108 | // TIMSK0 |= _BV(TOIE0); |
||
109 | } |
||
110 | |||
111 | // ----------------------------------------------------------------------- |
||
112 | void Delay_ms(unsigned int w) |
||
113 | { |
||
114 | unsigned int akt; |
||
115 | akt = SetDelay(w); |
||
116 | while (!CheckDelay(akt)); |
||
117 | } |
||
118 | |||
395 | hbuss | 119 | void Delay_ms_Mess(unsigned int w) |
120 | { |
||
121 | unsigned int akt; |
||
122 | akt = SetDelay(w); |
||
1166 | hbuss | 123 | while (!CheckDelay(akt)) if(AdReady) {AdReady = 0; ANALOG_ON;} |
395 | hbuss | 124 | } |
125 | |||
1156 | hbuss | 126 | /*****************************************************/ |
127 | /* Initialize Timer 2 */ |
||
128 | /*****************************************************/ |
||
129 | // The timer 2 is used to generate the PWM at PD7 (J7) |
||
130 | // to control a camera servo for nick compensation. |
||
131 | void TIMER2_Init(void) |
||
910 | hbuss | 132 | { |
1156 | hbuss | 133 | uint8_t sreg = SREG; |
134 | |||
135 | // disable all interrupts before reconfiguration |
||
136 | cli(); |
||
1469 | killagreg | 137 | |
1156 | hbuss | 138 | PORTD &= ~(1<<PORTD7); // set PD7 to low |
139 | |||
140 | DDRC |= (1<<DDC6); // set PC6 as output (Reset for HEF4017) |
||
1171 | hbuss | 141 | HEF4017R_ON; |
1156 | hbuss | 142 | // Timer/Counter 2 Control Register A |
143 | |||
144 | // Timer Mode is FastPWM with timer reload at OCR2A (Bits: WGM22 = 1, WGM21 = 1, WGM20 = 1) |
||
145 | // PD7: Normal port operation, OC2A disconnected, (Bits: COM2A1 = 0, COM2A0 = 0) |
||
146 | // PD6: Normal port operation, OC2B disconnected, (Bits: COM2B1 = 0, COM2B0 = 0) |
||
147 | TCCR2A &= ~((1<<COM2A1)|(1<<COM2A0)|(1<<COM2B1)|(1<<COM2B0)); |
||
148 | TCCR2A |= (1<<WGM21)|(1<<WGM20); |
||
149 | |||
150 | // Timer/Counter 2 Control Register B |
||
151 | |||
152 | // Set clock divider for timer 2 to SYSKLOCK/32 = 20MHz / 32 = 625 kHz |
||
153 | // The timer increments from 0x00 to 0xFF with an update rate of 625 kHz or 1.6 us |
||
154 | // hence the timer overflow interrupt frequency is 625 kHz / 256 = 2.44 kHz or 0.4096 ms |
||
155 | |||
156 | // divider 32 (Bits: CS022 = 0, CS21 = 1, CS20 = 1) |
||
157 | TCCR2B &= ~((1<<FOC2A)|(1<<FOC2B)|(1<<CS22)); |
||
158 | TCCR2B |= (1<<CS21)|(1<<CS20)|(1<<WGM22); |
||
159 | |||
160 | // Initialize the Timer/Counter 2 Register |
||
161 | TCNT2 = 0; |
||
162 | |||
163 | // Initialize the Output Compare Register A used for PWM generation on port PD7. |
||
164 | OCR2A = 255; |
||
165 | TCCR2A |= (1<<COM2A1); // set or clear at compare match depends on value of COM2A0 |
||
166 | |||
167 | // Timer/Counter 2 Interrupt Mask Register |
||
168 | // Enable timer output compare match A Interrupt only |
||
169 | TIMSK2 &= ~((1<<OCIE2B)|(1<<TOIE2)); |
||
170 | TIMSK2 |= (1<<OCIE2A); |
||
171 | |||
172 | SREG = sreg; |
||
910 | hbuss | 173 | } |
174 | |||
1156 | hbuss | 175 | //---------------------------- |
176 | void Timer_Init(void) |
||
1 | ingob | 177 | { |
1156 | hbuss | 178 | tim_main = SetDelay(10); |
179 | TCCR0B = CK8; |
||
180 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
||
181 | OCR0A = 0; |
||
1638 | holgerb | 182 | OCR0B = 180; |
1156 | hbuss | 183 | TCNT0 = (unsigned char)-TIMER_RELOAD_VALUE; // reload |
184 | //OCR1 = 0x00; |
||
185 | TIMSK0 |= _BV(TOIE0); |
||
186 | } |
||
187 | |||
188 | |||
189 | /*****************************************************/ |
||
190 | /* Control Servo Position */ |
||
191 | /*****************************************************/ |
||
192 | |||
1760 | holgerb | 193 | |
194 | void CalculateServo(void) |
||
195 | { |
||
2013 | - | 196 | //signed char cosinus, sinus; // MartinR : so war es |
197 | extern signed char cosinus, sinus; // MartinR : extern für PAN-Funktion |
||
1771 | holgerb | 198 | signed long nick, roll; |
1760 | holgerb | 199 | |
2013 | - | 200 | nick = 0; // MartinR : StartWert bei abgeschalteten Nick/ Roll ausgleich |
201 | roll = 0; // MartinR : StartWert bei abgeschalteten Nick/ Roll ausgleich |
||
202 | int tmp; // MartinR : für PAN-Funktion // Wert : 0-24 -> 0-360 -> 15° steps |
||
203 | /* // MartinR: bisher |
||
204 | tmp = EE_Parameter.CamOrientation + ((Parameter_Servo4 - 125) * (Parameter_UserParam8 - 125)) / 400 ; //MartinR : für PAN-Funktion |
||
205 | if (tmp < 0) tmp = 24- (abs(tmp)) % 24 ; // MartinR :Modulo 24 |
||
206 | else tmp = tmp % 24 ; // MartinR :Modulo 24 |
||
207 | */ |
||
208 | tmp = EE_Parameter.CamOrientation + ((Parameter_Servo4 - 125) * (Parameter_UserParam8 - 125)) / 200 ; //MartinR : für PAN-Funktion |
||
209 | if (tmp < 0) tmp = 48- (abs(tmp)) % 48 ; // MartinR :Modulo 48 |
||
210 | else tmp = tmp % 48 ; // MartinR :Modulo 48 |
||
211 | |||
212 | // cosinus = sintab[EE_Parameter.CamOrientation + 6]; // MartinR : so war es |
||
213 | // sinus = sintab[EE_Parameter.CamOrientation]; // MartinR : so war es |
||
214 | //cosinus = sintab[tmp + 6]; // MartinR : für PAN-Funktion |
||
215 | cosinus += (2*sintab[tmp + 12]- cosinus + 1) / 2; // MartinR : für PAN-Funktion |
||
216 | sinus += (2*sintab[tmp] - sinus + 1) / 2; // MartinR : für PAN-Funktion |
||
1760 | holgerb | 217 | |
218 | if(CalculateServoSignals == 1) |
||
219 | { |
||
2013 | - | 220 | if (Parameter_UserParam7 < 50) // MartinR: um per UserParameter den Nickausgleich abzuschalten |
221 | { |
||
222 | //nick = (cosinus * IntegralNick) / 128L - (sinus * IntegralRoll) / 128L; // MartinR: so war es |
||
223 | nick = (cosinus * IntegralNick) / 512L - (sinus * IntegralRoll) / 512L; // MartinR: bessere Auflösung |
||
1848 | holgerb | 224 | nick -= POI_KameraNick * 7; |
2013 | - | 225 | } |
1763 | killagreg | 226 | nick = ((long)EE_Parameter.ServoNickComp * nick) / 512L; |
227 | ServoNickOffset += ((int16_t)Parameter_ServoNickControl * (MULTIPLYER*16) - ServoNickOffset) / EE_Parameter.ServoManualControlSpeed; |
||
228 | ServoNickValue = ServoNickOffset / 16; // offset (Range from 0 to 255 * 3 = 765) |
||
1840 | holgerb | 229 | |
1763 | killagreg | 230 | if(EE_Parameter.ServoCompInvert & 0x01) |
231 | { // inverting movement of servo |
||
232 | ServoNickValue += nick;//(int16_t)( ( (int32_t)EE_Parameter.ServoNickComp * nick) / (256L) ); |
||
233 | } |
||
234 | else |
||
235 | { // non inverting movement of servo |
||
236 | ServoNickValue -= nick; |
||
237 | } |
||
238 | // limit servo value to its parameter range definition |
||
239 | if(ServoNickValue < ((int16_t)EE_Parameter.ServoNickMin * MULTIPLYER) ) |
||
240 | { |
||
241 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMin * MULTIPLYER; |
||
242 | } |
||
243 | else |
||
244 | if(ServoNickValue > ((int16_t)EE_Parameter.ServoNickMax * MULTIPLYER) ) |
||
245 | { |
||
246 | ServoNickValue = (int16_t)EE_Parameter.ServoNickMax * MULTIPLYER; |
||
247 | } |
||
248 | if(PlatinenVersion < 20) CalculateServoSignals = 0; else CalculateServoSignals++; |
||
1760 | holgerb | 249 | } |
250 | else |
||
251 | { |
||
2013 | - | 252 | if (Parameter_UserParam7 < 100) // MartinR: um per UserParameter den Nickausgleich abzuschalten |
253 | { |
||
254 | //roll = (cosinus * IntegralRoll) / 128L + (sinus * IntegralNick) / 128L; // MartinR: so war es |
||
255 | roll = (cosinus * IntegralRoll) / 512L + (sinus * IntegralNick) / 512L; // MartinR: bessere Auflösung |
||
256 | } |
||
1763 | killagreg | 257 | roll = ((long)EE_Parameter.ServoRollComp * roll) / 512L; |
258 | ServoRollOffset += ((int16_t)Parameter_ServoRollControl * (MULTIPLYER*16) - ServoRollOffset) / EE_Parameter.ServoManualControlSpeed; |
||
259 | ServoRollValue = ServoRollOffset/16; // offset (Range from 0 to 255 * 3 = 765) |
||
260 | if(EE_Parameter.ServoCompInvert & 0x02) |
||
261 | { // inverting movement of servo |
||
262 | ServoRollValue += roll; |
||
263 | } |
||
264 | else |
||
265 | { // non inverting movement of servo |
||
266 | ServoRollValue -= roll; |
||
267 | } |
||
268 | // limit servo value to its parameter range definition |
||
269 | if(ServoRollValue < ((int16_t)EE_Parameter.ServoRollMin * MULTIPLYER) ) |
||
270 | { |
||
271 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMin * MULTIPLYER; |
||
272 | } |
||
273 | else |
||
274 | if(ServoRollValue > ((int16_t)EE_Parameter.ServoRollMax * MULTIPLYER) ) |
||
275 | { |
||
276 | ServoRollValue = (int16_t)EE_Parameter.ServoRollMax * MULTIPLYER; |
||
277 | } |
||
2013 | - | 278 | |
279 | // MartinR: Filterung der Pan- Funktion |
||
280 | ServoPanOffset += ((int16_t)Parameter_Servo4 * (MULTIPLYER*16) - ServoPanOffset) / EE_Parameter.ServoManualControlSpeed; |
||
281 | ServoPanValue = (int16_t)ServoPanOffset/16; // offset (Range from 0 to 255 * 3 = 765) |
||
282 | |||
1763 | killagreg | 283 | CalculateServoSignals = 0; |
1760 | holgerb | 284 | } |
285 | } |
||
286 | |||
1156 | hbuss | 287 | ISR(TIMER2_COMPA_vect) |
288 | { |
||
289 | // frame len 22.5 ms = 14063 * 1.6 us |
||
290 | // stop pulse: 0.3 ms = 188 * 1.6 us |
||
291 | // min servo pulse: 0.6 ms = 375 * 1.6 us |
||
292 | // max servo pulse: 2.4 ms = 1500 * 1.6 us |
||
293 | // resolution: 1500 - 375 = 1125 steps |
||
294 | |||
295 | #define IRS_RUNTIME 127 |
||
296 | #define PPM_STOPPULSE 188 |
||
1171 | hbuss | 297 | #define PPM_FRAMELEN (1757 * EE_Parameter.ServoNickRefresh) |
1156 | hbuss | 298 | #define MINSERVOPULSE 375 |
299 | #define MAXSERVOPULSE 1500 |
||
300 | #define SERVORANGE (MAXSERVOPULSE - MINSERVOPULSE) |
||
301 | |||
302 | static uint8_t PulseOutput = 0; |
||
303 | static uint16_t ServoFrameTime = 0; |
||
304 | static uint8_t ServoIndex = 0; |
||
305 | |||
306 | |||
307 | if(PlatinenVersion < 20) |
||
308 | { |
||
2013 | - | 309 | /* // MartinR : deaktiviert wegen Platzbedarf |
1156 | hbuss | 310 | //--------------------------- |
311 | // Nick servo state machine |
||
312 | //--------------------------- |
||
313 | if(!PulseOutput) // pulse output complete |
||
314 | { |
||
315 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
||
316 | { |
||
317 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
||
318 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
||
319 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
||
320 | // range servo pulse width |
||
321 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
||
322 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
||
323 | // accumulate time for correct update rate |
||
324 | ServoFrameTime = RemainingPulse; |
||
325 | } |
||
326 | else // we had a high pulse |
||
327 | { |
||
328 | TCCR2A |= (1<<COM2A0); // make a low pulse |
||
329 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; |
||
1763 | killagreg | 330 | CalculateServoSignals = 1; |
1156 | hbuss | 331 | } |
332 | // set pulse output active |
||
333 | PulseOutput = 1; |
||
334 | } |
||
2013 | - | 335 | */ |
1156 | hbuss | 336 | } // EOF Nick servo state machine |
337 | else |
||
338 | { |
||
339 | //----------------------------------------------------- |
||
340 | // PPM state machine, onboard demultiplexed by HEF4017 |
||
341 | //----------------------------------------------------- |
||
342 | if(!PulseOutput) // pulse output complete |
||
343 | { |
||
344 | if(TCCR2A & (1<<COM2A0)) // we had a low pulse |
||
345 | { |
||
346 | TCCR2A &= ~(1<<COM2A0);// make a high pulse |
||
347 | |||
348 | if(ServoIndex == 0) // if we are at the sync gap |
||
349 | { |
||
350 | RemainingPulse = PPM_FRAMELEN - ServoFrameTime; // generate sync gap by filling time to full frame time |
||
351 | ServoFrameTime = 0; // reset servo frame time |
||
352 | HEF4017R_ON; // enable HEF4017 reset |
||
353 | } |
||
354 | else // servo channels |
||
355 | { |
||
356 | RemainingPulse = MINSERVOPULSE + SERVORANGE/2; // center position ~ 1.5ms |
||
357 | switch(ServoIndex) // map servo channels |
||
358 | { |
||
359 | case 1: // Nick Compensation Servo |
||
360 | RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
||
361 | break; |
||
1224 | hbuss | 362 | case 2: // Roll Compensation Servo |
363 | RemainingPulse += ServoRollValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position |
||
1232 | hbuss | 364 | break; |
1565 | killagreg | 365 | case 3: |
366 | RemainingPulse += ((int16_t)Parameter_Servo3 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
||
1403 | hbuss | 367 | break; |
1543 | killagreg | 368 | case 4: |
2013 | - | 369 | //RemainingPulse += ((int16_t)Parameter_Servo4 * MULTIPLYER) - (256 / 2) * MULTIPLYER; // MartinR: so war es |
370 | RemainingPulse += ServoPanValue - (256 / 2) * MULTIPLYER; // MartinR: zur Filterung der Pan-Funktion |
||
1403 | hbuss | 371 | break; |
1543 | killagreg | 372 | case 5: |
1565 | killagreg | 373 | RemainingPulse += ((int16_t)Parameter_Servo5 * MULTIPLYER) - (256 / 2) * MULTIPLYER; |
1403 | hbuss | 374 | break; |
1156 | hbuss | 375 | default: // other servo channels |
376 | RemainingPulse += 2 * PPM_in[ServoIndex]; // add channel value, factor of 2 because timer 1 increments 3.2µs |
||
377 | break; |
||
378 | } |
||
379 | // range servo pulse width |
||
380 | if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit |
||
381 | else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit |
||
382 | // substract stop pulse width |
||
383 | RemainingPulse -= PPM_STOPPULSE; |
||
384 | // accumulate time for correct sync gap |
||
385 | ServoFrameTime += RemainingPulse; |
||
386 | } |
||
387 | } |
||
388 | else // we had a high pulse |
||
389 | { |
||
390 | TCCR2A |= (1<<COM2A0); // make a low pulse |
||
391 | // set pulsewidth to stop pulse width |
||
392 | RemainingPulse = PPM_STOPPULSE; |
||
393 | // accumulate time for correct sync gap |
||
394 | ServoFrameTime += RemainingPulse; |
||
1916 | holgerb | 395 | if((ServoActive && SenderOkay) || ServoActive == 2) HEF4017R_OFF; // disable HEF4017 reset |
1232 | hbuss | 396 | else HEF4017R_ON; |
1156 | hbuss | 397 | ServoIndex++; // change to next servo channel |
1763 | killagreg | 398 | if(ServoIndex > EE_Parameter.ServoNickRefresh) |
399 | { |
||
400 | CalculateServoSignals = 1; |
||
1760 | holgerb | 401 | ServoIndex = 0; // reset to the sync gap |
402 | } |
||
1156 | hbuss | 403 | } |
404 | // set pulse output active |
||
405 | PulseOutput = 1; |
||
406 | } |
||
407 | } // EOF PPM state machine |
||
408 | |||
409 | // General pulse output generator |
||
410 | if(RemainingPulse > (255 + IRS_RUNTIME)) |
||
411 | { |
||
412 | OCR2A = 255; |
||
413 | RemainingPulse -= 255; |
||
910 | hbuss | 414 | } |
1156 | hbuss | 415 | else |
416 | { |
||
417 | if(RemainingPulse > 255) // this is the 2nd last part |
||
418 | { |
||
419 | if((RemainingPulse - 255) < IRS_RUNTIME) |
||
420 | { |
||
421 | OCR2A = 255 - IRS_RUNTIME; |
||
422 | RemainingPulse -= 255 - IRS_RUNTIME; |
||
423 | |||
424 | } |
||
425 | else // last part > ISR_RUNTIME |
||
426 | { |
||
427 | OCR2A = 255; |
||
428 | RemainingPulse -= 255; |
||
429 | } |
||
430 | } |
||
431 | else // this is the last part |
||
432 | { |
||
433 | OCR2A = RemainingPulse; |
||
434 | RemainingPulse = 0; |
||
435 | PulseOutput = 0; // trigger to stop pulse |
||
436 | } |
||
437 | } // EOF general pulse output generator |
||
1111 | hbuss | 438 | } |