chiark / gitweb /
Merge git://github.com/daid/Marlin into Marlin_v1
authorErik van der Zalm <erik@vdzalm.eu>
Sat, 14 Jul 2012 13:07:14 +0000 (15:07 +0200)
committerErik van der Zalm <erik@vdzalm.eu>
Sat, 14 Jul 2012 13:07:14 +0000 (15:07 +0200)
Added invert step pins to corexy code

Marlin/Configuration.h
Marlin/stepper.cpp
README.md

index d4032a39fb2cc25a7c580f85689df19aae1079db..2da2478d9146accc86421b129187b59b99a3463e 100644 (file)
@@ -35,6 +35,8 @@
 #define MOTHERBOARD 7
 #endif
 
+
+
 //===========================================================================
 //=============================Thermal Settings  ============================
 //===========================================================================
 //=============================Mechanical Settings===========================
 //===========================================================================
 
+// Uncomment the following line to enable CoreXY kinematics
+// #define COREXY
+
 // corse Endstop Settings
 #define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
 
index 6b561289cca19338f1746a29da6229938cf42652..38c18558742b9e36ab7a5519d2f77fc2a2bd4371 100644 (file)
@@ -214,6 +214,12 @@ void st_wake_up() {
   ENABLE_STEPPER_DRIVER_INTERRUPT();  
 }
 
+void step_wait(){
+    for(int8_t i=0; i < 6; i++){
+    }
+}
+  
+
 FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
   unsigned short timer;
   if(step_rate > MAX_STEP_FREQUENCY) step_rate = MAX_STEP_FREQUENCY;
@@ -317,8 +323,10 @@ ISR(TIMER1_COMPA_vect)
     out_bits = current_block->direction_bits;
 
     // Set direction en check limit switches
