Browse Source

Fix stepper pulse timing

Always honor minimum period on stepper pulse generation, and fix timing calculations

Signed-off-by: etagle <ejtagle@hotmail.com>
etagle 7 years ago
parent
commit
a215725df6

+ 12
- 15
Marlin/src/HAL/HAL_AVR/HAL.h View File

108
   int freeMemory(void);
108
   int freeMemory(void);
109
 }
109
 }
110
 
110
 
111
-// eeprom
112
-//void eeprom_write_byte(unsigned char *pos, unsigned char value);
113
-//unsigned char eeprom_read_byte(unsigned char *pos);
114
-
115
 // timers
111
 // timers
116
 #define HAL_TIMER_RATE          ((F_CPU) / 8)    // i.e., 2MHz or 2.5MHz
112
 #define HAL_TIMER_RATE          ((F_CPU) / 8)    // i.e., 2MHz or 2.5MHz
117
 
113
 
119
 #define TEMP_TIMER_NUM          0
115
 #define TEMP_TIMER_NUM          0
120
 #define PULSE_TIMER_NUM         STEP_TIMER_NUM
116
 #define PULSE_TIMER_NUM         STEP_TIMER_NUM
121
 
117
 
122
-#define STEPPER_TIMER_RATE      HAL_TIMER_RATE
123
-#define HAL_TICKS_PER_US        ((STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
124
-#define STEPPER_TIMER_PRESCALE  8
125
-#define STEP_TIMER_MIN_INTERVAL 8 // minimum time in µs between stepper interrupts
126
-
127
 #define TEMP_TIMER_FREQUENCY    ((F_CPU) / 64.0 / 256.0)
118
 #define TEMP_TIMER_FREQUENCY    ((F_CPU) / 64.0 / 256.0)
128
 
119
 
129
-#define TIMER_OCR_1             OCR1A
130
-#define TIMER_COUNTER_1         TCNT1
131
-
132
-#define TIMER_OCR_0             OCR0A
133
-#define TIMER_COUNTER_0         TCNT0
120
+#define STEPPER_TIMER_RATE      HAL_TIMER_RATE
121
+#define STEPPER_TIMER_PRESCALE  8
122
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
134
 
123
 
135
-#define PULSE_TIMER_PRESCALE    STEPPER_TIMER_PRESCALE
124
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
125
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
126
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
136
 
127
 
137
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
128
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
138
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
129
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
173
   }
164
   }
174
 }
165
 }
175
 
166
 
167
+#define TIMER_OCR_1             OCR1A
168
+#define TIMER_COUNTER_1         TCNT1
169
+
170
+#define TIMER_OCR_0             OCR0A
171
+#define TIMER_COUNTER_0         TCNT0
172
+
176
 #define _CAT(a, ...) a ## __VA_ARGS__
173
 #define _CAT(a, ...) a ## __VA_ARGS__
177
 #define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
174
 #define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
178
 #define HAL_timer_restrain(timer, interval_ticks) NOLESS(_CAT(TIMER_OCR_, timer), _CAT(TIMER_COUNTER_, timer) + interval_ticks)
175
 #define HAL_timer_restrain(timer, interval_ticks) NOLESS(_CAT(TIMER_OCR_, timer), _CAT(TIMER_COUNTER_, timer) + interval_ticks)

+ 9
- 8
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h View File

43
 typedef uint32_t hal_timer_t;
43
 typedef uint32_t hal_timer_t;
44
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
44
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
45
 
45
 
46
+#define HAL_TIMER_RATE         ((F_CPU) / 2)    // frequency of timers peripherals
47
+
46
 #define STEP_TIMER_NUM 3  // index of timer to use for stepper
48
 #define STEP_TIMER_NUM 3  // index of timer to use for stepper
47
 #define TEMP_TIMER_NUM 4  // index of timer to use for temperature
49
 #define TEMP_TIMER_NUM 4  // index of timer to use for temperature
50
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
48
 #define TONE_TIMER_NUM 6  // index of timer to use for beeper tones
