Browse Source

Merge pull request #11004 from ejtagle/always_honor_maximum_step_rate

[2.0.x] Fix stepper pulse minimum period and timing calculations
Scott Lahteine 7 years ago
parent
commit
81edbfa665
No account linked to committer's email address

+ 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)

+ 0
- 145
Marlin/src/inc/Conditionals_post.h View File

1444
   #define USE_EXECUTE_COMMANDS_IMMEDIATE
1444
   #define USE_EXECUTE_COMMANDS_IMMEDIATE
1445
 #endif
1445
 #endif
1446
 
1446
 
1447
-// Calculate a default maximum stepper rate, if not supplied
1448
-#ifndef MAXIMUM_STEPPER_RATE
1449
-  #if MINIMUM_STEPPER_PULSE
1450
-    #define MAXIMUM_STEPPER_RATE (1000000UL / (2UL * (MINIMUM_STEPPER_PULSE)))
1451
-  #else
1452
-    #define MAXIMUM_STEPPER_RATE 500000UL
1453
-  #endif
1454
-#endif
1455
-
1456
-//
1457
-// Estimate the amount of time the ISR will take to execute
1458
-//
1459
-#ifdef CPU_32_BIT
1460
-
1461
-  // The base ISR takes 792 cycles
1462
-  #define ISR_BASE_CYCLES  792UL
1463
-
1464
-  // Linear advance base time is 64 cycles
1465
-  #if ENABLED(LIN_ADVANCE)
1466
-    #define ISR_LA_BASE_CYCLES 64UL
1467
-  #else
1468
-    #define ISR_LA_BASE_CYCLES 0UL
1469
-  #endif
1470
-
1471
-  // S curve interpolation adds 40 cycles
1472
-  #if ENABLED(S_CURVE_ACCELERATION)
1473
-    #define ISR_S_CURVE_CYCLES 40UL
1474
-  #else
1475
-    #define ISR_S_CURVE_CYCLES 0UL
1476
-  #endif
1477
-
1478
-  // Stepper Loop base cycles
1479
-  #define ISR_LOOP_BASE_CYCLES 4UL
1480
-
1481
-  // And each stepper takes 16 cycles
1482
-  #define ISR_STEPPER_CYCLES 16UL
1483
-
1484
-#else
1485
-
1486
-  // The base ISR takes 752 cycles
1487
-  #define ISR_BASE_CYCLES  752UL
1488
-
1489
-  // Linear advance base time is 32 cycles
1490
-  #if ENABLED(LIN_ADVANCE)
1491
-    #define ISR_LA_BASE_CYCLES 32UL
1492
-  #else
1493
-    #define ISR_LA_BASE_CYCLES 0UL
1494
-  #endif
1495
-
1496
-  // S curve interpolation adds 160 cycles
1497
-  #if ENABLED(S_CURVE_ACCELERATION)
1498
-    #define ISR_S_CURVE_CYCLES 160UL
1499
-  #else
1500
-    #define ISR_S_CURVE_CYCLES 0UL
1501
-  #endif
1502
-
1503
-  // Stepper Loop base cycles
1504
-  #define ISR_LOOP_BASE_CYCLES 32UL
1505
-
1506
-  // And each stepper takes 88 cycles
1507
-  #define ISR_STEPPER_CYCLES 88UL
1508
-
1509
-#endif
1510
-
1511
-// For each stepper, we add its time
1512
-#ifdef HAS_X_STEP
1513
-  #define ISR_X_STEPPER_CYCLES ISR_STEPPER_CYCLES
1514
-#else
1515
-  #define ISR_X_STEPPER_CYCLES 0UL
1516
-#endif
1517
-
1518
-// For each stepper, we add its time
1519
-#ifdef HAS_Y_STEP
1520
-  #define ISR_Y_STEPPER_CYCLES ISR_STEPPER_CYCLES
1521
-#else
1522
-  #define ISR_Y_STEPPER_CYCLES 0UL
1523
-#endif
1524
-
1525
-// For each stepper, we add its time
1526
-#ifdef HAS_Z_STEP
1527
-  #define ISR_Z_STEPPER_CYCLES ISR_STEPPER_CYCLES
1528
-#else
1529
-  #define ISR_Z_STEPPER_CYCLES 0UL
1530
-#endif
1531
-
1532
-// E is always interpolated, even for mixing extruders
1533
-#define ISR_E_STEPPER_CYCLES ISR_STEPPER_CYCLES
1534
-
1535
-// If linear advance is disabled, then the loop also handles them
1536
-#if DISABLED(LIN_ADVANCE) && ENABLED(MIXING_EXTRUDER)
1537
-  #define ISR_MIXING_STEPPER_CYCLES ((MIXING_STEPPERS) * ISR_STEPPER_CYCLES)
1538
-#else
1539
-  #define ISR_MIXING_STEPPER_CYCLES  0UL
1540
-#endif
1541
-
1542
-// And the total minimum loop time is, without including the base
1543
-#define MIN_ISR_LOOP_CYCLES (ISR_X_STEPPER_CYCLES + ISR_Y_STEPPER_CYCLES + ISR_Z_STEPPER_CYCLES + ISR_E_STEPPER_CYCLES + ISR_MIXING_STEPPER_CYCLES)
1544
-
1545
-// Calculate the minimum MPU cycles needed per pulse to enforce not surpassing the maximum stepper rate
1546
-#define _MIN_STEPPER_PULSE_CYCLES(N) MAX((F_CPU) / (MAXIMUM_STEPPER_RATE), ((F_CPU) / 500000UL) * (N))
1547
-#if MINIMUM_STEPPER_PULSE
1548
-  #define MIN_STEPPER_PULSE_CYCLES _MIN_STEPPER_PULSE_CYCLES(MINIMUM_STEPPER_PULSE)
1549
-#else
1550
-  #define MIN_STEPPER_PULSE_CYCLES _MIN_STEPPER_PULSE_CYCLES(1)
1551
-#endif
1552
-
1553
-// But the user could be enforcing a minimum time, so the loop time is
1554
-#define ISR_LOOP_CYCLES (ISR_LOOP_BASE_CYCLES + MAX(MIN_STEPPER_PULSE_CYCLES, MIN_ISR_LOOP_CYCLES))
1555
-
1556
-// If linear advance is enabled, then it is handled separately
1557
-#if ENABLED(LIN_ADVANCE)
1558
-
1559
-  // Estimate the minimum LA loop time
1560
-  #if ENABLED(MIXING_EXTRUDER)
1561
-    #define MIN_ISR_LA_LOOP_CYCLES ((MIXING_STEPPERS) * (ISR_STEPPER_CYCLES))
1562
-  #else
1563
-    #define MIN_ISR_LA_LOOP_CYCLES ISR_STEPPER_CYCLES
1564
-  #endif
1565
-
1566
-  // And the real loop time
1567
-  #define ISR_LA_LOOP_CYCLES MAX(MIN_STEPPER_PULSE_CYCLES, MIN_ISR_LA_LOOP_CYCLES)
1568
-
1569
-#else
1570
-  #define ISR_LA_LOOP_CYCLES 0UL
1571
-#endif
1572
-
1573
-// Now estimate the total ISR execution time in cycles given a step per ISR multiplier
1574
-#define ISR_EXECUTION_CYCLES(rate) (((ISR_BASE_CYCLES + ISR_S_CURVE_CYCLES + (ISR_LOOP_CYCLES * rate) + ISR_LA_BASE_CYCLES + ISR_LA_LOOP_CYCLES)) / rate)
1575
-
1576
-// The maximum allowable stepping frequency when doing x128-x1 stepping (in Hz)
1577
-#define MAX_128X_STEP_ISR_FREQUENCY (F_CPU / ISR_EXECUTION_CYCLES(128))
1578
-#define MAX_64X_STEP_ISR_FREQUENCY  (F_CPU / ISR_EXECUTION_CYCLES(64))
1579
-#define MAX_32X_STEP_ISR_FREQUENCY  (F_CPU / ISR_EXECUTION_CYCLES(32))
1580
-#define MAX_16X_STEP_ISR_FREQUENCY  (F_CPU / ISR_EXECUTION_CYCLES(16))
1581
-#define MAX_8X_STEP_ISR_FREQUENCY   (F_CPU / ISR_EXECUTION_CYCLES(8))
1582
-#define MAX_4X_STEP_ISR_FREQUENCY   (F_CPU / ISR_EXECUTION_CYCLES(4))
1583
-#define MAX_2X_STEP_ISR_FREQUENCY   (F_CPU / ISR_EXECUTION_CYCLES(2))
1584
-#define MAX_1X_STEP_ISR_FREQUENCY   (F_CPU / ISR_EXECUTION_CYCLES(1))
1585
-
1586
-// The minimum allowable frequency for step smoothing will be 1/10 of the maximum nominal frequency (in Hz)
1587
-#define MIN_STEP_ISR_FREQUENCY    MAX_1X_STEP_ISR_FREQUENCY
1588
-
1589
-// Disable multiple steps per ISR
1590
-//#define DISABLE_MULTI_STEPPING
1591
-
1592
 #endif // CONDITIONALS_POST_H
