Skip to content

Commit fb5dd40

Browse files
Revise timer to MCK/2
Co-Authored-By: sjasonsmith <[email protected]>
1 parent c1775c9 commit fb5dd40

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

Marlin/src/HAL/DUE/Servo.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ void Servo_Handler(const timer16_Sequence_t timer, Tc *pTc, const uint8_t channe
7171
#endif
7272

7373
void Servo_Handler(const timer16_Sequence_t timer, Tc *tc, const uint8_t channel) {
74+
tc->TC_CHANNEL[channel].TC_SR; // clear interrupt
75+
7476
const bool good_servo = SERVO_INDEX(timer, Channel[timer]) < ServoCount;
7577
if (Channel[timer] < 0)
7678
tc->TC_CHANNEL[channel].TC_CCR |= TC_CCR_SWTRG; // channel set to -1 indicated that refresh interval completed so reset the timer
77-
else if (good_servo)
79+
else if (good_servo && SERVO(timer, Channel[timer]).Pin.isActive)
7880
extDigitalWrite(SERVO(timer, Channel[timer]).Pin.nbr, LOW); // always pulse the channel low
7981

80-
tc->TC_CHANNEL[channel].TC_SR; // clear interrupt
8182

8283
Channel[timer]++; // increment to the next channel
8384
if (good_servo && Channel[timer] < SERVOS_PER_TIMER) {
@@ -98,7 +99,7 @@ void Servo_Handler(const timer16_Sequence_t timer, Tc *tc, const uint8_t channel
9899
static void _initISR(Tc *tc, uint32_t channel, uint32_t id, IRQn_Type irqn) {
99100
pmc_enable_periph_clk(id);
100101
TC_Configure(tc, channel,
101-
TC_CMR_TCCLKS_TIMER_CLOCK3 | // MCK/32
102+
TC_CMR_TCCLKS_TIMER_CLOCK1 | // MCK/32
102103
TC_CMR_WAVE | // Waveform mode
103104
TC_CMR_WAVSEL_UP_RC ); // Counter running up and reset when equals to RC
104105

Marlin/src/HAL/DUE/ServoTimers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#define _useTimer5
3838

3939
#define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays
40-
#define SERVO_TIMER_PRESCALER 32 // timer prescaler
40+
#define SERVO_TIMER_PRESCALER 2 // timer prescaler
4141

4242
/*
4343
TC0, chan 0 => TC0_Handler

0 commit comments

Comments
 (0)