-    if ((out_bits & (1<<X_AXIS)) != 0) {   // -direction
-      WRITE(X_DIR_PIN, INVERT_X_DIR);
+    if ((out_bits & (1<<X_AXIS)) != 0) {   // stepping along -X axis
+      #if !defined COREXY  //NOT COREXY
+        WRITE(X_DIR_PIN, INVERT_X_DIR);
+      #endif
       count_direction[X_AXIS]=-1;
       CHECK_ENDSTOPS
       {
@@ -333,8 +341,11 @@ ISR(TIMER1_COMPA_vect)
         #endif
       }
     }
-    else { // +direction 
-      WRITE(X_DIR_PIN,!INVERT_X_DIR);
+    else { // +direction
+      #if !defined COREXY  //NOT COREXY
+        WRITE(X_DIR_PIN,!INVERT_X_DIR);
+      #endif
+      
       count_direction[X_AXIS]=1;
       CHECK_ENDSTOPS 
       {
@@ -351,7 +362,9 @@ ISR(TIMER1_COMPA_vect)
     }
 
     if ((out_bits & (1<<Y_AXIS)) != 0) {   // -direction
-      WRITE(Y_DIR_PIN,INVERT_Y_DIR);
+      #if !defined COREXY  //NOT COREXY
+        WRITE(Y_DIR_PIN,INVERT_Y_DIR);
+      #endif
       count_direction[Y_AXIS]=-1;
       CHECK_ENDSTOPS
       {
@@ -367,7 +380,9 @@ ISR(TIMER1_COMPA_vect)
       }
     }
     else { // +direction
-    WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
+      #if !defined COREXY  //NOT COREXY
+        WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
+      #endif
       count_direction[Y_AXIS]=1;
       CHECK_ENDSTOPS
       {
@@ -382,7 +397,28 @@ ISR(TIMER1_COMPA_vect)
         #endif
       }
     }
-
+    
+    
+    #ifdef COREXY  //coreXY kinematics defined
+      if((current_block->steps_x >= current_block->steps_y)&&((out_bits & (1<<X_AXIS)) == 0)){  //+X is major axis
+        WRITE(X_DIR_PIN, !INVERT_X_DIR);
+        WRITE(Y_DIR_PIN, !INVERT_Y_DIR);
+      }
+      if((current_block->steps_x >= current_block->steps_y)&&((out_bits & (1<<X_AXIS)) != 0)){  //-X is major axis
+        WRITE(X_DIR_PIN, INVERT_X_DIR);
+        WRITE(Y_DIR_PIN, INVERT_Y_DIR);
+      }      
+      if((current_block->steps_y > current_block->steps_x)&&((out_bits & (1<<Y_AXIS)) == 0)){  //+Y is major axis
+        WRITE(X_DIR_PIN, !INVERT_X_DIR);
+        WRITE(Y_DIR_PIN, INVERT_Y_DIR);
+      }        
+      if((current_block->steps_y > current_block->steps_x)&&((out_bits & (1<<Y_AXIS)) != 0)){  //-Y is major axis
+        WRITE(X_DIR_PIN, INVERT_X_DIR);
+        WRITE(Y_DIR_PIN, !INVERT_Y_DIR);
+      }  
+    #endif //coreXY
+    
+    
     if ((out_bits & (1<<Z_AXIS)) != 0) {   // -direction
       WRITE(Z_DIR_PIN,INVERT_Z_DIR);
       count_direction[Z_AXIS]=-1;
@@ -446,29 +482,79 @@ ISR(TIMER1_COMPA_vect)
         }
       }    
       #endif //ADVANCE
-      
-      counter_x += current_block->steps_x;
-      if (counter_x > 0) {
-        WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
-        counter_x -= current_block->step_event_count;
-        WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
-        count_position[X_AXIS]+=count_direction[X_AXIS];   
-      }
-
-      counter_y += current_block->steps_y;
-      if (counter_y > 0) {
-        WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
-        counter_y -= current_block->step_event_count;
-        WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
-        count_position[Y_AXIS]+=count_direction[Y_AXIS];
-      }
 
+      #if !defined COREXY      
+        counter_x += current_block->steps_x;
+        if (counter_x > 0) {
+          WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
+          counter_x -= current_block->step_event_count;
+          count_position[X_AXIS]+=count_direction[X_AXIS];   
+          WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
+        }
+  
+        counter_y += current_block->steps_y;
+        if (counter_y > 0) {
+          WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
+          counter_y -= current_block->step_event_count; 
+          count_position[Y_AXIS]+=count_direction[Y_AXIS]; 
+          WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
+        }
+      #endif
+  
+      #ifdef COREXY
+        counter_x += current_block->steps_x;        
+        counter_y += current_block->steps_y;
+        
+        if ((counter_x > 0)&&!(counter_y>0)){  //X step only
+          WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
+          WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
+          counter_x -= current_block->step_event_count; 
+          count_position[X_AXIS]+=count_direction[X_AXIS];         
+          WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
+          WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
+        }
+        
+        if (!(counter_x > 0)&&(counter_y>0)){  //Y step only
+          WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
+          WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
+          counter_y -= current_block->step_event_count; 
+          count_position[Y_AXIS]+=count_direction[Y_AXIS];
+          WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
+          WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
+        }        
+        
+        if ((counter_x > 0)&&(counter_y>0)){  //step in both axes
+          if (((out_bits & (1<<X_AXIS)) == 0)^((out_bits & (1<<Y_AXIS)) == 0)){  //X and Y in different directions
+            WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
+            counter_x -= current_block->step_event_count;             
+            WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
+            step_wait();
+            count_position[X_AXIS]+=count_direction[X_AXIS];
+            count_position[Y_AXIS]+=count_direction[Y_AXIS];
+            WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
+            counter_y -= current_block->step_event_count;
+            WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
+          }
+          else{  //X and Y in same direction
+            WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
+            counter_x -= current_block->step_event_count;             
+            WRITE(X_STEP_PIN, INVERT_X_STEP_PIN) ;
+            step_wait();
+            count_position[X_AXIS]+=count_direction[X_AXIS];
+            count_position[Y_AXIS]+=count_direction[Y_AXIS];
+            WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN); 
+            counter_y -= current_block->step_event_count;    
+            WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);        
+          }
+        }
+      #endif //corexy
+      
       counter_z += current_block->steps_z;
       if (counter_z > 0) {
         WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN);
         counter_z -= current_block->step_event_count;
-        WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN);
         count_position[Z_AXIS]+=count_direction[Z_AXIS];
+        WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN);
       }
 
       #ifndef ADVANCE
@@ -476,8 +562,8 @@ ISR(TIMER1_COMPA_vect)
         if (counter_e > 0) {
           WRITE_E_STEP(!INVERT_E_STEP_PIN);
           counter_e -= current_block->step_event_count;
-          WRITE_E_STEP(INVERT_E_STEP_PIN);
           count_position[E_AXIS]+=count_direction[E_AXIS];
+          WRITE(E_STEP_PIN, INVERT_E_STEP_PIN);
         }
       #endif //!ADVANCE
       step_events_completed += 1;  