1447
 #endif // CONDITIONALS_POST_H

+ 37
- 28
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
 }
1664
         uint32_t max_rate = current_block->nominal_rate;  // Get the maximum rate (maximum event speed)
1665
         uint32_t max_rate = current_block->nominal_rate;  // Get the maximum rate (maximum event speed)
1665
         while (max_rate < MIN_STEP_ISR_FREQUENCY) {
1666
         while (max_rate < MIN_STEP_ISR_FREQUENCY) {
1666
           max_rate <<= 1;
1667
           max_rate <<= 1;
1667
-          if (max_rate >= MAX_1X_STEP_ISR_FREQUENCY) break;
1668
+          if (max_rate >= MAX_STEP_ISR_FREQUENCY_1X) break;
1668
           ++oversampling;
1669
           ++oversampling;
1669
         }
1670
         }
1670
         oversampling_factor = oversampling;
1671
         oversampling_factor = oversampling;
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;

+ 165
- 13
Marlin/src/module/stepper.h View File

43
 #ifndef STEPPER_H
43
 #ifndef STEPPER_H
44
 #define STEPPER_H
44
 #define STEPPER_H
45
 
45
 
46
+#include "../inc/MarlinConfig.h"
47
+
48
+// Disable multiple steps per ISR
49
+//#define DISABLE_MULTI_STEPPING
50
+
51
+//
52
+// Estimate the amount of time the Stepper ISR will take to execute
53
+//
54
+
55
+#ifndef MINIMUM_STEPPER_PULSE
56
+  #define MINIMUM_STEPPER_PULSE 0
57
+#endif
58
+
59
+#ifndef MAXIMUM_STEPPER_RATE
60
+  #if MINIMUM_STEPPER_PULSE
61
+    #define MAXIMUM_STEPPER_RATE (1000000UL / (2UL * (MINIMUM_STEPPER_PULSE)))
62
+  #else
63
+    #define MAXIMUM_STEPPER_RATE 500000UL
64
+  #endif
65
+#endif
66
+
67
+#ifdef CPU_32_BIT
68
+
69
+  // The base ISR takes 792 cycles
70
+  #define ISR_BASE_CYCLES  792UL
71
+
72
+  // Linear advance base time is 64 cycles
73
+  #if ENABLED(LIN_ADVANCE)
74
+    #define ISR_LA_BASE_CYCLES 64UL
75
+  #else
76
+    #define ISR_LA_BASE_CYCLES 0UL
77
+  #endif
78
+
79
+  // S curve interpolation adds 40 cycles
80
+  #if ENABLED(S_CURVE_ACCELERATION)
81
+    #define ISR_S_CURVE_CYCLES 40UL
82
+  #else
83
+    #define ISR_S_CURVE_CYCLES 0UL
84
+  #endif
85
+
86
+  // Stepper Loop base cycles
87
+  #define ISR_LOOP_BASE_CYCLES 4UL
88
+
89
+  // And each stepper takes 16 cycles
90
+  #define ISR_STEPPER_CYCLES 16UL
91
+
92
+#else
93
+
94
+  // The base ISR takes 752 cycles
95
+  #define ISR_BASE_CYCLES  752UL
96
+
97
+  // Linear advance base time is 32 cycles
98
+  #if ENABLED(LIN_ADVANCE)
99
+    #define ISR_LA_BASE_CYCLES 32UL
100
+  #else
101
+    #define ISR_LA_BASE_CYCLES 0UL
102
+  #endif
103
+
104
+  // S curve interpolation adds 160 cycles
105
+  #if ENABLED(S_CURVE_ACCELERATION)
106
+    #define ISR_S_CURVE_CYCLES 160UL
107
+  #else
108
+    #define ISR_S_CURVE_CYCLES 0UL
109
+  #endif
110
+
111
+  // Stepper Loop base cycles
112
+  #define ISR_LOOP_BASE_CYCLES 32UL
113
+
114
+  // And each stepper takes 88 cycles
115
+  #define ISR_STEPPER_CYCLES 88UL
116
+
117
+#endif
118
+
119
+// Add time for each stepper
120
+#ifdef HAS_X_STEP
121
+  #define ISR_X_STEPPER_CYCLES ISR_STEPPER_CYCLES
122
+#else
123
+  #define ISR_X_STEPPER_CYCLES 0UL
124
+#endif
125
+#ifdef HAS_Y_STEP
126
+  #define ISR_Y_STEPPER_CYCLES ISR_STEPPER_CYCLES
127
+#else
128
+  #define ISR_Y_STEPPER_CYCLES 0UL
129
+#endif
130
+#ifdef HAS_Z_STEP
131
+  #define ISR_Z_STEPPER_CYCLES ISR_STEPPER_CYCLES
132
+#else
133
+  #define ISR_Z_STEPPER_CYCLES 0UL
134
+#endif
135
+
136
+// E is always interpolated, even for mixing extruders
137
+#define ISR_E_STEPPER_CYCLES ISR_STEPPER_CYCLES
138
+
139
+// If linear advance is disabled, then the loop also handles them
140
+#if DISABLED(LIN_ADVANCE) && ENABLED(MIXING_EXTRUDER)
141
+  #define ISR_MIXING_STEPPER_CYCLES ((MIXING_STEPPERS) * (ISR_STEPPER_CYCLES))
142
+#else
143
+  #define ISR_MIXING_STEPPER_CYCLES  0UL
144
+#endif
145
+
146
+// And the total minimum loop time, not including the base
147
+#define MIN_ISR_LOOP_CYCLES (ISR_X_STEPPER_CYCLES + ISR_Y_STEPPER_CYCLES + ISR_Z_STEPPER_CYCLES + ISR_E_STEPPER_CYCLES + ISR_MIXING_STEPPER_CYCLES)
148
+
149
+// Calculate the minimum MPU cycles needed per pulse to enforce, limited to the max stepper rate
150
+#define _MIN_STEPPER_PULSE_CYCLES(N) max((F_CPU) / (MAXIMUM_STEPPER_RATE), ((F_CPU) / 500000UL) * (N))
151
+#if MINIMUM_STEPPER_PULSE
152
+  #define MIN_STEPPER_PULSE_CYCLES _MIN_STEPPER_PULSE_CYCLES(MINIMUM_STEPPER_PULSE)
153
+#else
154
+  #define MIN_STEPPER_PULSE_CYCLES _MIN_STEPPER_PULSE_CYCLES(1)
155
+#endif
156
+
157
+#define MIN_PULSE_TICKS  ((PULSE_TIMER_TICKS_PER_US) * (MINIMUM_STEPPER_PULSE))
158
+#define ADDED_STEP_TICKS ((MIN_STEPPER_PULSE_CYCLES) / (PULSE_TIMER_PRESCALE) - MIN_PULSE_TICKS)
159
+
160
+// But the user could be enforcing a minimum time, so the loop time is
161
+#define ISR_LOOP_CYCLES (ISR_LOOP_BASE_CYCLES + max(MIN_STEPPER_PULSE_CYCLES, MIN_ISR_LOOP_CYCLES))
162
+
163
+// If linear advance is enabled, then it is handled separately
164
+#if ENABLED(LIN_ADVANCE)
165
+
166
+  // Estimate the minimum LA loop time
167
+  #if ENABLED(MIXING_EXTRUDER)
168
+    #define MIN_ISR_LA_LOOP_CYCLES ((MIXING_STEPPERS) * (ISR_STEPPER_CYCLES))
169
+  #else
170
+    #define MIN_ISR_LA_LOOP_CYCLES ISR_STEPPER_CYCLES
171
+  #endif
172
+
173
+  // And the real loop time
174
+  #define ISR_LA_LOOP_CYCLES max(MIN_STEPPER_PULSE_CYCLES, MIN_ISR_LA_LOOP_CYCLES)
175
+
176
+#else
177
+  #define ISR_LA_LOOP_CYCLES 0UL
178
+#endif
179
+
180
+// Now estimate the total ISR execution time in cycles given a step per ISR multiplier
181
+#define ISR_EXECUTION_CYCLES(R) (((ISR_BASE_CYCLES + ISR_S_CURVE_CYCLES + (ISR_LOOP_CYCLES) * (R) + ISR_LA_BASE_CYCLES + ISR_LA_LOOP_CYCLES)) / (R))
182
+
183
+// The maximum allowable stepping frequency when doing x128-x1 stepping (in Hz)
184
+#define MAX_STEP_ISR_FREQUENCY_128X ((F_CPU) / ISR_EXECUTION_CYCLES(128))
185
+#define MAX_STEP_ISR_FREQUENCY_64X  ((F_CPU) / ISR_EXECUTION_CYCLES(64))
186
+#define MAX_STEP_ISR_FREQUENCY_32X  ((F_CPU) / ISR_EXECUTION_CYCLES(32))
187
+#define MAX_STEP_ISR_FREQUENCY_16X  ((F_CPU) / ISR_EXECUTION_CYCLES(16))
188
+#define MAX_STEP_ISR_FREQUENCY_8X   ((F_CPU) / ISR_EXECUTION_CYCLES(8))
189
+#define MAX_STEP_ISR_FREQUENCY_4X   ((F_CPU) / ISR_EXECUTION_CYCLES(4))
190
+#define MAX_STEP_ISR_FREQUENCY_2X   ((F_CPU) / ISR_EXECUTION_CYCLES(2))
191
+#define MAX_STEP_ISR_FREQUENCY_1X   ((F_CPU) / ISR_EXECUTION_CYCLES(1))
192
+
193
+// The minimum allowable frequency for step smoothing will be 1/10 of the maximum nominal frequency (in Hz)
194
+#define MIN_STEP_ISR_FREQUENCY MAX_STEP_ISR_FREQUENCY_1X
195
+
196
+//
197
+// Stepper class definition
198
+//
199
+
46
 #include "stepper_indirection.h"
