Skip to content

Commit 3dbe390

Browse files
committed
Don't modify TCA0 clock divider to avoid breaking delay()
1 parent 4970d61 commit 3dbe390

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/megaavr/Servo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <Arduino.h>
44
#include <Servo.h>
55

6-
#define usToTicks(_us) ((clockCyclesPerMicrosecond() * _us) / 16) // converts microseconds to tick
7-
#define ticksToUs(_ticks) (((unsigned) _ticks * 16) / clockCyclesPerMicrosecond()) // converts from ticks back to microseconds
6+
#define usToTicks(_us) ((clockCyclesPerMicrosecond() / 16 * _us) / 4) // converts microseconds to tick
7+
#define ticksToUs(_ticks) (((unsigned) _ticks * 16) / (clockCyclesPerMicrosecond() / 4)) // converts from ticks back to microseconds
88

99
#define TRIM_DURATION 5 // compensation ticks to trim adjust for digitalWrite delays
1010

@@ -79,7 +79,7 @@ ISR(TCB2_INT_vect)
7979

8080
static void initISR(timer16_Sequence_t timer)
8181
{
82-
TCA0.SINGLE.CTRLA = (TCA_SINGLE_CLKSEL_DIV16_gc) | (TCA_SINGLE_ENABLE_bm);
82+
//TCA0.SINGLE.CTRLA = (TCA_SINGLE_CLKSEL_DIV16_gc) | (TCA_SINGLE_ENABLE_bm);
8383

8484
_timer->CTRLA = TCB_CLKSEL_CLKTCA_gc;
8585
// Timer to Periodic interrupt mode

0 commit comments

Comments
 (0)