Selaa lähdekoodia

Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1

Bernhard 13 vuotta sitten
vanhempi
commit
12e8edcac3
5 muutettua tiedostoa jossa 142 lisäystä ja 74 poistoa
  1. 3
    2
      Marlin/Configuration.h
  2. 5
    0
      Marlin/Marlin.pde
  3. 9
    3
      Marlin/planner.cpp
  4. 123
    69
      Marlin/stepper.cpp
  5. 2
    0
      Marlin/stepper.h

+ 3
- 2
Marlin/Configuration.h Näytä tiedosto

@@ -170,6 +170,7 @@ const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
170 170
 const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. 
171 171
 // For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false
172 172
 
173
+//#define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing
173 174
 
174 175
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
175 176
 #define X_ENABLE_ON 0
@@ -279,8 +280,8 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
279 280
 #ifdef ADVANCE
280 281
   #define EXTRUDER_ADVANCE_K .3
281 282
 
282
-  #define D_FILAMENT 1.7
283
-  #define STEPS_MM_E 65
283
+  #define D_FILAMENT 2.85
284
+  #define STEPS_MM_E 836
284 285
   #define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159)
285 286
   #define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA)
286 287
 

+ 5
- 0
Marlin/Marlin.pde Näytä tiedosto

@@ -529,6 +529,8 @@ FORCE_INLINE void process_commands()
529 529
       saved_feedmultiply = feedmultiply;
530 530
       feedmultiply = 100;
531 531
       
532
+      enable_endstops(true);
533
+      
532 534
       for(int8_t i=0; i < NUM_AXIS; i++) {
533 535
         destination[i] = current_position[i];
534 536
       }
@@ -564,6 +566,9 @@ FORCE_INLINE void process_commands()
564 566
         HOMEAXIS(Z);
565 567
 	current_position[2]=code_value()+add_homeing[2];
566 568
       }       
569
+      #ifdef ENDSTOPS_ONLY_FOR_HOMING
570
+        enable_endstops(false);
571
+      #endif
567 572
       
568 573
       feedrate = saved_feedrate;
569 574
       feedmultiply = saved_feedmultiply;

+ 9
- 3
Marlin/planner.cpp Näytä tiedosto

