a4988 wait 1ms when coming out of sleep (#1597)

This commit is contained in:
WeekendWarrior1 2021-03-14 11:29:31 +11:00 committed by GitHub
parent 848a5f1680
commit 08998caabc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

@ -11,6 +11,7 @@ void A4988::setup() {
if (this->sleep_pin_ != nullptr) { if (this->sleep_pin_ != nullptr) {
this->sleep_pin_->setup(); this->sleep_pin_->setup();
this->sleep_pin_->digital_write(false); this->sleep_pin_->digital_write(false);
this->sleep_pin_state_ = false;
} }
this->step_pin_->setup(); this->step_pin_->setup();
this->step_pin_->digital_write(false); this->step_pin_->digital_write(false);
@ -27,7 +28,12 @@ void A4988::dump_config() {
void A4988::loop() { void A4988::loop() {
bool at_target = this->has_reached_target(); bool at_target = this->has_reached_target();
if (this->sleep_pin_ != nullptr) { if (this->sleep_pin_ != nullptr) {
bool sleep_rising_edge = !sleep_pin_state_ & !at_target;
this->sleep_pin_->digital_write(!at_target); this->sleep_pin_->digital_write(!at_target);
this->sleep_pin_state_ = !at_target;
if (sleep_rising_edge) {
delayMicroseconds(1000);
}
} }
if (at_target) { if (at_target) {
this->high_freq_.stop(); this->high_freq_.stop();

View file

@ -21,6 +21,7 @@ class A4988 : public stepper::Stepper, public Component {
GPIOPin *step_pin_; GPIOPin *step_pin_;
GPIOPin *dir_pin_; GPIOPin *dir_pin_;
GPIOPin *sleep_pin_{nullptr}; GPIOPin *sleep_pin_{nullptr};
bool sleep_pin_state_;
HighFrequencyLoopRequester high_freq_; HighFrequencyLoopRequester high_freq_;
}; };