200
 #include "stepper_indirection.h"
47
 
201
 
48
 #ifdef __AVR__
202
 #ifdef __AVR__
49
   #include "speed_lookuptable.h"
203
   #include "speed_lookuptable.h"
50
 #endif
204
 #endif
51
 
205
 
52
-#include "../inc/MarlinConfig.h"
53
 #include "../module/planner.h"
206
 #include "../module/planner.h"
54
 #include "../core/language.h"
207
 #include "../core/language.h"
55
 
208
 
56
-class Stepper;
57
-extern Stepper stepper;
58
-
59
 class Stepper {
209
 class Stepper {
60
 
210
 
61
   public:
211
   public:
303
 
453
 
304
         // The stepping frequency limits for each multistepping rate
454
         // The stepping frequency limits for each multistepping rate
305
         static const uint32_t limit[] PROGMEM = {
455
         static const uint32_t limit[] PROGMEM = {
306
-          (  MAX_1X_STEP_ISR_FREQUENCY     ),
307
-          (  MAX_2X_STEP_ISR_FREQUENCY >> 1),
308
-          (  MAX_4X_STEP_ISR_FREQUENCY >> 2),
309
-          (  MAX_8X_STEP_ISR_FREQUENCY >> 3),
310
-          ( MAX_16X_STEP_ISR_FREQUENCY >> 4),
311
-          ( MAX_32X_STEP_ISR_FREQUENCY >> 5),
312
-          ( MAX_64X_STEP_ISR_FREQUENCY >> 6),
313
-          (MAX_128X_STEP_ISR_FREQUENCY >> 7)
456
+          (  MAX_STEP_ISR_FREQUENCY_1X     ),
457
+          (  MAX_STEP_ISR_FREQUENCY_2X >> 1),
458
+          (  MAX_STEP_ISR_FREQUENCY_4X >> 2),
459
+          (  MAX_STEP_ISR_FREQUENCY_8X >> 3),
460
+          ( MAX_STEP_ISR_FREQUENCY_16X >> 4),
461
+          ( MAX_STEP_ISR_FREQUENCY_32X >> 5),
462
+          ( MAX_STEP_ISR_FREQUENCY_64X >> 6),
463
+          (MAX_STEP_ISR_FREQUENCY_128X >> 7)
314
         };
464
         };
315
 
465
 
316
         // Select the proper multistepping
466
         // Select the proper multistepping
321
           ++idx;
471
           ++idx;
322
         };
472
         };
323
       #else
473
       #else
324
-        NOMORE(step_rate, uint32_t(MAX_1X_STEP_ISR_FREQUENCY));
474
+        NOMORE(step_rate, uint32_t(MAX_STEP_ISR_FREQUENCY_1X));
325
       #endif
475
       #endif
326
       *loops = multistep;
476
       *loops = multistep;
327
 
477
 
367
 
517
 
368
 };
518
 };
369
 
519
 
520
+extern Stepper stepper;
521
+
370
 #endif // STEPPER_H
522
 #endif // STEPPER_H

Loading…
Cancel
Save