@@ -200,7 +200,6 @@ void calculate_trapezoid_for_block(block_t *block, float entry_factor, float exi
200 200
   
201 201
  // block->accelerate_until = accelerate_steps;
202 202
  // block->decelerate_after = accelerate_steps+plateau_steps;
203
-  
204 203
   CRITICAL_SECTION_START;  // Fill variables used by the stepper in a critical section
205 204
   if(block->busy == false) { // Don't update variables if block is busy.
206 205
     block->accelerate_until = accelerate_steps;
@@ -484,7 +483,7 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
484 483
   // Bail if this is a zero-length block
485 484
   if (block->step_event_count <=dropsegments) { return; };
486 485
 
487
-  // Compute direction bits for this block
486
+  // Compute direction bits for this block 
488 487
   block->direction_bits = 0;
489 488
   if (target[X_AXIS] < position[X_AXIS]) { block->direction_bits |= (1<<X_AXIS); }
490 489
   if (target[Y_AXIS] < position[Y_AXIS]) { block->direction_bits |= (1<<Y_AXIS); }
@@ -725,7 +724,7 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
725 724
     else {
726 725
       long acc_dist = estimate_acceleration_distance(0, block->nominal_rate, block->acceleration_st);
727 726
       float advance = (STEPS_PER_CUBIC_MM_E * EXTRUDER_ADVANCE_K) * 
728
-        (current_speed[E_AXIS] * current_speed[E_AXIS] * EXTRUTION_AREA * EXTRUTION_AREA / 3600.0)*65536;
727
+        (current_speed[E_AXIS] * current_speed[E_AXIS] * EXTRUTION_AREA * EXTRUTION_AREA)*256;
729 728
       block->advance = advance;
730 729
       if(acc_dist == 0) {
731 730
         block->advance_rate = 0;
@@ -734,6 +733,13 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
734 733
         block->advance_rate = advance / (float)acc_dist;
735 734
       }
736 735
     }
736
+    /*
737
+    SERIAL_ECHO_START;
738
+    SERIAL_ECHOPGM("advance :");
739
+    SERIAL_ECHO(block->advance/256.0);
740
+    SERIAL_ECHOPGM("advance rate :");
741
+    SERIAL_ECHOLN(block->advance_rate/256.0);
742
+    */
737 743
   #endif // ADVANCE
738 744
 
739 745
 

+ 123
- 69
Marlin/stepper.cpp Näytä tiedosto

@@ -56,9 +56,9 @@ static long counter_x,       // Counter variables for the bresenham line tracer
56 56
 volatile static unsigned long step_events_completed; // The number of step events executed in the current block
57 57
 #ifdef ADVANCE
58 58
   static long advance_rate, advance, final_advance = 0;
59
-  static short old_advance = 0;
59
+  static long old_advance = 0;
60 60
 #endif
61
-static short e_steps;
61
+static long e_steps;
62 62
 static unsigned char busy = false; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler.
63 63
 static long acceleration_time, deceleration_time;
64 64
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
@@ -79,13 +79,20 @@ static bool old_y_max_endstop=false;
79 79
 static bool old_z_min_endstop=false;
80 80
 static bool old_z_max_endstop=false;
81 81
 
82
+static bool check_endstops = true;
83
+
82 84
 volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
83 85
 volatile char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
84 86
 
85 87
 //===========================================================================
86 88
 //=============================functions         ============================
87 89
 //===========================================================================
88
-  
90
+
91
+#ifdef ENDSTOPS_ONLY_FOR_HOMING
92
+  #define CHECK_ENDSTOPS  if(check_endstops)
93
+#else
94
+  #define CHECK_ENDSTOPS
95
+#endif
89 96
 
90 97
 // intRes = intIn1 * intIn2 >> 16
91 98
 // uses:
@@ -191,6 +198,11 @@ void endstops_hit_on_purpose()
191 198
   endstop_z_hit=false;
192 199
 }
193 200
 
201
+void enable_endstops(bool check)
202
+{
203
+  check_endstops = check;
204
+}
205
+
194 206
 //         __________________________
195 207
 //        /|                        |\     _________________         ^
196 208
 //       / |                        | \   /|               |\        |
@@ -254,6 +266,9 @@ FORCE_INLINE void trapezoid_generator_reset() {
254 266
   #ifdef ADVANCE
255 267
     advance = current_block->initial_advance;
256 268
     final_advance = current_block->final_advance;
269
+    // Do E steps + advance steps
270
+    e_steps += ((advance >>8) - old_advance);
271
+    old_advance = advance >>8;  
257 272
   #endif
258 273
   deceleration_time = 0;
259 274
   // step_rate to timer interval
@@ -261,6 +276,17 @@ FORCE_INLINE void trapezoid_generator_reset() {
261 276
   acceleration_time = calc_timer(acc_step_rate);
262 277
   OCR1A = acceleration_time;
263 278
   OCR1A_nominal = calc_timer(current_block->nominal_rate);
279
+  
280
+//    SERIAL_ECHO_START;
281
+//    SERIAL_ECHOPGM("advance :");
282
+//    SERIAL_ECHO(current_block->advance/256.0);
283
+//    SERIAL_ECHOPGM("advance rate :");
284
+//    SERIAL_ECHO(current_block->advance_rate/256.0);
285
+//    SERIAL_ECHOPGM("initial advance :");
286
+//  SERIAL_ECHO(current_block->initial_advance/256.0);
287
+//    SERIAL_ECHOPGM("final advance :");
288
+//    SERIAL_ECHOLN(current_block->final_advance/256.0);
289
+    
264 290
 }
265 291
 
266 292
 // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.  
@@ -295,82 +321,100 @@ ISR(TIMER1_COMPA_vect)
295 321
     if ((out_bits & (1<<X_AXIS)) != 0) {   // -direction
296 322
       WRITE(X_DIR_PIN, INVERT_X_DIR);
297 323
       count_direction[X_AXIS]=-1;
298
-      #if X_MIN_PIN > -1
299
-        bool x_min_endstop=(READ(X_MIN_PIN) != X_ENDSTOPS_INVERTING);
300
-        if(x_min_endstop && old_x_min_endstop && (current_block->steps_x > 0)) {
301
-          endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
302
-          endstop_x_hit=true;
303
-          step_events_completed = current_block->step_event_count;
304
-        }
305
-        old_x_min_endstop = x_min_endstop;
306
-      #endif
324
+      CHECK_ENDSTOPS
325
+      {
326
+        #if X_MIN_PIN > -1
327
+          bool x_min_endstop=(READ(X_MIN_PIN) != X_ENDSTOPS_INVERTING);
328
+          if(x_min_endstop && old_x_min_endstop && (current_block->steps_x > 0)) {
329
+            endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
330
+            endstop_x_hit=true;
331
+            step_events_completed = current_block->step_event_count;
332
+          }
333
+          old_x_min_endstop = x_min_endstop;
334
+        #endif
335
+      }
307 336
     }
308 337
     else { // +direction 
309 338
       WRITE(X_DIR_PIN,!INVERT_X_DIR);
310 339
       count_direction[X_AXIS]=1;
311
-      #if X_MAX_PIN > -1
312
-        bool x_max_endstop=(READ(X_MAX_PIN) != X_ENDSTOPS_INVERTING);
313
-        if(x_max_endstop && old_x_max_endstop && (current_block->steps_x > 0)){
314
-          endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
315
-          endstop_x_hit=true;
316
-          step_events_completed = current_block->step_event_count;
317
-        }
318
-        old_x_max_endstop = x_max_endstop;
319
-      #endif
340
+      CHECK_ENDSTOPS 
341
+      {
342
+        #if X_MAX_PIN > -1
343
+          bool x_max_endstop=(READ(X_MAX_PIN) != X_ENDSTOPS_INVERTING);
344
+          if(x_max_endstop && old_x_max_endstop && (current_block->steps_x > 0)){
345
+            endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
346
+            endstop_x_hit=true;
347
+            step_events_completed = current_block->step_event_count;
348
+          }
349
+          old_x_max_endstop = x_max_endstop;
350
+        #endif
351
+      }
320 352
     }
321 353
 
322 354
     if ((out_bits & (1<<Y_AXIS)) != 0) {   // -direction
323 355
       WRITE(Y_DIR_PIN,INVERT_Y_DIR);
324 356
       count_direction[Y_AXIS]=-1;
325
-      #if Y_MIN_PIN > -1
326
-        bool y_min_endstop=(READ(Y_MIN_PIN) != Y_ENDSTOPS_INVERTING);
327
-        if(y_min_endstop && old_y_min_endstop && (current_block->steps_y > 0)) {
328
-          endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
329
-          endstop_y_hit=true;
330
-          step_events_completed = current_block->step_event_count;
331
-        }
332
-        old_y_min_endstop = y_min_endstop;
333
-      #endif
357
+      CHECK_ENDSTOPS
358
+      {
359
+        #if Y_MIN_PIN > -1
360
+          bool y_min_endstop=(READ(Y_MIN_PIN) != Y_ENDSTOPS_INVERTING);
361
+          if(y_min_endstop && old_y_min_endstop && (current_block->steps_y > 0)) {
362
+            endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
363
+            endstop_y_hit=true;
364
+            step_events_completed = current_block->step_event_count;
365
+          }
366
+          old_y_min_endstop = y_min_endstop;
367
+        #endif
368
+      }
334 369
     }
335 370
     else { // +direction
336 371
     WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
337 372
       count_direction[Y_AXIS]=1;
338
-      #if Y_MAX_PIN > -1
339
-        bool y_max_endstop=(READ(Y_MAX_PIN) != Y_ENDSTOPS_INVERTING);
340
-        if(y_max_endstop && old_y_max_endstop && (current_block->steps_y > 0)){
341
-          endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
342
-          endstop_y_hit=true;
343
-          step_events_completed = current_block->step_event_count;
344
-        }
345
-        old_y_max_endstop = y_max_endstop;
346
-      #endif
373
+      CHECK_ENDSTOPS
374
+      {
375
+        #if Y_MAX_PIN > -1
376
+          bool y_max_endstop=(READ(Y_MAX_PIN) != Y_ENDSTOPS_INVERTING);
377
+          if(y_max_endstop && old_y_max_endstop && (current_block->steps_y > 0)){
378
+            endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
379
+            endstop_y_hit=true;
380
+            step_events_completed = current_block->step_event_count;
381
+          }
382
+          old_y_max_endstop = y_max_endstop;
383
+        #endif
384
+      }
347 385
     }
348 386
 
349 387
     if ((out_bits & (1<<Z_AXIS)) != 0) {   // -direction
350 388
       WRITE(Z_DIR_PIN,INVERT_Z_DIR);
351 389
       count_direction[Z_AXIS]=-1;
352
-      #if Z_MIN_PIN > -1
353
-        bool z_min_endstop=(READ(Z_MIN_PIN) != Z_ENDSTOPS_INVERTING);
354
-        if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) {
355
-          endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
356
-          endstop_z_hit=true;
357
-          step_events_completed = current_block->step_event_count;
358
-        }
359
-        old_z_min_endstop = z_min_endstop;
360
-      #endif
390
+      CHECK_ENDSTOPS
391
+      {
392
+        #if Z_MIN_PIN > -1
393
+          bool z_min_endstop=(READ(Z_MIN_PIN) != Z_ENDSTOPS_INVERTING);
394
+          if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) {
395
+            endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
396
+            endstop_z_hit=true;
397
+            step_events_completed = current_block->step_event_count;
398
+          }
399
+          old_z_min_endstop = z_min_endstop;
400
+        #endif
401
+      }
361 402
     }
