Browse Source

Add an option to specify "pulse" timer

Scott Lahteine 7 years ago
parent
commit
82ef6b5242

+ 4
- 0
Marlin/src/HAL/HAL_AVR/HAL_AVR.h View File

@@ -109,6 +109,10 @@ extern "C" {
109 109
 #define STEPPER_TIMER_PRESCALE  8
110 110
 #define HAL_TICKS_PER_US        ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
111 111
 
112
+#define PULSE_TIMER_NUM         TEMP_TIMER_NUM
113
+#define TIMER_COUNTER_0         TCNT0
114
+#define PULSE_TIMER_PRESCALE    8
115
+
112 116
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
113 117
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
114 118
 

+ 3
- 0
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h View File

@@ -64,6 +64,9 @@ typedef uint32_t hal_timer_t;
64 64
 #define HAL_STEP_TIMER_ISR  void TC3_Handler()
65 65
 #define HAL_TEMP_TIMER_ISR  void TC4_Handler()
66 66
 
67
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
68
+#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
69
+
67 70
 // --------------------------------------------------------------------------
68 71
 // Types
69 72
 // --------------------------------------------------------------------------

+ 3
- 0
Marlin/src/HAL/HAL_LPC1768/HAL_timers.h View File

@@ -53,6 +53,9 @@ typedef uint32_t hal_timer_t;
53 53
 #define HAL_TEMP_TIMER_RATE    1000000
54 54
 #define TEMP_TIMER_FREQUENCY   1000 // temperature interrupt frequency
55 55
 
56
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
57
+#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
58
+
56 59
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
57 60
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
58 61
 #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)

+ 3
- 0
Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h View File

@@ -56,6 +56,9 @@ typedef uint16_t hal_timer_t;
56 56
 #define HAL_STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
57 57
 #define HAL_TICKS_PER_US       ((HAL_STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per us
58 58
 
59
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
60
+#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
61
+
59 62
 #define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
60 63
 #define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
61 64
 

+ 3
- 0
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h View File

@@ -57,6 +57,9 @@ typedef uint32_t hal_timer_t;
57 57
 #define STEPPER_TIMER STEP_TIMER_NUM // Alias?
58 58
 #define STEPPER_TIMER_PRESCALE 0 // Not defined anywhere else!
59 59
 
60
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
61
+#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
62
+
60 63
 #define HAL_TIMER_RATE         (FTM0_TIMER_RATE)
61 64
 #define HAL_STEPPER_TIMER_RATE HAL_TIMER_RATE
62 65
 #define HAL_TICKS_PER_US       ((HAL_STEPPER_TIMER_RATE) / 1000000)

+ 9
- 9
Marlin/src/module/stepper.cpp View File

@@ -564,7 +564,7 @@ void Stepper::isr() {
564 564
      * 10µs = 160 or 200 cycles.
565 565
      */
566 566
     #if EXTRA_CYCLES_XYZE > 20
567
-      hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
567
+      hal_timer_t pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM);
568 568
     #endif
569 569
 
570 570
     #if HAS_X_STEP
@@ -596,8 +596,8 @@ void Stepper::isr() {
596 596
 
597 597
     // For minimum pulse time wait before stopping pulses
598 598
     #if EXTRA_CYCLES_XYZE > 20
599
-      while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ }
600
-      pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
599
+      while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
600
+      pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM);
601 601
     #elif EXTRA_CYCLES_XYZE > 0
602 602
       DELAY_NOPS(EXTRA_CYCLES_XYZE);
603 603
     #endif
@@ -637,7 +637,7 @@ void Stepper::isr() {
637 637
 
638 638
     // For minimum pulse time wait after stopping pulses also
639 639
     #if EXTRA_CYCLES_XYZE > 20
640
-      if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ }
640
+      if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
641 641
     #elif EXTRA_CYCLES_XYZE > 0
642 642
       if (i) DELAY_NOPS(EXTRA_CYCLES_XYZE);
643 643
     #endif
@@ -818,7 +818,7 @@ void Stepper::isr() {
818 818
     for (uint8_t i = step_loops; i--;) {
819 819
 
820 820
       #if EXTRA_CYCLES_E > 20
821
-        hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
821
+        hal_timer_t pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM);
822 822
       #endif
823 823
 
824 824
       START_E_PULSE(0);
@@ -837,8 +837,8 @@ void Stepper::isr() {
837 837
 
838 838
       // For minimum pulse time wait before stopping pulses
839 839
       #if EXTRA_CYCLES_E > 20
840
-        while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ }
841
-        pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
840
+        while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
841
+        pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM);
842 842
       #elif EXTRA_CYCLES_E > 0
843 843
         DELAY_NOPS(EXTRA_CYCLES_E);
844 844
       #endif
@@ -859,7 +859,7 @@ void Stepper::isr() {
859 859
 
860 860
       // For minimum pulse time wait before looping
861 861
       #if EXTRA_CYCLES_E > 20
862
-        if (i) while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ }
862
+        if (i) while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
863 863
       #elif EXTRA_CYCLES_E > 0
864 864
         if (i) DELAY_NOPS(EXTRA_CYCLES_E);
865 865
       #endif
@@ -1299,7 +1299,7 @@ void Stepper::report_positions() {
1299 1299
 
1300 1300
   #if EXTRA_CYCLES_BABYSTEP > 20
1301 1301
     #define _SAVE_START const hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM)
1302
-    #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ }
1302
+    #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
1303 1303
   #else
1304 1304
     #define _SAVE_START NOOP
1305 1305
     #if EXTRA_CYCLES_BABYSTEP > 0

Loading…
Cancel
Save