Browse Source

Seperate ENDSTOP_INVERTING for X Y and Z

Added simple endstop filter.
Corrected M114 count display.
Erik van der Zalm 13 years ago
parent
commit
c0f8c9fd72
6 changed files with 62 additions and 18 deletions
  1. 3
    1
      Marlin/Configuration.h
  2. 16
    9
      Marlin/Marlin.pde
  3. 7
    0
      Marlin/planner.cpp
  4. 1
    1
      Marlin/planner.h
  5. 33
    6
      Marlin/stepper.cpp
  6. 2
    1
      Marlin/stepper.h

+ 3
- 1
Marlin/Configuration.h View File

157
 // Endstop Settings
157
 // Endstop Settings
158
 #define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
158
 #define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
159
 // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
159
 // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
160
-const bool ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
160
+const bool X_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
161
+const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
162
+const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
161
 // For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false
163
 // For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false
162
 
164
 
163
 
165
 

+ 16
- 9
Marlin/Marlin.pde View File

556
       relative_mode = true;
556
       relative_mode = true;
557
       break;
557
       break;
558
     case 92: // G92
558
     case 92: // G92
559
-      if(!code_seen(axis_codes[E_AXIS])) 
559
+      if(!code_seen(axis_codes[E_AXIS]))
560
         st_synchronize();
560
         st_synchronize();
561
       for(int8_t i=0; i < NUM_AXIS; i++) {
561
       for(int8_t i=0; i < NUM_AXIS; i++) {
562
-        if(code_seen(axis_codes[i])) current_position[i] = code_value();  
562
+        if(code_seen(axis_codes[i])) { 
563
+           current_position[i] = code_value();  
564
+           if(i == E_AXIS) {
565
+             plan_set_e_position(current_position[E_AXIS]);
566
+           }
567
+           else {
568
+             plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
569
+           }
570
+        }
563
       }
571
       }
564
-      plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
565
       break;
572
       break;
566
     }
573
     }
567
   }
574
   }
865
     case 119: // M119
872
     case 119: // M119
866
       #if (X_MIN_PIN > -1)
873
       #if (X_MIN_PIN > -1)
867
         SERIAL_PROTOCOLPGM("x_min:");
874
         SERIAL_PROTOCOLPGM("x_min:");
