Browse Source

Some advance modifications

Erik van der Zalm 13 years ago
parent
commit
af22e9cd38
3 changed files with 41 additions and 18 deletions
  1. 2
    2
      Marlin/Configuration.h
  2. 9
    3
      Marlin/planner.cpp
  3. 30
    13
      Marlin/stepper.cpp

+ 2
- 2
Marlin/Configuration.h View File

278
 #ifdef ADVANCE
278
 #ifdef ADVANCE
279
   #define EXTRUDER_ADVANCE_K .3
279
   #define EXTRUDER_ADVANCE_K .3
280
 
280
 
281
-  #define D_FILAMENT 1.7
282
-  #define STEPS_MM_E 65
281
+  #define D_FILAMENT 2.85
282
+  #define STEPS_MM_E 836
283
   #define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159)
283
   #define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159)
284
   #define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA)
284
   #define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA)
285
 
285
 

+ 9
- 3
Marlin/planner.cpp View File

198
   
198
   
199
  // block->accelerate_until = accelerate_steps;
199
  // block->accelerate_until = accelerate_steps;
200
  // block->decelerate_after = accelerate_steps+plateau_steps;
200
  // block->decelerate_after = accelerate_steps+plateau_steps;
201
-  
202
   CRITICAL_SECTION_START;  // Fill variables used by the stepper in a critical section
201
   CRITICAL_SECTION_START;  // Fill variables used by the stepper in a critical section
203
   if(block->busy == false) { // Don't update variables if block is busy.
202
   if(block->busy == false) { // Don't update variables if block is busy.
204
     block->accelerate_until = accelerate_steps;
203
     block->accelerate_until = accelerate_steps;
482
   // Bail if this is a zero-length block
481
   // Bail if this is a zero-length block
483
   if (block->step_event_count <=dropsegments) { return; };
482
   if (block->step_event_count <=dropsegments) { return; };
484
 
483
 
485
-  // Compute direction bits for this block
484
+  // Compute direction bits for this block 
486
   block->direction_bits = 0;
485
   block->direction_bits = 0;
487
   if (target[X_AXIS] < position[X_AXIS]) { block->direction_bits |= (1<<X_AXIS); }
486
   if (target[X_AXIS] < position[X_AXIS]) { block->direction_bits |= (1<<X_AXIS); }
488
   if (target[Y_AXIS] < position[Y_AXIS]) { block->direction_bits |= (1<<Y_AXIS); }
487
   if (target[Y_AXIS] < position[Y_AXIS]) { block->direction_bits |= (1<<Y_AXIS); }
722
     else {
721
     else {
723
       long acc_dist = estimate_acceleration_distance(0, block->nominal_rate, block->acceleration_st);
722
       long acc_dist = estimate_acceleration_distance(0, block->nominal_rate, block->acceleration_st);
724
       float advance = (STEPS_PER_CUBIC_MM_E * EXTRUDER_ADVANCE_K) * 
723
       float advance = (STEPS_PER_CUBIC_MM_E * EXTRUDER_ADVANCE_K) * 
725
-        (current_speed[E_AXIS] * current_speed[E_AXIS] * EXTRUTION_AREA * EXTRUTION_AREA / 3600.0)*65536;
724
+        (current_speed[E_AXIS] * current_speed[E_AXIS] * EXTRUTION_AREA * EXTRUTION_AREA)*256;
726
       block->advance = advance;
725
       block->advance = advance;
727
       if(acc_dist == 0) {
726
       if(acc_dist == 0) {
728
         block->advance_rate = 0;
727
         block->advance_rate = 0;
731
         block->advance_rate = advance / (float)acc_dist;
730
         block->advance_rate = advance / (float)acc_dist;
732
       }
731
       }
733
     }
732
     }
733
+    /*
734
+    SERIAL_ECHO_START;
735
+    SERIAL_ECHOPGM("advance :");
736
+    SERIAL_ECHO(block->advance/256.0);
737
+    SERIAL_ECHOPGM("advance rate :");
738
+    SERIAL_ECHOLN(block->advance_rate/256.0);
739
+    */
734
   #endif // ADVANCE
740
   #endif // ADVANCE
735
 
741
 
736
 
742
 

+ 30
- 13
Marlin/stepper.cpp View File

55
 volatile static unsigned long step_events_completed; // The number of step events executed in the current block
55
 volatile static unsigned long step_events_completed; // The number of step events executed in the current block
56
 #ifdef ADVANCE
56
 #ifdef ADVANCE
57
   static long advance_rate, advance, final_advance = 0;
57
   static long advance_rate, advance, final_advance = 0;
58
-  static short old_advance = 0;
58
+  static long old_advance = 0;
59
 #endif
59
 #endif
60
-static short e_steps;
60
+static long e_steps;
61
 static unsigned char busy = false; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler.
61
 static unsigned char busy = false; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler.
62
 static long acceleration_time, deceleration_time;
62
 static long acceleration_time, deceleration_time;
63
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
63
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
253
   #ifdef ADVANCE
253
   #ifdef ADVANCE
254
     advance = current_block->initial_advance;
254
     advance = current_block->initial_advance;
255
     final_advance = current_block->final_advance;
255
     final_advance = current_block->final_advance;
256
+    // Do E steps + advance steps
257
+    e_steps += ((advance >>8) - old_advance);
258
+    old_advance = advance >>8;  
256
   #endif
259
   #endif
257
   deceleration_time = 0;
260
   deceleration_time = 0;
258
   // step_rate to timer interval
261
   // step_rate to timer interval
260
   acceleration_time = calc_timer(acc_step_rate);
263
   acceleration_time = calc_timer(acc_step_rate);
261
   OCR1A = acceleration_time;
264
   OCR1A = acceleration_time;
262
   OCR1A_nominal = calc_timer(current_block->nominal_rate);
265
   OCR1A_nominal = calc_timer(current_block->nominal_rate);
266
+  
267
+//    SERIAL_ECHO_START;
268
+//    SERIAL_ECHOPGM("advance :");
269
+//    SERIAL_ECHO(current_block->advance/256.0);
270
+//    SERIAL_ECHOPGM("advance rate :");
271
+//    SERIAL_ECHO(current_block->advance_rate/256.0);
272
+//    SERIAL_ECHOPGM("initial advance :");
273
+//  SERIAL_ECHO(current_block->initial_advance/256.0);
274
+//    SERIAL_ECHOPGM("final advance :");
275
+//    SERIAL_ECHOLN(current_block->final_advance/256.0);
276
+    
263
 }
277
 }