51
 #define TONE_TIMER_NUM 6  // index of timer to use for beeper tones
49
 
52
 
50
-#define HAL_TIMER_RATE         ((F_CPU) / 2)    // frequency of timers peripherals
53
+#define TEMP_TIMER_FREQUENCY   1000 // temperature interrupt frequency
51
 
54
 
52
 #define STEPPER_TIMER_RATE     HAL_TIMER_RATE   // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
55
 #define STEPPER_TIMER_RATE     HAL_TIMER_RATE   // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
53
-#define HAL_TICKS_PER_US       ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
54
-#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / HAL_TICKS_PER_US)
55
-#define STEP_TIMER_MIN_INTERVAL   8 // minimum time in µs between stepper interrupts
56
-
57
-#define TEMP_TIMER_FREQUENCY   1000 // temperature interrupt frequency
56
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
57
+#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
58
 
58
 
59
-#define PULSE_TIMER_NUM STEP_TIMER_NUM
60
-#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
59
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
60
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
61
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
61
 
62
 
62
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
63
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
63
 #define DISABLE_STEPPER_DRIVER_INTERRUPT()  HAL_timer_disable_interrupt(STEP_TIMER_NUM)
64
 #define DISABLE_STEPPER_DRIVER_INTERRUPT()  HAL_timer_disable_interrupt(STEP_TIMER_NUM)

+ 9
- 8
Marlin/src/HAL/HAL_LPC1768/HAL_timers.h View File

66
 typedef uint32_t hal_timer_t;
66
 typedef uint32_t hal_timer_t;
67
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
67
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
68
 
68
 
69
+#define HAL_TIMER_RATE         ((SystemCoreClock) / 4)  // frequency of timers peripherals
70
+
69
 #define STEP_TIMER_NUM 0  // Timer Index for Stepper
71
 #define STEP_TIMER_NUM 0  // Timer Index for Stepper
70
 #define TEMP_TIMER_NUM 1  // Timer Index for Temperature
72
 #define TEMP_TIMER_NUM 1  // Timer Index for Temperature
71
 #define PULSE_TIMER_NUM STEP_TIMER_NUM
73
 #define PULSE_TIMER_NUM STEP_TIMER_NUM
72
 #define PWM_TIMER_NUM 3   // Timer Index for PWM
74
 #define PWM_TIMER_NUM 3   // Timer Index for PWM
73
 
75
 
74
-#define HAL_TIMER_RATE         ((SystemCoreClock) / 4)  // frequency of timers peripherals
75
-#define STEPPER_TIMER_RATE     HAL_TIMER_RATE   // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
76
-#define HAL_TICKS_PER_US       ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
77
-#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / HAL_TICKS_PER_US)
78
-
79
-#define STEP_TIMER_MIN_INTERVAL   8 // minimum time in µs between stepper interrupts
80
-
81
 #define TEMP_TIMER_RATE        1000000
76
 #define TEMP_TIMER_RATE        1000000
82
 #define TEMP_TIMER_FREQUENCY   1000 // temperature interrupt frequency
77
 #define TEMP_TIMER_FREQUENCY   1000 // temperature interrupt frequency
83
 
78
 
84
-#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
79
+#define STEPPER_TIMER_RATE     HAL_TIMER_RATE   // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
80
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
81
+#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
82
+
83
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
84
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
85
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
85
 
86
 
86
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
87
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
87
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
88
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)

+ 15
- 18
Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h View File

47
 typedef uint16_t hal_timer_t;
47
 typedef uint16_t hal_timer_t;
48
 #define HAL_TIMER_TYPE_MAX 0xFFFF
48
 #define HAL_TIMER_TYPE_MAX 0xFFFF
49
 
49
 
50
+#define HAL_TIMER_RATE         (F_CPU)  // frequency of timers peripherals
51
+
52
+#define STEP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
53
+#define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
54
+
50
 #if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
55
 #if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
51
   #define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4
56
   #define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4
52
 #else
57
 #else
