Skip to content

Commit

Permalink
AccelStepper members as protected instead of public
Browse files Browse the repository at this point in the history
resource references moved over from header to cpp
last step during the transition from high to low (distanceToGo == 0)
computeNewSpeed already called in parent moveTo()
ISR's as friend
  • Loading branch information
sq7bti committed Sep 19, 2014
1 parent 78cb23c commit 399ce36
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 65 deletions.
12 changes: 6 additions & 6 deletions AccelStepper.patch
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ index 1714788..7674368 100644
_interface = interface;
_currentPos = 0;
diff --git a/AccelStepper.h b/AccelStepper.h
index cc6b6dc..084aad6 100644
index cc6b6dc..9fdb983 100644
--- a/AccelStepper.h
+++ b/AccelStepper.h
@@ -287,7 +287,8 @@ public:
Expand All @@ -25,9 +25,9 @@ index cc6b6dc..084aad6 100644

/// 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);
@@ -437,6 +438,29 @@ public:

protected:

+ /// The current interval between steps in microseconds.
+ /// 0 means the motor is currently stopped with _speed == 0
Expand All @@ -52,9 +52,9 @@ index cc6b6dc..084aad6 100644
+ /// stepper motor or driver
+ uint8_t _pin[4];
+
protected:

/// \brief Direction indicator
/// Symbolic names for the direction the motor is turning
typedef enum
@@ -515,31 +539,14 @@ protected:
/// pin3, pin4.
/// \param[in] step The current step phase number (0 to 7)
Expand Down
78 changes: 56 additions & 22 deletions iAccelStepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,43 @@
#include "inc/hw_gpio.h"
#include "inc/hw_timer.h"

//*****************************************************************************
//
// The list of Timer peripherals.
//
//*****************************************************************************
static const unsigned long g_ulTIMERPeriph[MAX_INST] =
{
#if defined(PART_TM4C1233H6PM) || defined(PART_LM4F120H5QR)
// SYSCTL_PERIPH_TIMER0, // wiring_analog.c analogWrite()
// SYSCTL_PERIPH_TIMER1,
SYSCTL_PERIPH_TIMER2,
SYSCTL_PERIPH_TIMER3
// SYSCTL_PERIPH_TIMER4, // Tone.c
// SYSCTL_PERIPH_TIMER5, // wiring.c - millis() micros()
// SYSCTL_PERIPH_TIMER6,
// SYSCTL_PERIPH_TIMER7
#else
#error "**** No PART defined or unsupported PART ****"
#endif
};

static const unsigned long g_ulTIMERBase[MAX_INST] =
{
#if defined(PART_TM4C1233H6PM) || defined(PART_LM4F120H5QR)
// TIMER0_BASE, // wiring_analog.c analogWrite()
// TIMER1_BASE,
TIMER2_BASE,
TIMER3_BASE
// TIMER4_BASE, // Tone.c
// TIMER5_BASE, // wiring.c - millis() micros()
// TIMER6_BASE,
// TIMER7_BASE
#else
#error "**** No PART defined or unsupported PART ****"
#endif
};

