Skip to content

Commit

Permalink
Set direction pin level earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Aug 7, 2023
1 parent bdd6033 commit 482d04b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ TEST_CASE("ContinuousStepper_TeensyTimerTool::spin()") {
REQUIRE(stepper.speed() == 10);

CHECK_ARDUINO_LOG({
{0'000, "digitalWrite(11, HIGH)"},
{0'000, "PeriodicTimer::stop()"},
{0'000, "PeriodicTimer::setPeriod(50000)"},
{0'000, "PeriodicTimer::start()"},
Expand All @@ -40,6 +41,7 @@ TEST_CASE("ContinuousStepper_TeensyTimerTool::spin()") {
REQUIRE(stepper.speed() == -10);

CHECK_ARDUINO_LOG({
{0'000, "digitalWrite(11, LOW)"},
{0'000, "PeriodicTimer::stop()"},
{0'000, "PeriodicTimer::setPeriod(50000)"},
{0'000, "PeriodicTimer::start()"},
Expand All @@ -58,10 +60,10 @@ TEST_CASE("ContinuousStepper_TeensyTimerTool::spin()") {
REQUIRE(stepper.speed() == 100);

CHECK_ARDUINO_LOG({
{0'000, "digitalWrite(11, HIGH)"},
{0'000, "PeriodicTimer::stop()"},
{0'000, "PeriodicTimer::setPeriod(15811)"},
{0'000, "PeriodicTimer::start()"},
{15'811, "digitalWrite(11, HIGH)"},
{15'811, "digitalWrite(10, HIGH)"},
{15'811, "PeriodicTimer::stop()"},
{15'811, "PeriodicTimer::setPeriod(10541)"},
Expand Down Expand Up @@ -156,6 +158,7 @@ TEST_CASE("ContinuousStepper_TeensyTimerTool::spin()") {
{182'478, "PeriodicTimer::stop()"},
{182'478, "PeriodicTimer::setPeriod(15811)"},
{182'478, "PeriodicTimer::start()"},
{198'289, "digitalWrite(11, LOW)"},
{198'289, "PeriodicTimer::stop()"},
{198'289, "PeriodicTimer::setPeriod(15811)"},
{198'289, "PeriodicTimer::start()"},
Expand All @@ -165,7 +168,6 @@ TEST_CASE("ContinuousStepper_TeensyTimerTool::spin()") {
{229'911, "PeriodicTimer::stop()"},
{229'911, "PeriodicTimer::setPeriod(13064)"},
{229'911, "PeriodicTimer::start()"},
{242'975, "digitalWrite(11, LOW)"},
{242'975, "digitalWrite(10, LOW)"},
{242'975, "PeriodicTimer::stop()"},
{242'975, "PeriodicTimer::setPeriod(9739)"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ TEST_CASE("ContinuousStepper_Timer1::spin()") {
REQUIRE(stepper.speed() == 10);

CHECK_ARDUINO_LOG({
{0'000, "digitalWrite(11, HIGH)"},
{0'000, "TimerOne::stop()"},
{0'000, "TimerOne::setPeriod(50000)"},
{0'000, "TimerOne::start()"},
Expand All @@ -40,6 +41,7 @@ TEST_CASE("ContinuousStepper_Timer1::spin()") {
REQUIRE(stepper.speed() == -10);

CHECK_ARDUINO_LOG({
{0'000, "digitalWrite(11, LOW)"},
{0'000, "TimerOne::stop()"},
{0'000, "TimerOne::setPeriod(50000)"},
{0'000, "TimerOne::start()"},
Expand All @@ -58,10 +60,10 @@ TEST_CASE("ContinuousStepper_Timer1::spin()") {
REQUIRE(stepper.speed() == 100);

CHECK_ARDUINO_LOG({
{0'000, "digitalWrite(11, HIGH)"},
{0'000, "TimerOne::stop()"},
{0'000, "TimerOne::setPeriod(15811)"},
{0'000, "TimerOne::start()"},
{15'811, "digitalWrite(11, HIGH)"},
{15'811, "digitalWrite(10, HIGH)"},
{15'811, "TimerOne::stop()"},
{15'811, "TimerOne::setPeriod(10541)"},
Expand Down Expand Up @@ -156,6 +158,7 @@ TEST_CASE("ContinuousStepper_Timer1::spin()") {
{182'478, "TimerOne::stop()"},
{182'478, "TimerOne::setPeriod(15811)"},
{182'478, "TimerOne::start()"},
{198'289, "digitalWrite(11, LOW)"},
{198'289, "TimerOne::stop()"},
{198'289, "TimerOne::setPeriod(15811)"},
{198'289, "TimerOne::start()"},
Expand All @@ -165,7 +168,6 @@ TEST_CASE("ContinuousStepper_Timer1::spin()") {
{229'911, "TimerOne::stop()"},
{229'911, "TimerOne::setPeriod(13064)"},
{229'911, "TimerOne::start()"},
{242'975, "digitalWrite(11, LOW)"},
{242'975, "digitalWrite(10, LOW)"},
{242'975, "TimerOne::stop()"},
{242'975, "TimerOne::setPeriod(9739)"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ TEST_CASE("ContinuousStepper_Timer3::spin()") {
REQUIRE(stepper.speed() == 10);

CHECK_ARDUINO_LOG({
{0'000, "digitalWrite(11, HIGH)"},
{0'000, "TimerThree::stop()"},
{0'000, "TimerThree::setPeriod(50000)"},
{0'000, "TimerThree::start()"},
Expand All @@ -40,6 +41,7 @@ TEST_CASE("ContinuousStepper_Timer3::spin()") {
REQUIRE(stepper.speed() == -10);

CHECK_ARDUINO_LOG({
{0'000, "digitalWrite(11, LOW)"},
{0'000, "TimerThree::stop()"},
{0'000, "TimerThree::setPeriod(50000)"},
{0'000, "TimerThree::start()"},
Expand All @@ -58,10 +60,10 @@ TEST_CASE("ContinuousStepper_Timer3::spin()") {
REQUIRE(stepper.speed() == 100);

CHECK_ARDUINO_LOG({
{0'000, "digitalWrite(11, HIGH)"},
{0'000, "TimerThree::stop()"},
{0'000, "TimerThree::setPeriod(15811)"},
{0'000, "TimerThree::start()"},
{15'811, "digitalWrite(11, HIGH)"},
{15'811, "digitalWrite(10, HIGH)"},
{15'811, "TimerThree::stop()"},
{15'811, "TimerThree::setPeriod(10541)"},
Expand Down Expand Up @@ -156,6 +158,7 @@ TEST_CASE("ContinuousStepper_Timer3::spin()") {
{182'478, "TimerThree::stop()"},
{182'478, "TimerThree::setPeriod(15811)"},
{182'478, "TimerThree::start()"},
{198'289, "digitalWrite(11, LOW)"},
{198'289, "TimerThree::stop()"},
{198'289, "TimerThree::setPeriod(15811)"},
{198'289, "TimerThree::start()"},
Expand All @@ -165,7 +168,6 @@ TEST_CASE("ContinuousStepper_Timer3::spin()") {
{229'911, "TimerThree::stop()"},
{229'911, "TimerThree::setPeriod(13064)"},
{229'911, "TimerThree::start()"},
{242'975, "digitalWrite(11, LOW)"},
{242'975, "digitalWrite(10, LOW)"},
{242'975, "TimerThree::stop()"},
{242'975, "TimerThree::setPeriod(9739)"},
Expand Down
2 changes: 1 addition & 1 deletion extras/tests/ContinuousStepperTests/powerOn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TEST_CASE("ContinuousStepper::powerOn()") {
REQUIRE(stepper.isSpinning() == true);
CHECK(stepper.speed() == 100);
CHECK_ARDUINO_LOG({
{15'811, "digitalWrite(11, HIGH)"}, // DIR
{0'000, "digitalWrite(11, HIGH)"}, // DIR
{15'811, "digitalWrite(10, HIGH)"}, // 10.541 ms
{26'352, "digitalWrite(10, LOW)"}, // 8.624 ms
{34'976, "digitalWrite(10, HIGH)"}, // 7.507 ms
Expand Down
4 changes: 2 additions & 2 deletions extras/tests/ContinuousStepperTests/spin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TEST_CASE("ContinuousStepper::spin()") {
REQUIRE(stepper.speed() == 100);

CHECK_ARDUINO_LOG({
{15'811, "digitalWrite(11, HIGH)"}, // DIR
{0'000, "digitalWrite(11, HIGH)"}, // DIR
{15'811, "digitalWrite(10, HIGH)"}, // 10.541 ms
{26'352, "digitalWrite(10, LOW)"}, // 8.624 ms
{34'976, "digitalWrite(10, HIGH)"}, // 7.507 ms
Expand Down Expand Up @@ -71,7 +71,7 @@ TEST_CASE("ContinuousStepper::spin()") {
{143'218, "digitalWrite(10, HIGH)"}, // 10.325 ms
{153'543, "digitalWrite(10, LOW)"}, // 13.124 ms
{166'667, "digitalWrite(10, HIGH)"}, // 76.308 ms
{242'975, "digitalWrite(11, LOW)"}, // DIR
{198'289, "digitalWrite(11, LOW)"}, // DIR
{242'975, "digitalWrite(10, LOW)"}, // 9.739 ms
{252'714, "digitalWrite(10, HIGH)"}, // 8.186 ms
{260'900, "digitalWrite(10, LOW)"}, // 7.219 ms
Expand Down
6 changes: 4 additions & 2 deletions src/ContinuousStepperBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class ContinuousStepperBase {
protected:
void tick() {
if (_status == STEP) {
writeDir();
if (_stepLevel == LOW) {
writeStep(HIGH);
_stepLevel = HIGH;
Expand All @@ -111,6 +110,7 @@ class ContinuousStepperBase {
return _stepPin;
}

private:
void writeDir() {
bool level = _currentSpeed >= 0 ? HIGH : LOW;
if (level == _dirLevel)
Expand All @@ -119,7 +119,6 @@ class ContinuousStepperBase {
_dirLevel = level;
}

private:
void updateSpeed() {
float_t speedIncrement = _period ? _acceleration * _period / oneSecond : _minSpeedForAcceleration;

Expand Down Expand Up @@ -152,6 +151,9 @@ class ContinuousStepperBase {
if (needsDoubleSpeed())
_period /= 2;

if (_period)
writeDir();

setPeriod(_period);
}

Expand Down
1 change: 0 additions & 1 deletion src/ContinuousStepperWithOscillator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class ContinuousStepperWithOscillator : public ContinuousStepperBase {

void setPeriod(unsigned long period) override {
if (period) {
writeDir();
startOscillator(1e6 / period);
} else {
stopOscillator();
Expand Down

0 comments on commit 482d04b

Please sign in to comment.