Permalink
Browse files

Add macro DIRECTION_DDR and DIRECTION_POR to be able to move dir and …

…step pins to different ports.

Signed-off-by: Alexander Danilov <alexander.a.danilov@gmail.com>
  • Loading branch information...
1 parent d7611f4 commit eb649d3e92b04ce40dbc54d83fdca87a96ede910 @daapp committed Jan 3, 2013
Showing with 23 additions and 6 deletions.
  1. +12 −6 config.h
  2. +11 −0 stepper.c
View
@@ -34,13 +34,19 @@
#define Y_STEP_BIT 1 // Uno Digital Pin 3
#define Z_STEP_BIT 2 // Uno Digital Pin 4
#define A_STEP_BIT 3
-#define X_DIRECTION_BIT 4 // Uno Digital Pin 5
-#define Y_DIRECTION_BIT 5 // Uno Digital Pin 6
-#define Z_DIRECTION_BIT 6 // Uno Digital Pin 7
-#define A_DIRECTION_BIT 7
+#define DIRECTION_DDR DDRD
+#define DIRECTION_PORT PORTD
+#define X_DIRECTION_BIT 2 // Uno Digital Pin 5
+#define Y_DIRECTION_BIT 3 // Uno Digital Pin 6
+#define Z_DIRECTION_BIT 4 // Uno Digital Pin 7
+#define A_DIRECTION_BIT 5
#define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)|(1<<A_STEP_BIT)) // All step bits
#define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)|(1<<A_DIRECTION_BIT)) // All direction bits
+#ifdef DIRECTION_DDR
+#define STEPPING_MASK STEP_MASK
+#else
#define STEPPING_MASK (STEP_MASK | DIRECTION_MASK) // All stepping-related bits (step/direction)
+#endif
#define STEPPERS_DISABLE_DDR DDRB
#define STEPPERS_DISABLE_PORT PORTB
@@ -58,7 +64,7 @@
#define LIMIT_INT PCIE0 // Pin change interrupt enable pin
#define LIMIT_INT_vect PCINT0_vect
#define LIMIT_PCMSK PCMSK0 // Pin change interrupt register
-#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
+#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)|(1<<A_LIMIT_BIT)) // All limit bits
#define SPINDLE_ENABLE_DDR DDRC
#define SPINDLE_ENABLE_PORT PORTC
@@ -107,7 +113,7 @@
#define DEFAULT_FEEDRATE 250.0
#define DEFAULT_ACCELERATION (DEFAULT_FEEDRATE*60*60/10.0) // mm/min^2
#define DEFAULT_JUNCTION_DEVIATION 0.05 // mm
-#define DEFAULT_STEPPING_INVERT_MASK ((1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT))
+#define DEFAULT_STEPPING_INVERT_MASK ((1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)|(1<<A_DIRECTION_BIT))
#define DEFAULT_REPORT_INCHES 0 // false
#define DEFAULT_AUTO_START 1 // true
#define DEFAULT_INVERT_ST_ENABLE 0 // false
View
@@ -150,7 +150,11 @@ ISR(TIMER1_COMPA_vect)
if (busy) { return; } // The busy-flag is used to avoid reentering this interrupt
// Set the direction pins a couple of nanoseconds before we step the steppers
+#ifdef DIRECTION_DDR
+ DIRECTION_PORT = (DIRECTION_PORT & ~DIRECTION_MASK) | (out_bits & DIRECTION_MASK);
+#else
STEPPING_PORT = (STEPPING_PORT & ~DIRECTION_MASK) | (out_bits & DIRECTION_MASK);
+#endif
// Then pulse the stepping pins
#ifdef STEP_PULSE_DELAY
step_bits = (STEPPING_PORT & ~STEP_MASK) | out_bits; // Store out_bits to prevent overwriting.
@@ -356,7 +360,14 @@ void st_init()
{
// Configure directions of interface pins
STEPPING_DDR |= STEPPING_MASK;
+
+#ifdef DIRECTION_DDR
+ DIRECTION_DDR |= DIRECTION_MASK;
+ DIRECTION_PORT = (DIRECTION_PORT & ~DIRECTION_MASK) | settings.invert_mask;
+ STEPPING_PORT = (STEPPING_PORT & ~STEPPING_MASK);
+#else
STEPPING_PORT = (STEPPING_PORT & ~STEPPING_MASK) | settings.invert_mask;
+#endif
STEPPERS_DISABLE_DDR |= 1<<STEPPERS_DISABLE_BIT;
// waveform generation = 0100 = CTC

0 comments on commit eb649d3

Please sign in to comment.