From e151a87dc6842dad0bccd2c83e414862d46eae49 Mon Sep 17 00:00:00 2001 From: luni64 <12611497+luni64@users.noreply.github.com> Date: Thu, 27 Jan 2022 20:08:29 +0100 Subject: [PATCH 1/5] Added callback functionality to RotateControl --- src/MotorControlBase.h | 5 ++++- src/RotateControlBase.h | 1 + src/StepControlBase.h | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/MotorControlBase.h b/src/MotorControlBase.h index 7a8e723..968ba62 100644 --- a/src/MotorControlBase.h +++ b/src/MotorControlBase.h @@ -27,6 +27,9 @@ namespace TeensyStep{ void emergencyStop() { timerField.end(); } + // set callback function to be called when target is reached + void setCallback(void (*_callback)()) { this->callback = _callback; } + virtual ~MotorControlBase(); void attachErrorFunction(ErrFunc ef) { errFunc = ef; } @@ -95,7 +98,7 @@ namespace TeensyStep{ template MotorControlBase::MotorControlBase(unsigned pulseWidth, unsigned accUpdatePeriod) : timerField(this), mCnt(0) - { + { timerField.setPulseWidth(pulseWidth); timerField.setAccUpdatePeriod(accUpdatePeriod); this->accUpdatePeriod = accUpdatePeriod; diff --git a/src/RotateControlBase.h b/src/RotateControlBase.h index f65de5a..17c243f 100644 --- a/src/RotateControlBase.h +++ b/src/RotateControlBase.h @@ -93,6 +93,7 @@ namespace TeensyStep this->timerField.end(); this->leadMotor->currentSpeed = 0; isStopping = false; + if (this->callback) this->callback(); return; } diff --git a/src/StepControlBase.h b/src/StepControlBase.h index c3b9d6d..5d3424d 100644 --- a/src/StepControlBase.h +++ b/src/StepControlBase.h @@ -56,8 +56,8 @@ namespace TeensyStep // Misc --------------------------------------------------------- - // set callback function to be called when target is reached - void setCallback(void (*_callback)()) { this->callback = _callback; } + // // set callback function to be called when target is reached + //void setCallback(void (*_callback)()) { this->callback = _callback; } protected: void accTimerISR(); From d32ff534469a32dcd14d274e88244d00f44fa4d1 Mon Sep 17 00:00:00 2001 From: luni64 Date: Tue, 29 Mar 2022 20:44:56 +0200 Subject: [PATCH 2/5] changed std::abs to abs to escape the Arduino madness #defining abs --- src/RotateControlBase.h | 6 +++--- src/StepControlBase.h | 6 +++--- src/Stepper.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/RotateControlBase.h b/src/RotateControlBase.h index 17c243f..04e8844 100644 --- a/src/RotateControlBase.h +++ b/src/RotateControlBase.h @@ -66,10 +66,10 @@ namespace TeensyStep this->leadMotor->currentSpeed = 0; - this->leadMotor->A = std::abs(this->leadMotor->vMax); + this->leadMotor->A = abs(this->leadMotor->vMax); for (int i = 1; i < N; i++) { - this->motorList[i]->A = std::abs(this->motorList[i]->vMax); + this->motorList[i]->A = abs(this->motorList[i]->vMax); this->motorList[i]->B = 2 * this->motorList[i]->A - this->leadMotor->A; } uint32_t acceleration = (*std::min_element(this->motorList, this->motorList + N, Stepper::cmpAcc))->a; // use the lowest acceleration for the move @@ -113,7 +113,7 @@ namespace TeensyStep delayMicroseconds(this->pulseWidth); // dir signal need some lead time } - this->timerField.setStepFrequency(std::abs(newSpeed)); // speed changed, update timer + this->timerField.setStepFrequency(abs(newSpeed)); // speed changed, update timer this->leadMotor->currentSpeed = newSpeed; } diff --git a/src/StepControlBase.h b/src/StepControlBase.h index 5d3424d..d94c1d0 100644 --- a/src/StepControlBase.h +++ b/src/StepControlBase.h @@ -96,16 +96,16 @@ namespace TeensyStep uint32_t pullOutSpeed = this->leadMotor->vPullOut; uint32_t acceleration = (*std::min_element(this->motorList, this->motorList + N, Stepper::cmpAcc))->a; // use the lowest acceleration for the move - uint32_t targetSpeed = std::abs((*std::min_element(this->motorList, this->motorList + N, Stepper::cmpVmin))->vMax) * speedOverride; // use the lowest max frequency for the move, scale by relSpeed + uint32_t targetSpeed = abs((*std::min_element(this->motorList, this->motorList + N, Stepper::cmpVmin))->vMax) * speedOverride; // use the lowest max frequency for the move, scale by relSpeed if (this->leadMotor->A == 0 || targetSpeed == 0) return; // target speed---- float x = 0; - float leadSpeed = std::abs(this->leadMotor->vMax); + float leadSpeed = abs(this->leadMotor->vMax); for (int i = 0; i < N; i++) { - float relDist = this->motorList[i]->A / (float)this->leadMotor->A * leadSpeed / std::abs(this->motorList[i]->vMax); + float relDist = this->motorList[i]->A / (float)this->leadMotor->A * leadSpeed / abs(this->motorList[i]->vMax); if (relDist > x) x = relDist; // Serial.printf("%d %f\n", i, relDist); } diff --git a/src/Stepper.h b/src/Stepper.h index bd200f5..fbaed34 100644 --- a/src/Stepper.h +++ b/src/Stepper.h @@ -51,8 +51,8 @@ namespace TeensyStep // compare functions static bool cmpDelta(const Stepper* a, const Stepper* b) { return a->A > b->A; } static bool cmpAcc(const Stepper* a, const Stepper* b) { return a->a < b->a; } - static bool cmpVmin(const Stepper* a, const Stepper* b) { return std::abs(a->vMax) < std::abs(b->vMax); } - static bool cmpVmax(const Stepper* a, const Stepper* b) { return std::abs(a->vMax) > std::abs(b->vMax); } + static bool cmpVmin(const Stepper* a, const Stepper* b) { return abs(a->vMax) < abs(b->vMax); } + static bool cmpVmax(const Stepper* a, const Stepper* b) { return abs(a->vMax) > abs(b->vMax); } // Pin & Dir registers #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) From cd4bd9e56f0e7f4239d65c66af184f41dafc5926 Mon Sep 17 00:00:00 2001 From: luni64 Date: Tue, 29 Mar 2022 20:46:00 +0200 Subject: [PATCH 3/5] bump version --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 5730af6..bf6baef 100644 --- a/library.json +++ b/library.json @@ -14,7 +14,7 @@ "maintainer": true }, "homepage": "https://luni64.github.io/TeensyStep", - "version": "2.3.1", + "version": "2.3.2", "frameworks": "arduino", "platforms": ["Teensy", "stm32"] } diff --git a/library.properties b/library.properties index 9d057a6..7169caa 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TeensyStep -version=2.3.1 +version=2.3.2 author=luni64 maintainer=luni64 sentence=High speed stepper driver for PJRC Teensy boards (T3.0 - T3.6) and STM32F4 From c10de78c532109c97c25c1602a600a7801b574ae Mon Sep 17 00:00:00 2001 From: Florian Rau Date: Tue, 14 Jun 2022 14:59:09 +0200 Subject: [PATCH 4/5] add definition of static constexpr members --- src/Stepper.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Stepper.cpp b/src/Stepper.cpp index 6898fe8..480d249 100644 --- a/src/Stepper.cpp +++ b/src/Stepper.cpp @@ -3,6 +3,12 @@ namespace TeensyStep { + constexpr int32_t Stepper::vMaxMax; + constexpr uint32_t Stepper::aMax; + constexpr uint32_t Stepper::vMaxDefault; + constexpr uint32_t Stepper::vPullInOutDefault; + constexpr uint32_t Stepper::aDefault; + Stepper::Stepper(const int _stepPin, const int _dirPin) : current(0), stepPin(_stepPin), dirPin(_dirPin) { From e8e2be44f55d167c6db81bbc45e47dcd386bb018 Mon Sep 17 00:00:00 2001 From: Jeppe Klitgaard Date: Tue, 12 Jul 2022 13:16:59 +0200 Subject: [PATCH 5/5] fix: timers on STM32F411xE boards --- src/timer/stm32/TimerField.cpp | 11 ++++++++++- src/timer/stm32/TimerField.h | 9 ++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/timer/stm32/TimerField.cpp b/src/timer/stm32/TimerField.cpp index e644b00..a6386eb 100644 --- a/src/timer/stm32/TimerField.cpp +++ b/src/timer/stm32/TimerField.cpp @@ -1,6 +1,15 @@ #if defined(STM32F4xx) #include "TimerField.h" int TimerField::instances = 0; -TIM_TypeDef* TimerField::timer_mapping[MAX_TIMERS] = { TIM1, TIM2, TIM4, TIM5, TIM6, TIM7, TIM8, TIM9, TIM10, TIM11, TIM12, TIM14 }; + // TIM3 and TIM13 used by HAL/FreeRTOS? doesn't work well to use. + +// --- Different boards. See TimerField.h for more +#if defined(STM32F429xx) +TIM_TypeDef* TimerField::timer_mapping[MAX_TIMERS] = { TIM1, TIM2, TIM4, TIM5, TIM6, TIM7, TIM8, TIM9, TIM10, TIM11, TIM12, TIM14 }; + +#elif defined(STM32F411xE) +TIM_TypeDef* TimerField::timer_mapping[MAX_TIMERS] = { TIM1, TIM2, TIM4, TIM5, TIM9, TIM10, TIM11 }; +#endif + #endif diff --git a/src/timer/stm32/TimerField.h b/src/timer/stm32/TimerField.h index 0e515cf..d87352a 100644 --- a/src/timer/stm32/TimerField.h +++ b/src/timer/stm32/TimerField.h @@ -6,8 +6,15 @@ #include "../TF_Handler.h" - +// --- Different boards: +#if defined(STM32F429xx) #define MAX_TIMERS 12 +#elif defined(STM32F411xE) +#define MAX_TIMERS 7 +#else +#error Board not currently supported. See: https://github.com/luni64/TeensyStep/issues/137 +#endif + class TimerField { public: