diff options
-rw-r--r-- | src/GCodes/GCodes2.cpp | 5 | ||||
-rw-r--r-- | src/GPIO/GpOutPort.cpp | 4 | ||||
-rw-r--r-- | src/GPIO/GpOutPort.h | 1 |
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; |