264
 
278
 
265
 // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.  
279
 // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.  
382
         count_direction[E_AXIS]=-1;
396
         count_direction[E_AXIS]=-1;
383
       }
397
       }
384
     #endif //!ADVANCE
398
     #endif //!ADVANCE
399
+    
400
+
401
+    
385
     for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves) 
402
     for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves) 
386
       MSerial.checkRx(); // Check for serial chars. 
403
       MSerial.checkRx(); // Check for serial chars. 
387
       
404
       
390
       if (counter_e > 0) {
407
       if (counter_e > 0) {
391
         counter_e -= current_block->step_event_count;
408
         counter_e -= current_block->step_event_count;
392
         if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
409
         if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
393
-          CRITICAL_SECTION_START;
394
           e_steps--;
410
           e_steps--;
395
-          CRITICAL_SECTION_END;
396
         }
411
         }
397
         else {
412
         else {
398
-          CRITICAL_SECTION_START;
399
           e_steps++;
413
           e_steps++;
400
-          CRITICAL_SECTION_END;
401
         }
414
         }
402
       }    
415
       }    
403
-      // Do E steps + advance steps
404
-      e_steps += ((advance >> 16) - old_advance);
405
-      old_advance = advance >> 16;  
406
       #endif //ADVANCE
416
       #endif //ADVANCE
407
       
417
       
408
       counter_x += current_block->steps_x;
418
       counter_x += current_block->steps_x;
461
         for(int8_t i=0; i < step_loops; i++) {
471
         for(int8_t i=0; i < step_loops; i++) {
462
           advance += advance_rate;
472
           advance += advance_rate;
463
         }
473
         }
474
+        //if(advance > current_block->advance) advance = current_block->advance;
475
+        // Do E steps + advance steps
476
+        e_steps += ((advance >>8) - old_advance);
477
+        old_advance = advance >>8;  
478
+        
464
       #endif
479
       #endif
465
     } 
480
     } 
466
     else if (step_events_completed > current_block->decelerate_after) {   
481
     else if (step_events_completed > current_block->decelerate_after) {   
485
         for(int8_t i=0; i < step_loops; i++) {
500
         for(int8_t i=0; i < step_loops; i++) {
486
           advance -= advance_rate;
501
           advance -= advance_rate;
487
         }
502
         }
488
-        if(advance < final_advance)
489
-          advance = final_advance;
503
+        if(advance < final_advance) advance = final_advance;
504
+        // Do E steps + advance steps
505
+        e_steps += ((advance >>8) - old_advance);
506
+        old_advance = advance >>8;  
490
       #endif //ADVANCE
507
       #endif //ADVANCE
491
     }
508
     }
492
     else {
509
     else {
507
   // Timer 0 is shared with millies
524
   // Timer 0 is shared with millies
508
   ISR(TIMER0_COMPA_vect)
525
   ISR(TIMER0_COMPA_vect)
509
   {
526
   {
510
-    old_OCR0A += 25; // ~10kHz interrupt
527
+    old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
511
     OCR0A = old_OCR0A;
528
     OCR0A = old_OCR0A;
512
     // Set E direction (Depends on E direction + advance)
529
     // Set E direction (Depends on E direction + advance)
513
     for(unsigned char i=0; i<4;) {
530
     for(unsigned char i=0; i<4;) {
519
         e_steps++;
536
         e_steps++;
520
         WRITE(E_STEP_PIN, HIGH);
537
         WRITE(E_STEP_PIN, HIGH);
521
       } 
538
       } 
522
-      if (e_steps > 0) {
539
+      else if (e_steps > 0) {
523
         WRITE(E_DIR_PIN,!INVERT_E_DIR);
540
         WRITE(E_DIR_PIN,!INVERT_E_DIR);
524
         e_steps--;
541
         e_steps--;
525
         WRITE(E_STEP_PIN, HIGH);
542
         WRITE(E_STEP_PIN, HIGH);

Loading…
Cancel
Save