53
   #define STEP_TIMER_NUM 5 // for other boards, five is fine.
58
   #define STEP_TIMER_NUM 5 // for other boards, five is fine.
54
 #endif
59
 #endif
55
-
56
-#define STEP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
57
 #define TEMP_TIMER_NUM 2  // index of timer to use for temperature
60
 #define TEMP_TIMER_NUM 2  // index of timer to use for temperature
58
-#define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
59
 #define PULSE_TIMER_NUM STEP_TIMER_NUM
61
 #define PULSE_TIMER_NUM STEP_TIMER_NUM
60
 
62
 
61
-timer_dev* get_timer_dev(int number);
62
-
63
-#define TIMER_DEV(num) get_timer_dev(num)
64
-
65
-#define STEP_TIMER_DEV TIMER_DEV(STEP_TIMER_NUM)
66
-#define TEMP_TIMER_DEV TIMER_DEV(TEMP_TIMER_NUM)
67
-
68
-//STM32_HAVE_TIMER(n);
63
+#define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
64
+#define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
69
 
65
 
70
-#define HAL_TIMER_RATE         (F_CPU)  // frequency of timers peripherals
71
 #define STEPPER_TIMER_PRESCALE 18             // prescaler for setting stepper timer, 4Mhz
66
 #define STEPPER_TIMER_PRESCALE 18             // prescaler for setting stepper timer, 4Mhz
72
 #define STEPPER_TIMER_RATE     (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer
67
 #define STEPPER_TIMER_RATE     (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer
73
-#define HAL_TICKS_PER_US       ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
74
-
75
-#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
68
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
76
 
69
 
77
-#define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
78
-#define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
70
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
71
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
72
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
79
 
73
 
80
-#define STEP_TIMER_MIN_INTERVAL    8 // minimum time in µs between stepper interrupts
74
+timer_dev* get_timer_dev(int number);
75
+#define TIMER_DEV(num) get_timer_dev(num)
76
+#define STEP_TIMER_DEV TIMER_DEV(STEP_TIMER_NUM)
77
+#define TEMP_TIMER_DEV TIMER_DEV(TEMP_TIMER_NUM)
81
 
78
 
82
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN)
79
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN)
83
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN)
80
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN)

+ 9
- 8
Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.h View File

38
 #define hal_timer_t uint32_t  // TODO: One is 16-bit, one 32-bit - does this need to be checked?
38
 #define hal_timer_t uint32_t  // TODO: One is 16-bit, one 32-bit - does this need to be checked?
39
 #define HAL_TIMER_TYPE_MAX 0xFFFF
39
 #define HAL_TIMER_TYPE_MAX 0xFFFF
40
 
40
 
41
-#define STEP_TIMER_NUM 0  // index of timer to use for stepper
42
-#define TEMP_TIMER_NUM 1  // index of timer to use for temperature
43
-
44
 #define HAL_TIMER_RATE         (HAL_RCC_GetSysClockFreq() / 2)  // frequency of timer peripherals
41
 #define HAL_TIMER_RATE         (HAL_RCC_GetSysClockFreq() / 2)  // frequency of timer peripherals
45
-#define STEPPER_TIMER_PRESCALE 54            // was 40,prescaler for setting stepper timer, 2Mhz
46
-#define STEPPER_TIMER_RATE     (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer
47
-#define HAL_TICKS_PER_US       ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
48
 
42
 
43
+#define STEP_TIMER_NUM 0  // index of timer to use for stepper
44
+#define TEMP_TIMER_NUM 1  // index of timer to use for temperature
49
 #define PULSE_TIMER_NUM STEP_TIMER_NUM
45
 #define PULSE_TIMER_NUM STEP_TIMER_NUM
50
-#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
51
 
46
 
52
 #define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
47
 #define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
53
 #define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
48
 #define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
54
 
49
 