362 403
     else { // +direction
363 404
       WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
364
-        count_direction[Z_AXIS]=1;
365
-      #if Z_MAX_PIN > -1
366
-        bool z_max_endstop=(READ(Z_MAX_PIN) != Z_ENDSTOPS_INVERTING);
367
-        if(z_max_endstop && old_z_max_endstop && (current_block->steps_z > 0)) {
368
-          endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
369
-          endstop_z_hit=true;
370
-          step_events_completed = current_block->step_event_count;
371
-        }
372
-        old_z_max_endstop = z_max_endstop;
373
-      #endif
405
+      count_direction[Z_AXIS]=1;
406
+      CHECK_ENDSTOPS
407
+      {
408
+        #if Z_MAX_PIN > -1
409
+          bool z_max_endstop=(READ(Z_MAX_PIN) != Z_ENDSTOPS_INVERTING);
410
+          if(z_max_endstop && old_z_max_endstop && (current_block->steps_z > 0)) {
411
+            endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
412
+            endstop_z_hit=true;
413
+            step_events_completed = current_block->step_event_count;
414
+          }
415
+          old_z_max_endstop = z_max_endstop;
416
+        #endif
417
+      }
374 418
     }
375 419
 
376 420
     #ifndef ADVANCE
@@ -383,6 +427,9 @@ ISR(TIMER1_COMPA_vect)
383 427
         count_direction[E_AXIS]=-1;