@@ -561,45 +647,45 @@ ISR(TIMER1_COMPA_vect)
     // Set E direction (Depends on E direction + advance)
     for(unsigned char i=0; i<4;i++) {
       if (e_steps[0] != 0) {
-        WRITE(E0_STEP_PIN, LOW);
+        WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN);
         if (e_steps[0] < 0) {
           WRITE(E0_DIR_PIN, INVERT_E0_DIR);
           e_steps[0]++;
-          WRITE(E0_STEP_PIN, HIGH);
+          WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN);
         } 
         else if (e_steps[0] > 0) {
           WRITE(E0_DIR_PIN, !INVERT_E0_DIR);
           e_steps[0]--;
-          WRITE(E0_STEP_PIN, HIGH);
+          WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN);
         }
       }
  #if EXTRUDERS > 1
       if (e_steps[1] != 0) {
-        WRITE(E1_STEP_PIN, LOW);
+        WRITE(E1_STEP_PIN, INVERT_E_STEP_PIN);
         if (e_steps[1] < 0) {
           WRITE(E1_DIR_PIN, INVERT_E1_DIR);
           e_steps[1]++;
-          WRITE(E1_STEP_PIN, HIGH);
+          WRITE(E1_STEP_PIN, !INVERT_E_STEP_PIN);
         } 
         else if (e_steps[1] > 0) {
           WRITE(E1_DIR_PIN, !INVERT_E1_DIR);
           e_steps[1]--;
-          WRITE(E1_STEP_PIN, HIGH);
+          WRITE(E1_STEP_PIN, !INVERT_E_STEP_PIN);
         }
       }
  #endif
  #if EXTRUDERS > 2
       if (e_steps[2] != 0) {
-        WRITE(E2_STEP_PIN, LOW);
+        WRITE(E2_STEP_PIN, INVERT_E_STEP_PIN);
         if (e_steps[2] < 0) {
           WRITE(E2_DIR_PIN, INVERT_E2_DIR);
           e_steps[2]++;
-          WRITE(E2_STEP_PIN, HIGH);
+          WRITE(E2_STEP_PIN, !INVERT_E_STEP_PIN);
         } 
         else if (e_steps[2] > 0) {
           WRITE(E2_DIR_PIN, !INVERT_E2_DIR);
           e_steps[2]--;
-          WRITE(E2_STEP_PIN, HIGH);
+          WRITE(E2_STEP_PIN, !INVERT_E_STEP_PIN);
         }
       }
  #endif
@@ -705,26 +791,32 @@ void st_init()
   #if (X_STEP_PIN > -1) 
     SET_OUTPUT(X_STEP_PIN);
     WRITE(X_STEP_PIN,INVERT_X_STEP_PIN);
+    if(!X_ENABLE_ON) WRITE(X_ENABLE_PIN,HIGH);
   #endif  
   #if (Y_STEP_PIN > -1) 
     SET_OUTPUT(Y_STEP_PIN);
     WRITE(Y_STEP_PIN,INVERT_Y_STEP_PIN);
+    if(!Y_ENABLE_ON) WRITE(Y_ENABLE_PIN,HIGH);
   #endif  
   #if (Z_STEP_PIN > -1) 
     SET_OUTPUT(Z_STEP_PIN);
     WRITE(Z_STEP_PIN,INVERT_Z_STEP_PIN);
+    if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH);
   #endif  
   #if (E0_STEP_PIN > -1) 
     SET_OUTPUT(E0_STEP_PIN);
     WRITE(E0_STEP_PIN,INVERT_E_STEP_PIN);
+    if(!E_ENABLE_ON) WRITE(E0_ENABLE_PIN,HIGH);
   #endif  
   #if defined(E1_STEP_PIN) && (E1_STEP_PIN > -1) 
     SET_OUTPUT(E1_STEP_PIN);
     WRITE(E1_STEP_PIN,INVERT_E_STEP_PIN);
+    if(!E_ENABLE_ON) WRITE(E1_ENABLE_PIN,HIGH);
   #endif  
   #if defined(E2_STEP_PIN) && (E2_STEP_PIN > -1) 
     SET_OUTPUT(E2_STEP_PIN);
     WRITE(E2_STEP_PIN,INVERT_E_STEP_PIN);
+    if(!E_ENABLE_ON) WRITE(E2_ENABLE_PIN,HIGH);
   #endif  
 
   #ifdef CONTROLLERFAN_PIN
index c6befba73062a6cb733311dfb0897bdf89c54b72..86dd93de952da7086db17b215378dd78dd3a6422 100644 (file)
--- a/README.md
+++ b/README.md
@@ -44,6 +44,7 @@ Features:
 *   Updated sdcardlib\r
 *   Heater power reporting. Useful for PID monitoring.\r
 *   PID tuning\r
+*   CoreXY kinematics (www.corexy.com/theory.html)\r
 \r
 The default baudrate is 250000. This baudrate has less jitter and hence errors than the usual 115200 baud, but is less supported by drivers and host-environments.\r
 \r