55
-#define STEP_TIMER_MIN_INTERVAL    8 // minimum time in µs between stepper interrupts
50
+#define STEPPER_TIMER_PRESCALE 54 // was 40,prescaler for setting stepper timer, 2Mhz
51
+#define STEPPER_TIMER_RATE     (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer
52
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
53
+
54
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
55
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
56
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
56
 
57
 
57
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
58
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
58
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
59
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)

+ 10
- 9
Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h View File

38
 #define hal_timer_t uint32_t  // TODO: One is 16-bit, one 32-bit - does this need to be checked?
38
 #define hal_timer_t uint32_t  // TODO: One is 16-bit, one 32-bit - does this need to be checked?
39
 #define HAL_TIMER_TYPE_MAX 0xFFFF
39
 #define HAL_TIMER_TYPE_MAX 0xFFFF
40
 
40
 
41
-#define STEP_TIMER_NUM 0  // index of timer to use for stepper
42
-#define TEMP_TIMER_NUM 1  // index of timer to use for temperature
43
-
44
 #define HAL_TIMER_RATE         (HAL_RCC_GetSysClockFreq() / 2)  // frequency of timer peripherals
41
 #define HAL_TIMER_RATE         (HAL_RCC_GetSysClockFreq() / 2)  // frequency of timer peripherals
45
-#define STEPPER_TIMER_PRESCALE 54            // was 40,prescaler for setting stepper timer, 2Mhz
46
-#define STEPPER_TIMER_RATE     (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer
47
-#define HAL_TICKS_PER_US       ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
48
 
42
 
43
+#define STEP_TIMER_NUM 0  // index of timer to use for stepper
44
+#define TEMP_TIMER_NUM 1  // index of timer to use for temperature
49
 #define PULSE_TIMER_NUM STEP_TIMER_NUM
45
 #define PULSE_TIMER_NUM STEP_TIMER_NUM
50
-#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
51
 
46
 
52
-#define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
53
 #define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
47
 #define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
48
+#define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
49
+
50
+#define STEPPER_TIMER_PRESCALE 54    // was 40,prescaler for setting stepper timer, 2Mhz
51
+#define STEPPER_TIMER_RATE     (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer
52
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
54
 
53
 
55
-#define STEP_TIMER_MIN_INTERVAL    8 // minimum time in µs between stepper interrupts
54
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
55
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
56
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
56
 
57
 
57
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
58
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
58
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
59
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)

+ 12
- 10
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h View File

43
 typedef uint32_t hal_timer_t;
43
 typedef uint32_t hal_timer_t;
44
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
44
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
45
 
45
 
46
-#define STEP_TIMER_NUM 0
47
-#define TEMP_TIMER_NUM 1
48
-#define PULSE_TIMER_NUM STEP_TIMER_NUM
49
-
50
 #define FTM0_TIMER_PRESCALE 8
46
 #define FTM0_TIMER_PRESCALE 8
51
 #define FTM1_TIMER_PRESCALE 4
47
 #define FTM1_TIMER_PRESCALE 4
52
 #define FTM0_TIMER_PRESCALE_BITS 0b011
48
 #define FTM0_TIMER_PRESCALE_BITS 0b011
56
 #define FTM1_TIMER_RATE (F_BUS / FTM1_TIMER_PRESCALE) // 60MHz / 4 = 15MHz
52
 #define FTM1_TIMER_RATE (F_BUS / FTM1_TIMER_PRESCALE) // 60MHz / 4 = 15MHz
57
 
53
 
58
 #define HAL_TIMER_RATE         (FTM0_TIMER_RATE)
54
 #define HAL_TIMER_RATE         (FTM0_TIMER_RATE)
59
-#define STEPPER_TIMER_RATE     HAL_TIMER_RATE
60
-#define HAL_TICKS_PER_US       ((STEPPER_TIMER_RATE) / 1000000)
61
-#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / HAL_TICKS_PER_US)
62
-#define STEP_TIMER_MIN_INTERVAL   8 // minimum time in µs between stepper interrupts
63
 
55
 
