Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit eb649d3e92b04ce40dbc54d83fdca87a96ede910 1 parent d7611f4
Alexander Danilov authored January 03, 2013

Showing 2 changed files with 23 additions and 6 deletions. Show diff stats Hide diff stats

  1. 18  config.h
  2. 11  stepper.c
18  config.h
@@ -34,13 +34,19 @@
34 34
 #define Y_STEP_BIT         1  // Uno Digital Pin 3
35 35
 #define Z_STEP_BIT         2  // Uno Digital Pin 4
36 36
 #define A_STEP_BIT         3
37  
-#define X_DIRECTION_BIT    4  // Uno Digital Pin 5
38  
-#define Y_DIRECTION_BIT    5  // Uno Digital Pin 6
39  
-#define Z_DIRECTION_BIT    6  // Uno Digital Pin 7
40  
-#define A_DIRECTION_BIT    7
  37
+#define DIRECTION_DDR      DDRD
  38
+#define DIRECTION_PORT     PORTD
  39
+#define X_DIRECTION_BIT    2  // Uno Digital Pin 5
  40
+#define Y_DIRECTION_BIT    3  // Uno Digital Pin 6
  41
+#define Z_DIRECTION_BIT    4  // Uno Digital Pin 7
  42
+#define A_DIRECTION_BIT    5
41 43
 #define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)|(1<<A_STEP_BIT)) // All step bits
42 44
 #define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)|(1<<A_DIRECTION_BIT)) // All direction bits
  45
+#ifdef DIRECTION_DDR
  46
+#define STEPPING_MASK STEP_MASK
  47
+#else
43 48
 #define STEPPING_MASK (STEP_MASK | DIRECTION_MASK) // All stepping-related bits (step/direction)
  49
+#endif
44 50
 
45 51
 #define STEPPERS_DISABLE_DDR    DDRB
46 52
 #define STEPPERS_DISABLE_PORT   PORTB
@@ -58,7 +64,7 @@
58 64
 #define LIMIT_INT       PCIE0  // Pin change interrupt enable pin
59 65
 #define LIMIT_INT_vect  PCINT0_vect
60 66
 #define LIMIT_PCMSK     PCMSK0 // Pin change interrupt register
61  
-#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
  67
+#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)|(1<<A_LIMIT_BIT)) // All limit bits
62 68
 
63 69
 #define SPINDLE_ENABLE_DDR   DDRC
64 70
 #define SPINDLE_ENABLE_PORT  PORTC
@@ -107,7 +113,7 @@
107 113
 #define DEFAULT_FEEDRATE 250.0
108 114
 #define DEFAULT_ACCELERATION (DEFAULT_FEEDRATE*60*60/10.0) // mm/min^2
109 115
 #define DEFAULT_JUNCTION_DEVIATION 0.05 // mm
110  
-#define DEFAULT_STEPPING_INVERT_MASK ((1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT))
  116
+#define DEFAULT_STEPPING_INVERT_MASK ((1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)|(1<<A_DIRECTION_BIT))
111 117
 #define DEFAULT_REPORT_INCHES 0 // false
112 118
 #define DEFAULT_AUTO_START 1 // true
113 119
 #define DEFAULT_INVERT_ST_ENABLE 0 // false
11  stepper.c
@@ -150,7 +150,11 @@ ISR(TIMER1_COMPA_vect)
150 150
   if (busy) { return; } // The busy-flag is used to avoid reentering this interrupt
151 151
 
152 152
   // Set the direction pins a couple of nanoseconds before we step the steppers
  153
+#ifdef DIRECTION_DDR
  154
+  DIRECTION_PORT = (DIRECTION_PORT & ~DIRECTION_MASK) | (out_bits & DIRECTION_MASK);
  155
+#else
153 156
   STEPPING_PORT = (STEPPING_PORT & ~DIRECTION_MASK) | (out_bits & DIRECTION_MASK);
  157
+#endif
154 158
   // Then pulse the stepping pins
155 159
   #ifdef STEP_PULSE_DELAY
156 160
     step_bits = (STEPPING_PORT & ~STEP_MASK) | out_bits; // Store out_bits to prevent overwriting.
@@ -356,7 +360,14 @@ void st_init()
356 360
 {
357 361
   // Configure directions of interface pins
358 362
   STEPPING_DDR |= STEPPING_MASK;
  363
+
  364
+#ifdef DIRECTION_DDR
  365
+  DIRECTION_DDR |= DIRECTION_MASK;
  366
+  DIRECTION_PORT = (DIRECTION_PORT & ~DIRECTION_MASK) | settings.invert_mask;
  367
+  STEPPING_PORT = (STEPPING_PORT & ~STEPPING_MASK);
  368
+#else
359 369
   STEPPING_PORT = (STEPPING_PORT & ~STEPPING_MASK) | settings.invert_mask;
  370
+#endif
360 371
   STEPPERS_DISABLE_DDR |= 1<<STEPPERS_DISABLE_BIT;
361 372
 
362 373
   // waveform generation = 0100 = CTC

0 notes on commit eb649d3

Please sign in to comment.
Something went wrong with that request. Please try again.