Browse Source

Fix timer comments

Scott Lahteine 8 years ago
parent
commit
3752d9aca8
2 changed files with 39 additions and 10 deletions
  1. 19
    5
      Marlin/stepper.cpp
  2. 20
    5
      Marlin/temperature.cpp

+ 19
- 5
Marlin/stepper.cpp View File

311
   #endif // !ADVANCE && !LIN_ADVANCE
311
   #endif // !ADVANCE && !LIN_ADVANCE
312
 }
312
 }
313
 
313
 
314
-// "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.
315
-// It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
314
+/**
315
+ * Stepper Driver Interrupt
316
+ *
317
+ * Directly pulses the stepper motors at high frequency.
318
+ * Timer 1 runs at a base frequency of 2MHz, with this ISR using OCR1A compare mode.
319
+ *
320
+ * OCR1A   Frequency
321
+ *     1     2 MHz
322
+ *    50    40 KHz
323
+ *   100    20 KHz - capped max rate
324
+ *   200    10 KHz - nominal max rate
325
+ *  2000     1 KHz - sleep rate
326
+ *  4000   500  Hz - init rate
327
+ */
316
 ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
328
 ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
317
 
329
 
318
 void Stepper::isr() {
330
 void Stepper::isr() {
323
       if ((cleaning_buffer_counter == 1) && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
335
       if ((cleaning_buffer_counter == 1) && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
324
     #endif
336
     #endif
325
     cleaning_buffer_counter--;
337
     cleaning_buffer_counter--;
326
-    OCR1A = 200;
338
+    OCR1A = 200; // Run at max speed - 10 KHz
327
     return;
339
     return;
328
   }
340
   }
329
 
341
 
348
       #if ENABLED(Z_LATE_ENABLE)
360
       #if ENABLED(Z_LATE_ENABLE)
349
         if (current_block->steps[Z_AXIS] > 0) {
361
         if (current_block->steps[Z_AXIS] > 0) {
350
           enable_z();
362
           enable_z();
351
-          OCR1A = 2000; //1ms wait
363
+          OCR1A = 2000; // Run at slow speed - 1 KHz
352
           return;
364
           return;
353
         }
365
         }
354
       #endif
366
       #endif
358
       // #endif
370
       // #endif
359
     }
371
     }
360
     else {
372
     else {
361
-      OCR1A = 2000; // 1kHz.
373
+      OCR1A = 2000; // Run at slow speed - 1 KHz
362
       return;
374
       return;
363
     }
375
     }
364
   }
376
   }
903
   // output mode = 00 (disconnected)
915
   // output mode = 00 (disconnected)
904
   TCCR1A &= ~(3 << COM1A0);
916
   TCCR1A &= ~(3 << COM1A0);
905
   TCCR1A &= ~(3 << COM1B0);
917
   TCCR1A &= ~(3 << COM1B0);
918
+
906
   // Set the timer pre-scaler
919
   // Set the timer pre-scaler
907
   // Generally we use a divider of 8, resulting in a 2MHz timer
920
   // Generally we use a divider of 8, resulting in a 2MHz timer
908
   // frequency on a 16MHz MCU. If you are going to change this, be
921
   // frequency on a 16MHz MCU. If you are going to change this, be
910
   // create_speed_lookuptable.py
923
   // create_speed_lookuptable.py
911
   TCCR1B = (TCCR1B & ~(0x07 << CS10)) | (2 << CS10);
924
   TCCR1B = (TCCR1B & ~(0x07 << CS10)) | (2 << CS10);
912
 
925
 
926
+  // Init Stepper ISR to 122 Hz for quick starting
913
   OCR1A = 0x4000;
927
   OCR1A = 0x4000;
914
   TCNT1 = 0;
928
   TCNT1 = 0;
915
   ENABLE_STEPPER_DRIVER_INTERRUPT();
929
   ENABLE_STEPPER_DRIVER_INTERRUPT();

+ 20
- 5
Marlin/temperature.cpp View File

1371
  * Timer 0 is shared with millies so don't change the prescaler.
1371
  * Timer 0 is shared with millies so don't change the prescaler.
1372
  *
1372
  *
1373
  * This ISR uses the compare method so it runs at the base
1373
  * This ISR uses the compare method so it runs at the base
1374
- * frequency (16 MHz / 256 = 62500 Hz), but at the TCNT0 set
1374
+ * frequency (16 MHz / 64 / 256 = 976.5625 Hz), but at the TCNT0 set
1375
  * in OCR0B above (128 or halfway between OVFs).
1375
  * in OCR0B above (128 or halfway between OVFs).
1376
  *
1376
  *
1377
  *  - Manage PWM to all the heaters and fan
1377
  *  - Manage PWM to all the heaters and fan
1485
       #endif
1485
       #endif
1486
     #endif
1486
     #endif
1487
 
1487
 
1488
-    // 488.28 Hz (or 1:976.56, 2:1953.12, 3:3906.25, 4:7812.5, 5:7812.5 6:15625, 6:15625 7:31250)
1488
+    // SOFT_PWM_SCALE to frequency:
1489
+    //
1490
+    // 0: 16000000/64/256/128 =   7.6294 Hz
1491
+    // 1:                / 64 =  15.2588 Hz
1492
+    // 2:                / 32 =  30.5176 Hz
1493
+    // 3:                / 16 =  61.0352 Hz
1494
+    // 4:                /  8 = 122.0703 Hz
1495
+    // 5:                /  4 = 244.1406 Hz
1489
     pwm_count += _BV(SOFT_PWM_SCALE);
1496
     pwm_count += _BV(SOFT_PWM_SCALE);
1490
-    pwm_count &= 0x7f;
1497
+    pwm_count &= 0x7F;
1491
 
1498
 
1492
   #else // SLOW_PWM_HEATERS
1499
   #else // SLOW_PWM_HEATERS
1493
 
1500
 
1586
       #endif
1593
       #endif
1587
     #endif //FAN_SOFT_PWM
1594
     #endif //FAN_SOFT_PWM
1588
 
1595
 
1596
+    // SOFT_PWM_SCALE to frequency:
1597
+    //
1598
+    // 0: 16000000/64/256/128 =   7.6294 Hz
1599
+    // 1:                / 64 =  15.2588 Hz
1600
+    // 2:                / 32 =  30.5176 Hz
1601
+    // 3:                / 16 =  61.0352 Hz
1602
+    // 4:                /  8 = 122.0703 Hz
1603
+    // 5:                /  4 = 244.1406 Hz
1589
     pwm_count += _BV(SOFT_PWM_SCALE);
1604
     pwm_count += _BV(SOFT_PWM_SCALE);
1590
-    pwm_count &= 0x7f;
1605
+    pwm_count &= 0x7F;
1591
 
1606
 
1592
-    // increment slow_pwm_count only every 64 pwm_count circa 65.5ms
1607
+    // increment slow_pwm_count only every 64 pwm_count (e.g., every 8s)
1593
     if ((pwm_count % 64) == 0) {
1608
     if ((pwm_count % 64) == 0) {
1594
       slow_pwm_count++;
1609
       slow_pwm_count++;
1595
       slow_pwm_count &= 0x7f;
1610
       slow_pwm_count &= 0x7f;

Loading…
Cancel
Save