64
-#define TEMP_TIMER_FREQUENCY   1000
56
+#define STEP_TIMER_NUM 0
57
+#define TEMP_TIMER_NUM 1
58
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
59
+
60
+#define TEMP_TIMER_FREQUENCY    1000
61
+
62
+#define STEPPER_TIMER_RATE     HAL_TIMER_RATE
63
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000)
64
+#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
65
 
65
 
66
-#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
66
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
67
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
68
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
67
 
69
 
68
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
70
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
69
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
71
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)

+ 36
- 27
Marlin/src/module/stepper.cpp View File

1263
       #else
1263
       #else
1264
         1
1264
         1
1265
       #endif
1265
       #endif
1266
-      * (HAL_TICKS_PER_US)
1266
+      * (STEPPER_TIMER_TICKS_PER_US)
1267
     );
1267
     );
1268
 
1268
 
1269
     /**
1269
     /**
1316
   // Just update the value we will get at the end of the loop
1316
   // Just update the value we will get at the end of the loop
1317
   step_events_completed += events_to_do;
1317
   step_events_completed += events_to_do;
1318
 
1318
 
1319
-  #if MINIMUM_STEPPER_PULSE
1320
-    // Get the timer count and estimate the end of the pulse
1321
-    hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t((HAL_TICKS_PER_US) * (MINIMUM_STEPPER_PULSE));
1322
-  #endif
1319
+  // Get the timer count and estimate the end of the pulse
1320
+  hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t(MIN_PULSE_TICKS);
1321
+
1322
+  const hal_timer_t added_step_ticks = ADDED_STEP_TICKS;
1323
 
1323
 
1324
   // Take multiple steps per interrupt (For high speed moves)
1324
   // Take multiple steps per interrupt (For high speed moves)
1325
   do {
1325
   do {
1392
     #if MINIMUM_STEPPER_PULSE
1392
     #if MINIMUM_STEPPER_PULSE
1393
       // Just wait for the requested pulse duration
1393
       // Just wait for the requested pulse duration
1394
       while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1394
       while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1395
-      // Add to the value, the value needed for the pulse end and ensuring the maximum driver rate is enforced
1396
-      pulse_end += hal_timer_t(MIN_STEPPER_PULSE_CYCLES) - hal_timer_t((HAL_TICKS_PER_US) * (MINIMUM_STEPPER_PULSE));
1397
     #endif
1395
     #endif
1398
 
1396
 
1397
+    // Add the delay needed to ensure the maximum driver rate is enforced
1398
+    if (signed(added_step_ticks) > 0) pulse_end += hal_timer_t(added_step_ticks);
1399
+
1399
     // Pulse stop
1400
     // Pulse stop
1400
     #if HAS_X_STEP
1401
     #if HAS_X_STEP
1401
       PULSE_STOP(X);
1402
       PULSE_STOP(X);
1423
     // Decrement the count of pending pulses to do
1424
     // Decrement the count of pending pulses to do
1424
     --events_to_do;
1425
     --events_to_do;
1425
 
1426
 
1426
-    #if MINIMUM_STEPPER_PULSE
1427
-      // For minimum pulse time wait after stopping pulses also
1428
-      if (events_to_do) {
1429
-        // Just wait for the requested pulse duration
1430
-        while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1427
+    // For minimum pulse time wait after stopping pulses also
1428
+    if (events_to_do) {
1429
+      // Just wait for the requested pulse duration
1430
+      while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1431
+      #if MINIMUM_STEPPER_PULSE
1431
         // Add to the value, the time that the pulse must be active (to be used on the next loop)
1432
         // Add to the value, the time that the pulse must be active (to be used on the next loop)
1432
-        pulse_end += hal_timer_t((HAL_TICKS_PER_US) * (MINIMUM_STEPPER_PULSE));
1433
-      }
1434
-    #endif
1433
+        pulse_end += hal_timer_t(MIN_PULSE_TICKS);
1434
+      #endif
1435
+    }
1435
 
1436
 
1436
   } while (events_to_do);
1437
   } while (events_to_do);
1437
 }
1438
 }
1810
           REV_E_DIR(active_extruder);
1811
           REV_E_DIR(active_extruder);
1811
       #endif
1812
       #endif
1812
 
1813
 
1814
+    // Get the timer count and estimate the end of the pulse
1815
+    hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t(MIN_PULSE_TICKS);
1816
+
1817
+    const hal_timer_t added_step_ticks = ADDED_STEP_TICKS;
1818
+
1813
     // Step E stepper if we have steps
1819
     // Step E stepper if we have steps
1814
     while (LA_steps) {
1820
     while (LA_steps) {
1815
 
1821
 
1816
-      #if MINIMUM_STEPPER_PULSE
1817
-        hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t((HAL_TICKS_PER_US) * (MINIMUM_STEPPER_PULSE));
1818
-      #endif
1819
-
1822
+      // Set the STEP pulse ON
1820
       #if ENABLED(MIXING_EXTRUDER)
1823
       #if ENABLED(MIXING_EXTRUDER)
1821
         MIXING_STEPPERS_LOOP(j) {
1824
         MIXING_STEPPERS_LOOP(j) {
1822
           // Step mixing steppers (proportionally)
1825
           // Step mixing steppers (proportionally)
1828
         E_STEP_WRITE(active_extruder, !INVERT_E_STEP_PIN);
1831
         E_STEP_WRITE(active_extruder, !INVERT_E_STEP_PIN);
1829
       #endif
1832
       #endif
1830
 
1833
 
1834
+      // Enforce a minimum duration for STEP pulse ON
1831
       #if MINIMUM_STEPPER_PULSE
1835
       #if MINIMUM_STEPPER_PULSE
1832
         // Just wait for the requested pulse duration
1836
         // Just wait for the requested pulse duration
1833
         while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1837
         while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1834
-        // Add to the value, the value needed for the pulse end and ensuring the maximum driver rate is enforced
1835
-        pulse_end += hal_timer_t(MIN_STEPPER_PULSE_CYCLES) - hal_timer_t((HAL_TICKS_PER_US) * (MINIMUM_STEPPER_PULSE));
1836
       #endif
1838
       #endif
1837
 
1839
 
1840
+      // Add the delay needed to ensure the maximum driver rate is enforced
1841
+      if (signed(added_step_ticks) > 0) pulse_end += hal_timer_t(added_step_ticks);
1842
+
1838
       LA_steps < 0 ? ++LA_steps : --LA_steps;
1843
       LA_steps < 0 ? ++LA_steps : --LA_steps;
1839
 
1844
 
1845
+      // Set the STEP pulse OFF
1840
       #if ENABLED(MIXING_EXTRUDER)
1846
       #if ENABLED(MIXING_EXTRUDER)
1841
         MIXING_STEPPERS_LOOP(j) {
1847
         MIXING_STEPPERS_LOOP(j) {
1842
           if (delta_error_m[j] >= 0) {
1848
           if (delta_error_m[j] >= 0) {
1848
         E_STEP_WRITE(active_extruder, INVERT_E_STEP_PIN);
1854
         E_STEP_WRITE(active_extruder, INVERT_E_STEP_PIN);
1849
       #endif
1855
       #endif
1850
 
1856
 
1851
-      #if MINIMUM_STEPPER_PULSE
1852
-        // For minimum pulse time wait before looping
1853
-        // Just wait for the requested pulse duration
1854
-        if (LA_steps) while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1855
-      #endif
1856
-
1857
+      // For minimum pulse time wait before looping
1858
+      // Just wait for the requested pulse duration
1859
+      if (LA_steps) {
1860
+        while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1861
+        #if MINIMUM_STEPPER_PULSE
1862
+          // Add to the value, the time that the pulse must be active (to be used on the next loop)
1863
+          pulse_end += hal_timer_t(MIN_PULSE_TICKS);
1864
+        #endif
1865
+      }
1857
     } // LA_steps
1866
     } // LA_steps
1858
 
1867
 
1859
     return interval;
1868
     return interval;

Loading…
Cancel
Save