Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2020-04-20 20:43:15 +0300
committerDavid Crocker <dcrocker@eschertech.com>2020-04-20 20:43:15 +0300
commit64e172adf08f72d766d0abc26002ad9ef3ac0137 (patch)
tree6925a4fde7b1033ae2dd8483d50fbb01a77d6fdc /src/Fans/LocalFan.cpp
parent56c8e1d583d7f17e5c4266c7ce8cc227d40e3bdd (diff)
Reduced fan tacho reporting latcency for ATE
Diffstat (limited to 'src/Fans/LocalFan.cpp')
-rw-r--r--src/Fans/LocalFan.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/Fans/LocalFan.cpp b/src/Fans/LocalFan.cpp
index 44fcd9da..7bba31a4 100644
--- a/src/Fans/LocalFan.cpp
+++ b/src/Fans/LocalFan.cpp
@@ -161,17 +161,6 @@ void LocalFan::InternalRefresh() noexcept
SetHardwarePwm(reqVal);
lastVal = reqVal;
-
- if (tachoPort.IsValid())
- {
- // The ISR sets fanInterval to the number of step interrupt clocks it took to get fanMaxInterruptCount interrupts.
- // We get 2 tacho pulses per revolution, hence 2 interrupts per revolution.
- // When the fan stops, we get no interrupts and fanInterval stops getting updated. We must recognise this and return zero.
- const float rpm = (fanInterval != 0 && StepTimer::GetTimerTicks() - fanLastResetTime < 3 * StepTimer::StepClockRate) // if we have a reading and it is less than 3 seconds old
- ? (StepTimer::StepClockRate * fanMaxInterruptCount * (60/2))/fanInterval // then calculate RPM assuming 2 interrupts per rev
- : 0; // else assume fan is off or tacho not connected
- SetLastRpm(rpm);
- }
}
GCodeResult LocalFan::Refresh(const StringRef& reply) noexcept
@@ -215,6 +204,19 @@ bool LocalFan::AssignPorts(const char *pinNames, const StringRef& reply) noexcep
return true;
}
+// Tacho support
+int32_t LocalFan::GetRPM() const noexcept
+{
+ // The ISR sets fanInterval to the number of step interrupt clocks it took to get fanMaxInterruptCount interrupts.
+ // We get 2 tacho pulses per revolution, hence 2 interrupts per revolution.
+ // When the fan stops, we get no interrupts and fanInterval stops getting updated. We must recognise this and return zero.
+ return (!tachoPort.IsValid())
+ ? -1 // we return -1 if there is no tacho configured
+ : (fanInterval != 0 && StepTimer::GetTimerTicks() - fanLastResetTime < 3 * StepTimer::StepClockRate) // if we have a reading and it is less than 3 seconds old
+ ? (StepTimer::StepClockRate * fanMaxInterruptCount * (60/2))/fanInterval // then calculate RPM assuming 2 interrupts per rev
+ : 0; // else assume fan is off or tacho not connected
+}
+
void LocalFan::Interrupt() noexcept
{
++fanInterruptCount;