384 428
       }
385 429
     #endif //!ADVANCE
430
+    
431
+
432
+    
386 433
     for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves) 
387 434
       MSerial.checkRx(); // Check for serial chars. 
388 435
       
@@ -391,19 +438,12 @@ ISR(TIMER1_COMPA_vect)
391 438
       if (counter_e > 0) {
392 439
         counter_e -= current_block->step_event_count;
393 440
         if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
394
-          CRITICAL_SECTION_START;
395 441
           e_steps--;
396
-          CRITICAL_SECTION_END;
397 442
         }
398 443
         else {
399
-          CRITICAL_SECTION_START;
400 444
           e_steps++;
401
-          CRITICAL_SECTION_END;
402 445
         }
403 446
       }    
404
-      // Do E steps + advance steps
405
-      e_steps += ((advance >> 16) - old_advance);
406
-      old_advance = advance >> 16;  
407 447
       #endif //ADVANCE
408 448
       
409 449
       counter_x += current_block->steps_x;
@@ -462,6 +502,11 @@ ISR(TIMER1_COMPA_vect)
462 502
         for(int8_t i=0; i < step_loops; i++) {
463 503
           advance += advance_rate;
464 504
         }
505
+        //if(advance > current_block->advance) advance = current_block->advance;
506
+        // Do E steps + advance steps
507
+        e_steps += ((advance >>8) - old_advance);
508
+        old_advance = advance >>8;  
509
+        
465 510
       #endif
