From fb5dd4094910ff3a8f4f81f4e54567fbda8e9bf6 Mon Sep 17 00:00:00 2001 From: InsanityAutomation Date: Wed, 8 Jun 2022 17:38:04 -0400 Subject: [PATCH] Revise timer to MCK/2 Co-Authored-By: sjasonsmith <20053467+sjasonsmith@users.noreply.github.com> --- Marlin/src/HAL/DUE/Servo.cpp | 7 ++++--- Marlin/src/HAL/DUE/ServoTimers.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Marlin/src/HAL/DUE/Servo.cpp b/Marlin/src/HAL/DUE/Servo.cpp index a04f0e4aa7..5b63637dbc 100644 --- a/Marlin/src/HAL/DUE/Servo.cpp +++ b/Marlin/src/HAL/DUE/Servo.cpp @@ -71,13 +71,14 @@ void Servo_Handler(const timer16_Sequence_t timer, Tc *pTc, const uint8_t channe #endif void Servo_Handler(const timer16_Sequence_t timer, Tc *tc, const uint8_t channel) { + tc->TC_CHANNEL[channel].TC_SR; // clear interrupt + const bool good_servo = SERVO_INDEX(timer, Channel[timer]) < ServoCount; if (Channel[timer] < 0) tc->TC_CHANNEL[channel].TC_CCR |= TC_CCR_SWTRG; // channel set to -1 indicated that refresh interval completed so reset the timer - else if (good_servo) + else if (good_servo && SERVO(timer, Channel[timer]).Pin.isActive) extDigitalWrite(SERVO(timer, Channel[timer]).Pin.nbr, LOW); // always pulse the channel low - tc->TC_CHANNEL[channel].TC_SR; // clear interrupt Channel[timer]++; // increment to the next channel 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 static void _initISR(Tc *tc, uint32_t channel, uint32_t id, IRQn_Type irqn) { pmc_enable_periph_clk(id); TC_Configure(tc, channel, - TC_CMR_TCCLKS_TIMER_CLOCK3 | // MCK/32 + TC_CMR_TCCLKS_TIMER_CLOCK1 | // MCK/32 TC_CMR_WAVE | // Waveform mode TC_CMR_WAVSEL_UP_RC ); // Counter running up and reset when equals to RC diff --git a/Marlin/src/HAL/DUE/ServoTimers.h b/Marlin/src/HAL/DUE/ServoTimers.h index c32c938253..f95afeda41 100644 --- a/Marlin/src/HAL/DUE/ServoTimers.h +++ b/Marlin/src/HAL/DUE/ServoTimers.h @@ -37,7 +37,7 @@ #define _useTimer5 #define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays -#define SERVO_TIMER_PRESCALER 32 // timer prescaler +#define SERVO_TIMER_PRESCALER 2 // timer prescaler /* TC0, chan 0 => TC0_Handler