|
@@ -221,6 +221,7 @@ void tmr0_reset()
|
221
|
221
|
OCR0A = ctl_regs[kTmr_Fine_idx];
|
222
|
222
|
}
|
223
|
223
|
|
|
224
|
+ TCNT0 = 0;
|
224
|
225
|
TIMSK |= _BV(OCIE0A); // enable the timer interrupt
|
225
|
226
|
}
|
226
|
227
|
|
|
@@ -247,7 +248,8 @@ ISR(TIMER0_COMPA_vect)
|
247
|
248
|
// This marks the end of a timer period
|
248
|
249
|
|
249
|
250
|
clear_attack();
|
250
|
|
-
|
|
251
|
+
|
|
252
|
+ TCNT1 = 0;
|
251
|
253
|
TIMSK |= _BV(OCIE1B) + _BV(TOIE1); // PWM interupt Enable interrupts
|
252
|
254
|
TIMSK &= ~_BV(OCIE0A); // clear timer interrupt
|
253
|
255
|
|
|
@@ -282,15 +284,17 @@ void pwm1_update()
|
282
|
284
|
}
|
283
|
285
|
|
284
|
286
|
|
285
|
|
-
|
|
287
|
+// Called when TCNT1 == OCR1C.
|
|
288
|
+// At this point TCNT1 is reset to 0, new OCR1B values are latched from temp. loctaion to OCR1B
|
286
|
289
|
ISR(TIMER1_OVF_vect)
|
287
|
290
|
{
|
288
|
|
- PORTB |= _BV(HOLD_PIN); // set PWM pin
|
|
291
|
+ PORTB &= ~(_BV(HOLD_PIN)); // clear PWM pin
|
289
|
292
|
}
|
290
|
293
|
|
|
294
|
+// Called when TCN1 == OCR1B
|
291
|
295
|
ISR(TIMER1_COMPB_vect)
|
292
|
296
|
{
|
293
|
|
- PORTB &= ~(_BV(HOLD_PIN)); // clear PWM pin
|
|
297
|
+ PORTB |= _BV(HOLD_PIN); // set PWM pin
|
294
|
298
|
}
|
295
|
299
|
|
296
|
300
|
|
|
@@ -298,11 +302,8 @@ void pwm1_init()
|
298
|
302
|
{
|
299
|
303
|
TIMSK &= ~(_BV(OCIE1B) + _BV(TOIE1)); // Disable interrupts
|
300
|
304
|
|
301
|
|
- DDRB |= _BV(HOLD_DIR); // setup PB3 as output
|
|
305
|
+ DDRB |= _BV(HOLD_DIR); // setup PB3 as output
|
302
|
306
|
|
303
|
|
- // set on TCNT1 == 0 // happens when TCNT1 matches OCR1C
|
304
|
|
- // clr on OCR1B == TCNT // happens when TCNT1 matches OCR1B
|
305
|
|
- // // COM1B1=1 COM1B0=0 (enable output on ~OC1B)
|
306
|
307
|
TCCR1 |= ctl_regs[ kPwm_Div_idx]; // 32us period (512 divider) prescaler
|
307
|
308
|
GTCCR |= _BV(PWM1B); // Enable PWM B and disconnect output pins
|
308
|
309
|
GTCCR |= _BV(PSR1); // Set the pre-scaler to the selected value
|
|
@@ -452,7 +453,9 @@ void on_receive( uint8_t byteN )
|
452
|
453
|
|
453
|
454
|
// if the PWM prescaler was changed
|
454
|
455
|
if( i == 3 )
|
|
456
|
+ cli();
|
455
|
457
|
pwm1_init();
|
|
458
|
+ sei();
|
456
|
459
|
|
457
|
460
|
pwm1_update();
|
458
|
461
|
break;
|
|
@@ -470,7 +473,9 @@ void on_receive( uint8_t byteN )
|
470
|
473
|
}
|
471
|
474
|
// if a prescaler was included then the timer needs to be re-initialized
|
472
|
475
|
if( i == 3 )
|
|
476
|
+ cli();
|
473
|
477
|
tmr0_init();
|
|
478
|
+ sei();
|
474
|
479
|
|
475
|
480
|
tmr0_reset();
|
476
|
481
|
break;
|