Skip to content

Stepper class does not initialize step_delay which can lead to lock-ups #18

Open
@per1234

Description

@per1234

Moved from arduino/Arduino#3300 by @cxrodgers

I was having an intermittent issue where my arduino would occasionally lock up while stepping a stepper. It turned out that it was because I had neglected to call setSpeed explicitly. I had thought that it defaulted to some reasonable value, but upon examining the code, I see that it does not, meaning that step_delay will be whatever random value resides in that memory location.
https://github.com/arduino/Arduino/blob/master/libraries/Stepper/src/Stepper.cpp

Here was my forum posting on this topic.
http://forum.arduino.cc/index.php?topic=327132.0

I believe that the memory is typically set to zero, but when using dynamic memory allocation (for instance: stepper = new Stepper(...), there is no guarantee that this memory location will start at zero. Regardless, it seems dangerous to rely on the memory containing any particular value without being initialized.

I think step_delay should be initialized to zero in the constructor. Alternatively, I think it should be documented that a call to setSpeed is required before calling step.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions