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
path: root/src
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2022-01-04 13:00:00 +0300
committerDavid Crocker <dcrocker@eschertech.com>2022-01-04 13:00:00 +0300
commit8e58dcacf096b2f82037c393c6c628483548d569 (patch)
tree8f19725fa75a6b977654e854f5f242c016459949 /src
parent214e4fb2b768475e1a02d5565d49428ccd8fde99 (diff)
Support variable servo refresh frequency
Diffstat (limited to 'src')
-rw-r--r--src/GCodes/GCodes2.cpp5
-rw-r--r--src/GPIO/GpOutPort.cpp4
-rw-r--r--src/GPIO/GpOutPort.h1
3 files changed, 6 insertions, 4 deletions
diff --git a/src/GCodes/GCodes2.cpp b/src/GCodes/GCodes2.cpp
index e2205c2f..97cf9ed2 100644
--- a/src/GCodes/GCodes2.cpp
+++ b/src/GCodes/GCodes2.cpp
@@ -2419,8 +2419,9 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
angleOrWidth = MaxServoPulseWidth;
}
- const float pwm = angleOrWidth * (ServoRefreshFrequency/1e6);
- result = platform.GetGpOutPort(gpioPortNumber).WriteAnalog(gpioPortNumber, true, pwm, gb, reply);
+ GpOutputPort& port = platform.GetGpOutPort(gpioPortNumber);
+ const float pwm = angleOrWidth * 1.0e-6 * port.GetPwmFrequency();
+ result = port.WriteAnalog(gpioPortNumber, true, pwm, gb, reply);
}
break;
diff --git a/src/GPIO/GpOutPort.cpp b/src/GPIO/GpOutPort.cpp
index 188bb9f7..f17eec12 100644
--- a/src/GPIO/GpOutPort.cpp
+++ b/src/GPIO/GpOutPort.cpp
@@ -85,7 +85,7 @@ GCodeResult GpOutputPort::Configure(uint32_t gpioNumber, bool isServo, GCodeBuff
if (!seenFreq)
{
- freq = (isServo) ? ServoRefreshFrequency : DefaultPinWritePwmFreq;
+ freq = (isServo) ? DefaultServoRefreshFrequency : DefaultPinWritePwmFreq;
}
GCodeResult rslt;
@@ -176,7 +176,7 @@ GCodeResult GpOutputPort::AssignFromRemote(uint32_t gpioPortNumber, const CanMes
const bool seenFreq = parser.GetUintParam('Q', freq);
if (!seenFreq)
{
- freq = (isServo) ? ServoRefreshFrequency : DefaultPinWritePwmFreq;
+ freq = (isServo) ? DefaultServoRefreshFrequency : DefaultPinWritePwmFreq;
}
String<StringLength50> pinName;
diff --git a/src/GPIO/GpOutPort.h b/src/GPIO/GpOutPort.h
index 087e48f4..245d32f6 100644
--- a/src/GPIO/GpOutPort.h
+++ b/src/GPIO/GpOutPort.h
@@ -29,6 +29,7 @@ public:
bool IsUnused() const noexcept;
GCodeResult WriteAnalog(uint32_t gpioPortNumber, bool isServo, float pwm, const GCodeBuffer& gb, const StringRef& reply) noexcept;
GCodeResult Configure(uint32_t gpioNumber, bool isServo, GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException);
+ PwmFrequency GetPwmFrequency() const noexcept { return port.GetFrequency(); }
#if SUPPORT_REMOTE_COMMANDS
GCodeResult AssignFromRemote(uint32_t gpioPortNumber, const CanMessageGenericParser& parser, const StringRef& reply) noexcept;