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>2021-07-24 13:04:13 +0300
committerDavid Crocker <dcrocker@eschertech.com>2021-07-24 13:04:13 +0300
commit745c9baea0c8d6b3987d0a8795c74afa5ae4da03 (patch)
tree0e1f2f27d7c5f2585e809ec5deb2eb4d5966ebc7 /src/RepRapFirmware.h
parent107551283f1f69e607125b75bb8cfebf4cb8cd5d (diff)
Finished converting time units to step clocks, pending testing
Diffstat (limited to 'src/RepRapFirmware.h')
-rw-r--r--src/RepRapFirmware.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/RepRapFirmware.h b/src/RepRapFirmware.h
index edc921e0..53019c85 100644
--- a/src/RepRapFirmware.h
+++ b/src/RepRapFirmware.h
@@ -503,6 +503,61 @@ constexpr float TwoPi = 3.141592653589793 * 2;
constexpr float DegreesToRadians = 3.141592653589793/180.0;
constexpr float RadiansToDegrees = 180.0/3.141592653589793;
+// The step clock is used for timing step pulses and oyther fine-resolution timer purposes
+
+#if SAME70 || SAME5x
+// All Duet 3 boards use a common step clock rate of 750kHz so that we can sync the clocks over CAN
+constexpr uint32_t StepClockRate = 48000000/64; // 750kHz
+#elif defined(__LPC17xx__)
+constexpr uint32_t StepClockRate = 1000000; // 1MHz
+#else
+constexpr uint32_t StepClockRate = SystemCoreClockFreq/128; // Duet 2 and Maestro: use just under 1MHz
+#endif
+
+constexpr uint64_t StepClockRateSquared = (uint64_t)StepClockRate * StepClockRate;
+constexpr float StepClocksToMillis = 1000.0/(float)StepClockRate;
+
+// Functions to convert speeds and accelerations between seconds and step clocks
+static inline constexpr float ConvertSpeedFromMmPerSec(float speed) noexcept
+{
+ return speed * 1.0/StepClockRate;
+}
+
+static inline constexpr float ConvertSpeedFromMmPerMin(float speed) noexcept
+{
+ return speed * (MinutesToSeconds/StepClockRate);
+}
+
+static inline constexpr float ConvertSpeedFromMm(float speed, bool useSeconds) noexcept
+{
+ return speed * ((useSeconds) ? 1.0/StepClockRate : MinutesToSeconds/StepClockRate);
+}
+
+static inline constexpr float InverseConvertSpeedToMmPerSec(float speed) noexcept
+{
+ return speed * StepClockRate;
+}
+
+static inline constexpr float InverseConvertSpeedToMmPerMin(float speed) noexcept
+{
+ return speed * (StepClockRate * SecondsToMinutes);
+}
+
+static inline constexpr float InverseConvertSpeedToMm(float speed, bool useSeconds) noexcept
+{
+ return speed * ((useSeconds) ? StepClockRate : StepClockRate * SecondsToMinutes);
+}
+
+static inline constexpr float ConvertAcceleration(float accel) noexcept
+{
+ return accel * (1.0/StepClockRateSquared);
+}
+
+static inline constexpr float InverseConvertAcceleration(float accel) noexcept
+{
+ return accel * StepClockRateSquared;
+}
+
constexpr unsigned int MaxFloatDigitsDisplayedAfterPoint = 7;
const char *GetFloatFormatString(unsigned int numDigitsAfterPoint) noexcept;