466 511
     } 
467 512
     else if (step_events_completed > (unsigned long int)current_block->decelerate_after) {   
@@ -486,8 +531,10 @@ ISR(TIMER1_COMPA_vect)
486 531
         for(int8_t i=0; i < step_loops; i++) {
487 532
           advance -= advance_rate;
488 533
         }
489
-        if(advance < final_advance)
490
-          advance = final_advance;
534
+        if(advance < final_advance) advance = final_advance;
535
+        // Do E steps + advance steps
536
+        e_steps += ((advance >>8) - old_advance);
537
+        old_advance = advance >>8;  
491 538
       #endif //ADVANCE
492 539
     }
493 540
     else {
@@ -508,7 +555,7 @@ ISR(TIMER1_COMPA_vect)
508 555
   // Timer 0 is shared with millies
509 556
   ISR(TIMER0_COMPA_vect)
510 557
   {
511
-    old_OCR0A += 25; // ~10kHz interrupt
558
+    old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
512 559
     OCR0A = old_OCR0A;
513 560
     // Set E direction (Depends on E direction + advance)
514 561
     for(unsigned char i=0; i<4;) {
@@ -520,7 +567,7 @@ ISR(TIMER1_COMPA_vect)
520 567
         e_steps++;
521 568
         WRITE(E_STEP_PIN, HIGH);
522 569
       } 
523
-      if (e_steps > 0) {
570
+      else if (e_steps > 0) {
524 571
         WRITE(E_DIR_PIN,!INVERT_E_DIR);
525 572
         e_steps--;
526 573
         WRITE(E_STEP_PIN, HIGH);
@@ -649,6 +696,13 @@ void st_init()
649 696
     e_steps = 0;
650 697
     TIMSK0 |= (1<<OCIE0A);
651 698
   #endif //ADVANCE
699
+  
700
+  #ifdef ENDSTOPS_ONLY_FOR_HOMING
701
+    enable_endstops(false);
702
+  #else
703
+    enable_endstops(true);
704
+  #endif
705
+  
652 706
   sei();
653 707
 }
654 708
 

+ 2
- 0
Marlin/stepper.h Näytä tiedosto

@@ -44,6 +44,8 @@ void st_wake_up();
44 44
 void checkHitEndstops(); //call from somwhere to create an serial error message with the locations the endstops where hit, in case they were triggered
45 45
 void endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homeing and before a routine call of checkHitEndstops();
46 46
 
47
+void enable_endstops(bool check); // Enable/disable endstop checking
48
+
47 49
 void checkStepperErrors(); //Print errors detected by the stepper
48 50
 
49 51
 void finishAndDisableSteppers();

Loading…
Peruuta
Tallenna