868
-        SERIAL_PROTOCOL(((READ(X_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L "));
875
+        SERIAL_PROTOCOL(((READ(X_MIN_PIN)^X_ENDSTOPS_INVERTING)?"H ":"L "));
869
       #endif
876
       #endif
870
       #if (X_MAX_PIN > -1)
877
       #if (X_MAX_PIN > -1)
871
         SERIAL_PROTOCOLPGM("x_max:");
878
         SERIAL_PROTOCOLPGM("x_max:");
872
-        SERIAL_PROTOCOL(((READ(X_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L "));
879
+        SERIAL_PROTOCOL(((READ(X_MAX_PIN)^X_ENDSTOPS_INVERTING)?"H ":"L "));
873
       #endif
880
       #endif
874
       #if (Y_MIN_PIN > -1)
881
       #if (Y_MIN_PIN > -1)
875
         SERIAL_PROTOCOLPGM("y_min:");
882
         SERIAL_PROTOCOLPGM("y_min:");
876
-        SERIAL_PROTOCOL(((READ(Y_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L "));
883
+        SERIAL_PROTOCOL(((READ(Y_MIN_PIN)^Y_ENDSTOPS_INVERTING)?"H ":"L "));
877
       #endif
884
       #endif
878
       #if (Y_MAX_PIN > -1)
885
       #if (Y_MAX_PIN > -1)
879
         SERIAL_PROTOCOLPGM("y_max:");
886
         SERIAL_PROTOCOLPGM("y_max:");
880
-        SERIAL_PROTOCOL(((READ(Y_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L "));
887
+        SERIAL_PROTOCOL(((READ(Y_MAX_PIN)^Y_ENDSTOPS_INVERTING)?"H ":"L "));
881
       #endif
888
       #endif
882
       #if (Z_MIN_PIN > -1)
889
       #if (Z_MIN_PIN > -1)
883
         SERIAL_PROTOCOLPGM("z_min:");
890
         SERIAL_PROTOCOLPGM("z_min:");
884
-        SERIAL_PROTOCOL(((READ(Z_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L "));
891
+        SERIAL_PROTOCOL(((READ(Z_MIN_PIN)^Z_ENDSTOPS_INVERTING)?"H ":"L "));
885
       #endif
892
       #endif
886
       #if (Z_MAX_PIN > -1)
893
       #if (Z_MAX_PIN > -1)
887
         SERIAL_PROTOCOLPGM("z_max:");
894
         SERIAL_PROTOCOLPGM("z_max:");
888
-        SERIAL_PROTOCOL(((READ(Z_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L "));
895
+        SERIAL_PROTOCOL(((READ(Z_MAX_PIN)^Z_ENDSTOPS_INVERTING)?"H ":"L "));
889
       #endif
896
       #endif
890
       SERIAL_PROTOCOLLN("");
897
       SERIAL_PROTOCOLLN("");
891
       break;
898
       break;

+ 7
- 0
Marlin/planner.cpp View File

762
   previous_speed[3] = 0.0;
762
   previous_speed[3] = 0.0;
763
 }
763
 }
764
 
764
 
765
+void plan_set_e_position(const float &e)
766
+{
767
+  position[E_AXIS] = lround(e*axis_steps_per_unit[E_AXIS]);  
768
+  st_set_e_position(position[E_AXIS]);
769
+}
770
+
765
 uint8_t movesplanned()
771
 uint8_t movesplanned()
766
 {
772
 {
767
  return (block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1);
773
  return (block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1);
768
 }
774
 }
775
+

+ 1
- 1
Marlin/planner.h View File

70
 
70
 
71
 // Set position. Used for G92 instructions.
71
 // Set position. Used for G92 instructions.
72
 void plan_set_position(const float &x, const float &y, const float &z, const float &e);
72
 void plan_set_position(const float &x, const float &y, const float &z, const float &e);
73
-
73
+void plan_set_e_position(const float &e);
74
 
74
 
75
 // Called when the current block is no longer needed. Discards the block and makes the memory
75
 // Called when the current block is no longer needed. Discards the block and makes the memory
76
 // availible for new blocks.
76
 // availible for new blocks.

+ 33
- 6
Marlin/stepper.cpp View File

70
 static volatile bool endstop_y_hit=false;
70
 static volatile bool endstop_y_hit=false;
71
 static volatile bool endstop_z_hit=false;
71
 static volatile bool endstop_z_hit=false;
72
 
72
 
73
+static bool old_x_min_endstop=false;
74
+static bool old_x_max_endstop=false;
75
+static bool old_y_min_endstop=false;
76
+static bool old_y_max_endstop=false;
77
+static bool old_z_min_endstop=false;
78
+static bool old_z_max_endstop=false;
79
+
73
 volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
80
 volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
74
 volatile char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
81
 volatile char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
75
 
82
 
260
     SERIAL_ERROR_START
267
     SERIAL_ERROR_START
261
     SERIAL_ERROR(*(unsigned short *)OCR1A);
268
     SERIAL_ERROR(*(unsigned short *)OCR1A);
262
     SERIAL_ERRORLNPGM(" ISR overtaking itself.");
269
     SERIAL_ERRORLNPGM(" ISR overtaking itself.");
270
+    OCR1A = 0x30000;
263
     return; 
271
     return; 
264
   } // The busy-flag is used to avoid reentering this interrupt
272
   } // The busy-flag is used to avoid reentering this interrupt
265
 
273
 
295
       WRITE(X_DIR_PIN, INVERT_X_DIR);
303
       WRITE(X_DIR_PIN, INVERT_X_DIR);
296
       count_direction[X_AXIS]=-1;
304
       count_direction[X_AXIS]=-1;
297
       #if X_MIN_PIN > -1
305
       #if X_MIN_PIN > -1
298
-        if((READ(X_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x > 0)) {
306
+        bool x_min_endstop=(READ(X_MIN_PIN) != X_ENDSTOPS_INVERTING);
307
+        if(x_min_endstop && old_x_min_endstop && (current_block->steps_x > 0)) {
299
           endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
308
           endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
300
           endstop_x_hit=true;
309
           endstop_x_hit=true;
301
           step_events_completed = current_block->step_event_count;
310
           step_events_completed = current_block->step_event_count;
302
         }
311
         }
312
+        old_x_min_endstop = x_min_endstop;
303
       #endif
313
       #endif
304
     }
314
     }
305
     else { // +direction 
315
     else { // +direction 
306
       WRITE(X_DIR_PIN,!INVERT_X_DIR);
316
       WRITE(X_DIR_PIN,!INVERT_X_DIR);
307
       count_direction[X_AXIS]=1;
317
       count_direction[X_AXIS]=1;
308
       #if X_MAX_PIN > -1
318
       #if X_MAX_PIN > -1
309
-        if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x > 0)){
319
+        bool x_max_endstop=(READ(X_MAX_PIN) != X_ENDSTOPS_INVERTING);
320
+        if(x_max_endstop && old_x_max_endstop && (current_block->steps_x > 0)){
310
           endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
321
           endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
311
           endstop_x_hit=true;
322
           endstop_x_hit=true;
312
           step_events_completed = current_block->step_event_count;
323
           step_events_completed = current_block->step_event_count;
313
         }
324
         }
325
+        old_x_max_endstop = x_max_endstop;
314
       #endif
326
       #endif
315
     }
327
     }
316
 
328
 
318
       WRITE(Y_DIR_PIN,INVERT_Y_DIR);
330
       WRITE(Y_DIR_PIN,INVERT_Y_DIR);
319
       count_direction[Y_AXIS]=-1;
331
       count_direction[Y_AXIS]=-1;
320
       #if Y_MIN_PIN > -1
332
       #if Y_MIN_PIN > -1
321
-        if((READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y > 0)) {
333
+        bool y_min_endstop=(READ(Y_MIN_PIN) != Y_ENDSTOPS_INVERTING);
334
+        if(y_min_endstop && old_y_min_endstop && (current_block->steps_y > 0)) {
322
           endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
335
           endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
323
           endstop_y_hit=true;
336
           endstop_y_hit=true;
324
           step_events_completed = current_block->step_event_count;
337
           step_events_completed = current_block->step_event_count;
325
         }
338
         }
339
+        old_y_min_endstop = y_min_endstop;
326
       #endif
340
       #endif
327
     }
341
     }
328
     else { // +direction
342
     else { // +direction
329
     WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
343
     WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
330
       count_direction[Y_AXIS]=1;
344
       count_direction[Y_AXIS]=1;
331
       #if Y_MAX_PIN > -1
345
       #if Y_MAX_PIN > -1
332
-      if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y > 0)){
346
+        bool y_max_endstop=(READ(Y_MAX_PIN) != Y_ENDSTOPS_INVERTING);
347
+        if(y_max_endstop && old_y_max_endstop && (current_block->steps_y > 0)){
333
           endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
348
           endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
334
           endstop_y_hit=true;
349
           endstop_y_hit=true;
335
           step_events_completed = current_block->step_event_count;
350
           step_events_completed = current_block->step_event_count;
336
         }
351
         }
352
+        old_y_max_endstop = y_max_endstop;
337
       #endif
353
       #endif
338
     }
354
     }
339
 
355
 
341
       WRITE(Z_DIR_PIN,INVERT_Z_DIR);
357
       WRITE(Z_DIR_PIN,INVERT_Z_DIR);
342
       count_direction[Z_AXIS]=-1;
358
       count_direction[Z_AXIS]=-1;
343
       #if Z_MIN_PIN > -1
359
       #if Z_MIN_PIN > -1
344
-        if((READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_z > 0)) {
360
+        bool z_min_endstop=(READ(Z_MIN_PIN) != Z_ENDSTOPS_INVERTING);
361
+        if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) {
345
           endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
362
           endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
346
           endstop_z_hit=true;
363
           endstop_z_hit=true;
347
           step_events_completed = current_block->step_event_count;
364
           step_events_completed = current_block->step_event_count;
348
         }
365
         }
366
+        old_z_min_endstop = z_min_endstop;
349
       #endif
367
       #endif
350
     }
368
     }
351
     else { // +direction
369
     else { // +direction
352
       WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
370
       WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
353
         count_direction[Z_AXIS]=1;
371
         count_direction[Z_AXIS]=1;
354
       #if Z_MAX_PIN > -1
372
       #if Z_MAX_PIN > -1
355
-        if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_z > 0)){
373
+        bool z_max_endstop=(READ(Z_MAX_PIN) != Z_ENDSTOPS_INVERTING);
374
+        if(z_max_endstop && old_z_max_endstop && (current_block->steps_z > 0)) {
356
           endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
375
           endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
357
           endstop_z_hit=true;
376
           endstop_z_hit=true;
358
           step_events_completed = current_block->step_event_count;
377
           step_events_completed = current_block->step_event_count;
359
         }
378
         }
379
+        old_z_max_endstop = z_max_endstop;
360
       #endif
380
       #endif
361
     }
381
     }
362
 
382
 
654
   CRITICAL_SECTION_END;
674
   CRITICAL_SECTION_END;
655
 }
675
 }
656
 
676
 
677
+void st_set_e_position(const long &e)
678
+{
679
+  CRITICAL_SECTION_START;
680
+  count_position[E_AXIS] = e;
681
+  CRITICAL_SECTION_END;
682
+}
683
+
657
 long st_get_position(char axis)
684
 long st_get_position(char axis)
658
 {
685
 {
659
   long count_pos;
686
   long count_pos;

+ 2
- 1
Marlin/stepper.h View File

31
 
31
 
32
 // Set current position in steps
32
 // Set current position in steps
33
 void st_set_position(const long &x, const long &y, const long &z, const long &e);
33
 void st_set_position(const long &x, const long &y, const long &z, const long &e);
34
+void st_set_e_position(const long &e);
34
 
35
 
35
 // Get current position in steps
36
 // Get current position in steps
36
 long st_get_position(char axis);
37
 long st_get_position(char axis);
48
 extern block_t *current_block;  // A pointer to the block currently being traced
49
 extern block_t *current_block;  // A pointer to the block currently being traced
49
 
50
 
50
 
51
 
51
-#endif
52
+#endif

Loading…
Cancel
Save