Skip to content

Commit

Permalink
adding a patch file for AccelStepper
Browse files Browse the repository at this point in the history
comments cleanup
  • Loading branch information
sq7bti committed Sep 17, 2014
1 parent 369aa92 commit 9acade1
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 4 deletions.
110 changes: 110 additions & 0 deletions AccelStepper.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
diff --git a/AccelStepper.cpp b/AccelStepper.cpp
index 1714788..7674368 100644
--- a/AccelStepper.cpp
+++ b/AccelStepper.cpp
@@ -189,7 +189,7 @@ boolean AccelStepper::run()
return _speed != 0.0 || distanceToGo() != 0;
}

-AccelStepper::AccelStepper(uint8_t interface, uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, bool enable)
+void AccelStepper::begin(uint8_t interface, uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, bool enable)
{
_interface = interface;
_currentPos = 0;
diff --git a/AccelStepper.h b/AccelStepper.h
index cc6b6dc..084aad6 100644
--- a/AccelStepper.h
+++ b/AccelStepper.h
@@ -287,7 +287,8 @@ public:
/// to pin 5.
/// \param[in] enable If this is true (the default), enableOutputs() will be called to enable
/// the output pins at construction time.
- AccelStepper(uint8_t interface = AccelStepper::FULL4WIRE, uint8_t pin1 = 2, uint8_t pin2 = 3, uint8_t pin3 = 4, uint8_t pin4 = 5, bool enable = true);
+ AccelStepper() {};
+ void begin(uint8_t interface = AccelStepper::FULL4WIRE, uint8_t pin1 = 2, uint8_t pin2 = 3, uint8_t pin3 = 4, uint8_t pin4 = 5, bool enable = true);

/// Alternate Constructor which will call your own functions for forward and backward steps.
/// You can have multiple simultaneous steppers, all moving
@@ -435,6 +436,29 @@ public:
/// \param[in] enableInvert True for inverted enable pin, false (default) for non-inverted
void setPinsInverted(bool pin1Invert, bool pin2Invert, bool pin3Invert, bool pin4Invert, bool enableInvert);

+ /// The current interval between steps in microseconds.
+ /// 0 means the motor is currently stopped with _speed == 0
+ unsigned long _stepInterval;
+
+ /// Current direction motor is spinning in
+ boolean _direction; // 1 == CW
+
+ /// The current absolution position in steps.
+ long _currentPos; // Steps
+
+ /// The target position in steps. The AccelStepper library will move the
+ /// motor from the _currentPos to the _targetPos, taking into account the
+ /// max speed, acceleration and deceleration
+ long _targetPos; // Steps
+
+ /// The current motos speed in steps per second
+ /// Positive is clockwise
+ float _speed; // Steps per second
+
+ /// Arduino pin number assignments for the 2 or 4 pins required to interface to the
+ /// stepper motor or driver
+ uint8_t _pin[4];
+
protected:

/// \brief Direction indicator
@@ -515,31 +539,14 @@ protected:
/// pin3, pin4.
/// \param[in] step The current step phase number (0 to 7)
virtual void step8(long step);
-
private:
/// Number of pins on the stepper motor. Permits 2 or 4. 2 pins is a
/// bipolar, and 4 pins is a unipolar.
uint8_t _interface; // 0, 1, 2, 4, 8, See MotorInterfaceType

- /// Arduino pin number assignments for the 2 or 4 pins required to interface to the
- /// stepper motor or driver
- uint8_t _pin[4];
-
/// Whether the _pins is inverted or not
uint8_t _pinInverted[4];

- /// The current absolution position in steps.
- long _currentPos; // Steps
-
- /// The target position in steps. The AccelStepper library will move the
- /// motor from the _currentPos to the _targetPos, taking into account the
- /// max speed, acceleration and deceleration
- long _targetPos; // Steps
-
- /// The current motos speed in steps per second
- /// Positive is clockwise
- float _speed; // Steps per second
-
/// The maximum permitted speed in steps per second. Must be > 0.
float _maxSpeed;

@@ -548,10 +555,6 @@ private:
float _acceleration;
float _sqrt_twoa; // Precomputed sqrt(2*_acceleration)

- /// The current interval between steps in microseconds.
- /// 0 means the motor is currently stopped with _speed == 0
- unsigned long _stepInterval;
-
/// The last step time in microseconds
unsigned long _lastStepTime;

@@ -588,9 +591,6 @@ private:
/// Min step size in microseconds based on maxSpeed
float _cmin; // at max speed

- /// Current direction motor is spinning in
- boolean _direction; // 1 == CW
-
};

/// @example Random.pde
7 changes: 3 additions & 4 deletions iAccelStepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void iAccelStepper::ISR(void) {
_state[id] = false;

// prepare for the next period
// rising edge - calculate everything necessary and calculate _stepInterval
// falling edge - calculate everything necessary and calculate _stepInterval
computeNewSpeed();

if(direction[id] != _direction) {
Expand Down Expand Up @@ -64,7 +64,7 @@ void iAccelStepper::ISR(void) {

void timerISR0(void) { me[0]->ISR(); }
void timerISR1(void) { me[1]->ISR(); }
void timerISR2(void) { me[2]->ISR(); }
//void timerISR2(void) { me[2]->ISR(); }
//void timerISR3(void) { me[3]->ISR(); }
//void timerISR4(void) { me[4]->ISR(); }

Expand Down Expand Up @@ -128,9 +128,8 @@ void iAccelStepper::moveTo(long absolute)
HWREG(_port_step[id]) = 0;
_state[id] = false;

//TimerLoadSet(g_ulTIMERBase[id], TIMER_A, ulPeriod);
//TimerLoadSet(g_ulTIMERBase[id], TIMER_A, _stepInterval - ulPeriod);
HWREG(g_ulTIMERBase[id] + TIMER_O_TAILR) = _stepInterval - ulPeriod;
// HWREG(g_ulTIMERBase[id] + TIMER_O_TAILR) = ulPeriod;
//TimerEnable(g_ulTIMERBase[id], TIMER_A);
HWREG(g_ulTIMERBase[id] + TIMER_O_CTL) |= TIMER_A & (TIMER_CTL_TAEN | TIMER_CTL_TBEN);
}
Expand Down

0 comments on commit 9acade1

Please sign in to comment.