static iAccelStepper* me[MAX_INST];
static uint32_t _port_step[MAX_INST];
static uint8_t _pin_step[MAX_INST];
Expand Down Expand Up @@ -30,35 +67,34 @@ void iAccelStepper::ISR(void) {
HWREG(_port_dir[id]) = _direction?_pin_dir[id]:0;
}

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

} else {

// either fire the timer again for another period or switch it off when the move is finished
if((_stepInterval == 0) || (abs(distanceToGo()) < 1)) {
//TimerDisable(g_ulTIMERBase[id], TIMER_A);
HWREG(g_ulTIMERBase[id] + TIMER_O_CTL) &= ~(TIMER_A & (TIMER_CTL_TAEN | TIMER_CTL_TBEN));
running = false;
} else {
_state[id] = true;

if(_direction == DIRECTION_CW)
// Clockwise
++_currentPos;
else
// Anticlockwise
--_currentPos;

//TimerLoadSet(g_ulTIMERBase[id], TIMER_A, ulPeriod);
HWREG(g_ulTIMERBase[id] + TIMER_O_TAILR) = ulPeriod;
HWREG(_port_step[id]) = _pin_step[id];
HWREG(_port_step[id]) = 0;
//TimerLoadSet(g_ulTIMERBase[id], TIMER_A, _stepInterval - ulPeriod);
HWREG(g_ulTIMERBase[id] + TIMER_O_TAILR) = _stepInterval - ulPeriod;
//TimerEnable(g_ulTIMERBase[id], TIMER_A);
HWREG(g_ulTIMERBase[id] + TIMER_O_CTL) |= TIMER_A & (TIMER_CTL_TAEN | TIMER_CTL_TBEN);
}
} else {

_state[id] = true;

if(_direction == DIRECTION_CW)
// Clockwise
++_currentPos;
else
// Anticlockwise
--_currentPos;

//TimerLoadSet(g_ulTIMERBase[id], TIMER_A, ulPeriod);
HWREG(g_ulTIMERBase[id] + TIMER_O_TAILR) = ulPeriod;
HWREG(_port_step[id]) = _pin_step[id];
//TimerEnable(g_ulTIMERBase[id], TIMER_A);
HWREG(g_ulTIMERBase[id] + TIMER_O_CTL) |= TIMER_A & (TIMER_CTL_TAEN | TIMER_CTL_TBEN);
}
}

Expand Down Expand Up @@ -118,8 +154,6 @@ void iAccelStepper::moveTo(long absolute)
if(!running && (distanceToGo() != 0)) {
running = true;

computeNewSpeed();

if(direction[id] != _direction) {
direction[id] = _direction;
HWREG(_port_dir[id]) = _direction?_pin_dir[id]:0;
Expand Down
44 changes: 7 additions & 37 deletions iAccelStepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,6 @@

#define MAX_INST 2

//*****************************************************************************
//
// The list of Timer peripherals.
//
//*****************************************************************************
static const unsigned long g_ulTIMERPeriph[MAX_INST] =
{
#if defined(PART_TM4C1233H6PM) || defined(PART_LM4F120H5QR)
// SYSCTL_PERIPH_TIMER0, // wiring_analog.c analogWrite()
// SYSCTL_PERIPH_TIMER1,
SYSCTL_PERIPH_TIMER2,
SYSCTL_PERIPH_TIMER3
// SYSCTL_PERIPH_TIMER4, // Tone.c
// SYSCTL_PERIPH_TIMER5, // wiring.c - millis() micros()
// SYSCTL_PERIPH_TIMER6,
// SYSCTL_PERIPH_TIMER7
#else
#error "**** No PART defined or unsupported PART ****"
#endif
};

static const unsigned long g_ulTIMERBase[MAX_INST] =
{
#if defined(PART_TM4C1233H6PM) || defined(PART_LM4F120H5QR)
// TIMER0_BASE, // wiring_analog.c analogWrite()
// TIMER1_BASE,
TIMER2_BASE,
TIMER3_BASE
// TIMER4_BASE, // Tone.c
// TIMER5_BASE, // wiring.c - millis() micros()
// TIMER6_BASE,
// TIMER7_BASE
#else
#error "**** No PART defined or unsupported PART ****"
#endif
};

class iAccelStepper : public AccelStepper
{
public:
Expand All @@ -54,7 +17,14 @@ class iAccelStepper : public AccelStepper
void move(long relative);
boolean run(void) { return running; };
unsigned long stepInterval() { return _stepInterval; };

friend void timerISR0();
friend void timerISR1();
// friend void timerISR2();

protected:
void ISR(void);

private:
volatile boolean running;
unsigned int id;
Expand Down

0 comments on commit 399ce36

Please sign in to comment.