|
@@ -217,18 +217,12 @@ uint32_t Stepper::advance_divisor = 0,
|
217
|
217
|
#endif
|
218
|
218
|
|
219
|
219
|
#if ENABLED(LIN_ADVANCE)
|
220
|
|
-
|
221
|
220
|
uint32_t Stepper::nextAdvanceISR = LA_ADV_NEVER,
|
222
|
|
- Stepper::LA_isr_rate = LA_ADV_NEVER;
|
223
|
|
- uint16_t Stepper::LA_current_adv_steps = 0,
|
224
|
|
- Stepper::LA_final_adv_steps,
|
225
|
|
- Stepper::LA_max_adv_steps;
|
226
|
|
-
|
227
|
|
- int8_t Stepper::LA_steps = 0;
|
228
|
|
-
|
229
|
|
- bool Stepper::LA_use_advance_lead;
|
230
|
|
-
|
231
|
|
-#endif // LIN_ADVANCE
|
|
221
|
+ Stepper::la_interval = LA_ADV_NEVER;
|
|
222
|
+ int32_t Stepper::la_delta_error = 0,
|
|
223
|
+ Stepper::la_dividend = 0,
|
|
224
|
+ Stepper::la_advance_steps = 0;
|
|
225
|
+#endif
|
232
|
226
|
|
233
|
227
|
#if ENABLED(INTEGRATED_BABYSTEPPING)
|
234
|
228
|
uint32_t Stepper::nextBabystepISR = BABYSTEP_NEVER;
|
|
@@ -588,29 +582,27 @@ void Stepper::set_directions() {
|
588
|
582
|
TERN_(HAS_V_DIR, SET_STEP_DIR(V));
|
589
|
583
|
TERN_(HAS_W_DIR, SET_STEP_DIR(W));
|
590
|
584
|
|
591
|
|
- #if DISABLED(LIN_ADVANCE)
|
592
|
|
- #if ENABLED(MIXING_EXTRUDER)
|
593
|
|
- // Because this is valid for the whole block we don't know
|
594
|
|
- // what E steppers will step. Likely all. Set all.
|
595
|
|
- if (motor_direction(E_AXIS)) {
|
596
|
|
- MIXER_STEPPER_LOOP(j) REV_E_DIR(j);
|
597
|
|
- count_direction.e = -1;
|
598
|
|
- }
|
599
|
|
- else {
|
600
|
|
- MIXER_STEPPER_LOOP(j) NORM_E_DIR(j);
|
601
|
|
- count_direction.e = 1;
|
602
|
|
- }
|
603
|
|
- #elif HAS_EXTRUDERS
|
604
|
|
- if (motor_direction(E_AXIS)) {
|
605
|
|
- REV_E_DIR(stepper_extruder);
|
606
|
|
- count_direction.e = -1;
|
607
|
|
- }
|
608
|
|
- else {
|
609
|
|
- NORM_E_DIR(stepper_extruder);
|
610
|
|
- count_direction.e = 1;
|
611
|
|
- }
|
612
|
|
- #endif
|
613
|
|
- #endif // !LIN_ADVANCE
|
|
585
|
+ #if ENABLED(MIXING_EXTRUDER)
|
|
586
|
+ // Because this is valid for the whole block we don't know
|
|
587
|
+ // what E steppers will step. Likely all. Set all.
|
|
588
|
+ if (motor_direction(E_AXIS)) {
|
|
589
|
+ MIXER_STEPPER_LOOP(j) REV_E_DIR(j);
|
|
590
|
+ count_direction.e = -1;
|
|
591
|
+ }
|
|
592
|
+ else {
|
|
593
|
+ MIXER_STEPPER_LOOP(j) NORM_E_DIR(j);
|
|
594
|
+ count_direction.e = 1;
|
|
595
|
+ }
|
|
596
|
+ #elif HAS_EXTRUDERS
|
|
597
|
+ if (motor_direction(E_AXIS)) {
|
|
598
|
+ REV_E_DIR(stepper_extruder);
|
|
599
|
+ count_direction.e = -1;
|
|
600
|
+ }
|
|
601
|
+ else {
|
|
602
|
+ NORM_E_DIR(stepper_extruder);
|
|
603
|
+ count_direction.e = 1;
|
|
604
|
+ }
|
|
605
|
+ #endif
|
614
|
606
|
|
615
|
607
|
DIR_WAIT_AFTER();
|
616
|
608
|
}
|
|
@@ -1467,14 +1459,19 @@ void Stepper::isr() {
|
1467
|
1459
|
// Enable ISRs to reduce USART processing latency
|
1468
|
1460
|
hal.isr_on();
|
1469
|
1461
|
|
1470
|
|
- if (!nextMainISR) pulse_phase_isr(); // 0 = Do coordinated axes Stepper pulses
|
|
1462
|
+ if (!nextMainISR) pulse_phase_isr(); // 0 = Do coordinated axes Stepper pulses
|
1471
|
1463
|
|
1472
|
1464
|
#if ENABLED(LIN_ADVANCE)
|
1473
|
|
- if (!nextAdvanceISR) nextAdvanceISR = advance_isr(); // 0 = Do Linear Advance E Stepper pulses
|
|
1465
|
+ if (!nextAdvanceISR) { // 0 = Do Linear Advance E Stepper pulses
|
|
1466
|
+ advance_isr();
|
|
1467
|
+ nextAdvanceISR = la_interval;
|
|
1468
|
+ }
|
|
1469
|
+ else if (nextAdvanceISR == LA_ADV_NEVER) // Start LA steps if necessary
|
|
1470
|
+ nextAdvanceISR = la_interval;
|
1474
|
1471
|
#endif
|
1475
|
1472
|
|
1476
|
1473
|
#if ENABLED(INTEGRATED_BABYSTEPPING)
|
1477
|
|
- const bool is_babystep = (nextBabystepISR == 0); // 0 = Do Babystepping (XY)Z pulses
|
|
1474
|
+ const bool is_babystep = (nextBabystepISR == 0); // 0 = Do Babystepping (XY)Z pulses
|
1478
|
1475
|
if (is_babystep) nextBabystepISR = babystepping_isr();
|
1479
|
1476
|
#endif
|
1480
|
1477
|
|
|
@@ -1796,20 +1793,18 @@ void Stepper::pulse_phase_isr() {
|
1796
|
1793
|
PULSE_PREP(W);
|
1797
|
1794
|
#endif
|
1798
|
1795
|
|
1799
|
|
- #if EITHER(LIN_ADVANCE, MIXING_EXTRUDER)
|
1800
|
|
- delta_error.e += advance_dividend.e;
|
1801
|
|
- if (delta_error.e >= 0) {
|
1802
|
|
- #if ENABLED(LIN_ADVANCE)
|
1803
|
|
- delta_error.e -= advance_divisor;
|
1804
|
|
- // Don't step E here - But remember the number of steps to perform
|
1805
|
|
- motor_direction(E_AXIS) ? --LA_steps : ++LA_steps;
|
1806
|
|
- #else
|
1807
|
|
- count_position.e += count_direction.e;
|
1808
|
|
- step_needed.e = true;
|
1809
|
|
- #endif
|
1810
|
|
- }
|
1811
|
|
- #elif HAS_E0_STEP
|
|
1796
|
+ #if EITHER(HAS_E0_STEP, MIXING_EXTRUDER)
|
1812
|
1797
|
PULSE_PREP(E);
|
|
1798
|
+
|
|
1799
|
+ #if ENABLED(LIN_ADVANCE)
|
|
1800
|
+ if (step_needed.e && current_block->la_advance_rate) {
|
|
1801
|
+ // don't actually step here, but do subtract movements steps
|
|
1802
|
+ // from the linear advance step count
|
|
1803
|
+ step_needed.e = false;
|
|
1804
|
+ count_position.e -= count_direction.e;
|
|
1805
|
+ la_advance_steps--;
|
|
1806
|
+ }
|
|
1807
|
+ #endif
|
1813
|
1808
|
#endif
|
1814
|
1809
|
}
|
1815
|
1810
|
|
|
@@ -1849,12 +1844,10 @@ void Stepper::pulse_phase_isr() {
|
1849
|
1844
|
PULSE_START(W);
|
1850
|
1845
|
#endif
|
1851
|
1846
|
|
1852
|
|
- #if DISABLED(LIN_ADVANCE)
|
1853
|
|
- #if ENABLED(MIXING_EXTRUDER)
|
1854
|
|
- if (step_needed.e) E_STEP_WRITE(mixer.get_next_stepper(), !INVERT_E_STEP_PIN);
|
1855
|
|
- #elif HAS_E0_STEP
|
1856
|
|
- PULSE_START(E);
|
1857
|
|
- #endif
|
|
1847
|
+ #if ENABLED(MIXING_EXTRUDER)
|
|
1848
|
+ if (step_needed.e) E_STEP_WRITE(mixer.get_next_stepper(), !INVERT_E_STEP_PIN);
|
|
1849
|
+ #elif HAS_E0_STEP
|
|
1850
|
+ PULSE_START(E);
|
1858
|
1851
|
#endif
|
1859
|
1852
|
|
1860
|
1853
|
TERN_(I2S_STEPPER_STREAM, i2s_push_sample());
|
|
@@ -1894,15 +1887,10 @@ void Stepper::pulse_phase_isr() {
|
1894
|
1887
|
PULSE_STOP(W);
|
1895
|
1888
|
#endif
|
1896
|
1889
|
|
1897
|
|
- #if DISABLED(LIN_ADVANCE)
|
1898
|
|
- #if ENABLED(MIXING_EXTRUDER)
|
1899
|
|
- if (delta_error.e >= 0) {
|
1900
|
|
- delta_error.e -= advance_divisor;
|
1901
|
|
- E_STEP_WRITE(mixer.get_stepper(), INVERT_E_STEP_PIN);
|
1902
|
|
- }
|
1903
|
|
- #elif HAS_E0_STEP
|
1904
|
|
- PULSE_STOP(E);
|
1905
|
|
- #endif
|
|
1890
|
+ #if ENABLED(MIXING_EXTRUDER)
|
|
1891
|
+ if (step_needed.e) E_STEP_WRITE(mixer.get_stepper(), INVERT_E_STEP_PIN);
|
|
1892
|
+ #elif HAS_E0_STEP
|
|
1893
|
+ PULSE_STOP(E);
|
1906
|
1894
|
#endif
|
1907
|
1895
|
|
1908
|
1896
|
#if ISR_MULTI_STEPS
|
|
@@ -1912,6 +1900,69 @@ void Stepper::pulse_phase_isr() {
|
1912
|
1900
|
} while (--events_to_do);
|
1913
|
1901
|
}
|
1914
|
1902
|
|
|
1903
|
+// Calculate timer interval, with all limits applied.
|
|
1904
|
+uint32_t Stepper::calc_timer_interval(uint32_t step_rate) {
|
|
1905
|
+ #ifdef CPU_32_BIT
|
|
1906
|
+ // In case of high-performance processor, it is able to calculate in real-time
|
|
1907
|
+ return uint32_t(STEPPER_TIMER_RATE) / step_rate;
|
|
1908
|
+ #else
|
|
1909
|
+ // AVR is able to keep up at 30khz Stepping ISR rate.
|
|
1910
|
+ constexpr uint32_t min_step_rate = (F_CPU) / 500000U;
|
|
1911
|
+ if (step_rate <= min_step_rate) {
|
|
1912
|
+ step_rate = 0;
|
|
1913
|
+ uintptr_t table_address = (uintptr_t)&speed_lookuptable_slow[0][0];
|
|
1914
|
+ return uint16_t(pgm_read_word(table_address));
|
|
1915
|
+ }
|
|
1916
|
+ else {
|
|
1917
|
+ step_rate -= min_step_rate; // Correct for minimal speed
|
|
1918
|
+ if (step_rate >= 0x0800) { // higher step rate
|
|
1919
|
+ const uint8_t rate_mod_256 = (step_rate & 0x00FF);
|
|
1920
|
+ const uintptr_t table_address = uintptr_t(&speed_lookuptable_fast[uint8_t(step_rate >> 8)][0]),
|
|
1921
|
+ gain = uint16_t(pgm_read_word(table_address + 2));
|
|
1922
|
+ return uint16_t(pgm_read_word(table_address)) - MultiU16X8toH16(rate_mod_256, gain);
|
|
1923
|
+ }
|
|
1924
|
+ else { // lower step rates
|
|
1925
|
+ uintptr_t table_address = uintptr_t(&speed_lookuptable_slow[0][0]);
|
|
1926
|
+ table_address += (step_rate >> 1) & 0xFFFC;
|
|
1927
|
+ return uint16_t(pgm_read_word(table_address))
|
|
1928
|
+ - ((uint16_t(pgm_read_word(table_address + 2)) * uint8_t(step_rate & 0x0007)) >> 3);
|
|
1929
|
+ }
|
|
1930
|
+ }
|
|
1931
|
+ #endif
|
|
1932
|
+}
|
|
1933
|
+
|
|
1934
|
+// Get the timer interval and the number of loops to perform per tick
|
|
1935
|
+uint32_t Stepper::calc_timer_interval(uint32_t step_rate, uint8_t &loops) {
|
|
1936
|
+ uint8_t multistep = 1;
|
|
1937
|
+ #if DISABLED(DISABLE_MULTI_STEPPING)
|
|
1938
|
+
|
|
1939
|
+ // The stepping frequency limits for each multistepping rate
|
|
1940
|
+ static const uint32_t limit[] PROGMEM = {
|
|
1941
|
+ ( MAX_STEP_ISR_FREQUENCY_1X ),
|
|
1942
|
+ ( MAX_STEP_ISR_FREQUENCY_2X >> 1),
|
|
1943
|
+ ( MAX_STEP_ISR_FREQUENCY_4X >> 2),
|
|
1944
|
+ ( MAX_STEP_ISR_FREQUENCY_8X >> 3),
|
|
1945
|
+ ( MAX_STEP_ISR_FREQUENCY_16X >> 4),
|
|
1946
|
+ ( MAX_STEP_ISR_FREQUENCY_32X >> 5),
|
|
1947
|
+ ( MAX_STEP_ISR_FREQUENCY_64X >> 6),
|
|
1948
|
+ (MAX_STEP_ISR_FREQUENCY_128X >> 7)
|
|
1949
|
+ };
|
|
1950
|
+
|
|
1951
|
+ // Select the proper multistepping
|
|
1952
|
+ uint8_t idx = 0;
|
|
1953
|
+ while (idx < 7 && step_rate > (uint32_t)pgm_read_dword(&limit[idx])) {
|
|
1954
|
+ step_rate >>= 1;
|
|
1955
|
+ multistep <<= 1;
|
|
1956
|
+ ++idx;
|
|
1957
|
+ };
|
|
1958
|
+ #else
|
|
1959
|
+ NOMORE(step_rate, uint32_t(MAX_STEP_ISR_FREQUENCY_1X));
|
|
1960
|
+ #endif
|
|
1961
|
+ loops = multistep;
|
|
1962
|
+
|
|
1963
|
+ return calc_timer_interval(step_rate);
|
|
1964
|
+}
|
|
1965
|
+
|
1915
|
1966
|
// This is the last half of the stepper interrupt: This one processes and
|
1916
|
1967
|
// properly schedules blocks from the planner. This is executed after creating
|
1917
|
1968
|
// the step pulses, so it is not time critical, as pulses are already done.
|
|
@@ -1964,15 +2015,14 @@ uint32_t Stepper::block_phase_isr() {
|
1964
|
2015
|
// acc_step_rate is in steps/second
|
1965
|
2016
|
|
1966
|
2017
|
// step_rate to timer interval and steps per stepper isr
|
1967
|
|
- interval = calc_timer_interval(acc_step_rate, &steps_per_isr);
|
|
2018
|
+ interval = calc_timer_interval(acc_step_rate << oversampling_factor, steps_per_isr);
|
1968
|
2019
|
acceleration_time += interval;
|
1969
|
2020
|
|
1970
|
2021
|
#if ENABLED(LIN_ADVANCE)
|
1971
|
|
- if (LA_use_advance_lead) {
|
1972
|
|
- // Fire ISR if final adv_rate is reached
|
1973
|
|
- if (LA_steps && LA_isr_rate != current_block->advance_speed) nextAdvanceISR = 0;
|
|
2022
|
+ if (current_block->la_advance_rate) {
|
|
2023
|
+ const uint32_t la_step_rate = la_advance_steps < current_block->max_adv_steps ? current_block->la_advance_rate : 0;
|
|
2024
|
+ la_interval = calc_timer_interval(acc_step_rate + la_step_rate) << current_block->la_scaling;
|
1974
|
2025
|
}
|
1975
|
|
- else if (LA_steps) nextAdvanceISR = 0;
|
1976
|
2026
|
#endif
|
1977
|
2027
|
|
1978
|
2028
|
/**
|
|
@@ -2035,18 +2085,41 @@ uint32_t Stepper::block_phase_isr() {
|
2035
|
2085
|
#endif
|
2036
|
2086
|
|
2037
|
2087
|
// step_rate to timer interval and steps per stepper isr
|
2038
|
|
- interval = calc_timer_interval(step_rate, &steps_per_isr);
|
|
2088
|
+ interval = calc_timer_interval(step_rate << oversampling_factor, steps_per_isr);
|
2039
|
2089
|
deceleration_time += interval;
|
2040
|
2090
|
|
2041
|
2091
|
#if ENABLED(LIN_ADVANCE)
|
2042
|
|
- if (LA_use_advance_lead) {
|
2043
|
|
- // Wake up eISR on first deceleration loop and fire ISR if final adv_rate is reached
|
2044
|
|
- if (step_events_completed <= decelerate_after + steps_per_isr || (LA_steps && LA_isr_rate != current_block->advance_speed)) {
|
2045
|
|
- initiateLA();
|
2046
|
|
- LA_isr_rate = current_block->advance_speed;
|
|
2092
|
+ if (current_block->la_advance_rate) {
|
|
2093
|
+ const uint32_t la_step_rate = la_advance_steps > current_block->final_adv_steps ? current_block->la_advance_rate : 0;
|
|
2094
|
+ if (la_step_rate != step_rate) {
|
|
2095
|
+ bool reverse_e = la_step_rate > step_rate;
|
|
2096
|
+ la_interval = calc_timer_interval(reverse_e ? la_step_rate - step_rate : step_rate - la_step_rate) << current_block->la_scaling;
|
|
2097
|
+
|
|
2098
|
+ if (reverse_e != motor_direction(E_AXIS)) {
|
|
2099
|
+ TBI(last_direction_bits, E_AXIS);
|
|
2100
|
+ count_direction.e = -count_direction.e;
|
|
2101
|
+
|
|
2102
|
+ DIR_WAIT_BEFORE();
|
|
2103
|
+
|
|
2104
|
+ if (reverse_e) {
|
|
2105
|
+ #if ENABLED(MIXING_EXTRUDER)
|
|
2106
|
+ MIXER_STEPPER_LOOP(j) REV_E_DIR(j);
|
|
2107
|
+ #else
|
|
2108
|
+ REV_E_DIR(stepper_extruder);
|
|
2109
|
+ #endif
|
|
2110
|
+ }
|
|
2111
|
+ else {
|
|
2112
|
+ #if ENABLED(MIXING_EXTRUDER)
|
|
2113
|
+ MIXER_STEPPER_LOOP(j) NORM_E_DIR(j);
|
|
2114
|
+ #else
|
|
2115
|
+ NORM_E_DIR(stepper_extruder);
|
|
2116
|
+ #endif
|
|
2117
|
+ }
|
|
2118
|
+
|
|
2119
|
+ DIR_WAIT_AFTER();
|
|
2120
|
+ }
|
2047
|
2121
|
}
|
2048
|
2122
|
}
|
2049
|
|
- else if (LA_steps) nextAdvanceISR = 0;
|
2050
|
2123
|
#endif // LIN_ADVANCE
|
2051
|
2124
|
|
2052
|
2125
|
/*
|
|
@@ -2069,15 +2142,15 @@ uint32_t Stepper::block_phase_isr() {
|
2069
|
2142
|
}
|
2070
|
2143
|
else { // Must be in cruise phase otherwise
|
2071
|
2144
|
|
2072
|
|
- #if ENABLED(LIN_ADVANCE)
|
2073
|
|
- // If there are any esteps, fire the next advance_isr "now"
|
2074
|
|
- if (LA_steps && LA_isr_rate != current_block->advance_speed) initiateLA();
|
2075
|
|
- #endif
|
2076
|
|
-
|
2077
|
2145
|
// Calculate the ticks_nominal for this nominal speed, if not done yet
|
2078
|
2146
|
if (ticks_nominal < 0) {
|
2079
|
2147
|
// step_rate to timer interval and loops for the nominal speed
|
2080
|
|
- ticks_nominal = calc_timer_interval(current_block->nominal_rate, &steps_per_isr);
|
|
2148
|
+ ticks_nominal = calc_timer_interval(current_block->nominal_rate << oversampling_factor, steps_per_isr);
|
|
2149
|
+
|
|
2150
|
+ #if ENABLED(LIN_ADVANCE)
|
|
2151
|
+ if (current_block->la_advance_rate)
|
|
2152
|
+ la_interval = calc_timer_interval(current_block->nominal_rate) << current_block->la_scaling;
|
|
2153
|
+ #endif
|
2081
|
2154
|
}
|
2082
|
2155
|
|
2083
|
2156
|
// The timer interval is just the nominal value for the nominal speed
|
|
@@ -2291,7 +2364,7 @@ uint32_t Stepper::block_phase_isr() {
|
2291
|
2364
|
step_event_count = current_block->step_event_count << oversampling;
|
2292
|
2365
|
|
2293
|
2366
|
// Initialize Bresenham delta errors to 1/2
|
2294
|
|
- delta_error = -int32_t(step_event_count);
|
|
2367
|
+ delta_error = TERN_(LIN_ADVANCE, la_delta_error =) -int32_t(step_event_count);
|
2295
|
2368
|
|
2296
|
2369
|
// Calculate Bresenham dividends and divisors
|
2297
|
2370
|
advance_dividend = current_block->steps << 1;
|
|
@@ -2312,16 +2385,12 @@ uint32_t Stepper::block_phase_isr() {
|
2312
|
2385
|
#if ENABLED(LIN_ADVANCE)
|
2313
|
2386
|
#if DISABLED(MIXING_EXTRUDER) && E_STEPPERS > 1
|
2314
|
2387
|
// If the now active extruder wasn't in use during the last move, its pressure is most likely gone.
|
2315
|
|
- if (stepper_extruder != last_moved_extruder) LA_current_adv_steps = 0;
|
|
2388
|
+ if (stepper_extruder != last_moved_extruder) la_advance_steps = 0;
|
2316
|
2389
|
#endif
|
2317
|
|
-
|
2318
|
|
- if ((LA_use_advance_lead = current_block->use_advance_lead)) {
|
2319
|
|
- LA_final_adv_steps = current_block->final_adv_steps;
|
2320
|
|
- LA_max_adv_steps = current_block->max_adv_steps;
|
2321
|
|
- initiateLA(); // Start the ISR
|
2322
|
|
- LA_isr_rate = current_block->advance_speed;
|
|
2390
|
+ if (current_block->la_advance_rate) {
|
|
2391
|
+ // apply LA scaling and discount the effect of frequency scaling
|
|
2392
|
+ la_dividend = (advance_dividend.e << current_block->la_scaling) << oversampling;
|
2323
|
2393
|
}
|
2324
|
|
- else LA_isr_rate = LA_ADV_NEVER;
|
2325
|
2394
|
#endif
|
2326
|
2395
|
|
2327
|
2396
|
if ( ENABLED(DUAL_X_CARRIAGE) // TODO: Find out why this fixes "jittery" small circles
|
|
@@ -2375,7 +2444,15 @@ uint32_t Stepper::block_phase_isr() {
|
2375
|
2444
|
#endif
|
2376
|
2445
|
|
2377
|
2446
|
// Calculate the initial timer interval
|
2378
|
|
- interval = calc_timer_interval(current_block->initial_rate, &steps_per_isr);
|
|
2447
|
+ interval = calc_timer_interval(current_block->initial_rate << oversampling_factor, steps_per_isr);
|
|
2448
|
+ acceleration_time += interval;
|
|
2449
|
+
|
|
2450
|
+ #if ENABLED(LIN_ADVANCE)
|
|
2451
|
+ if (current_block->la_advance_rate) {
|
|
2452
|
+ const uint32_t la_step_rate = la_advance_steps < current_block->max_adv_steps ? current_block->la_advance_rate : 0;
|
|
2453
|
+ la_interval = calc_timer_interval(current_block->initial_rate + la_step_rate) << current_block->la_scaling;
|
|
2454
|
+ }
|
|
2455
|
+ #endif
|
2379
|
2456
|
}
|
2380
|
2457
|
}
|
2381
|
2458
|
|
|
@@ -2386,71 +2463,15 @@ uint32_t Stepper::block_phase_isr() {
|
2386
|
2463
|
#if ENABLED(LIN_ADVANCE)
|
2387
|
2464
|
|
2388
|
2465
|
// Timer interrupt for E. LA_steps is set in the main routine
|
2389
|
|
- uint32_t Stepper::advance_isr() {
|
2390
|
|
- uint32_t interval;
|
2391
|
|
-
|
2392
|
|
- if (LA_use_advance_lead) {
|
2393
|
|
- if (step_events_completed > decelerate_after && LA_current_adv_steps > LA_final_adv_steps) {
|
2394
|
|
- LA_steps--;
|
2395
|
|
- LA_current_adv_steps--;
|
2396
|
|
- interval = LA_isr_rate;
|
2397
|
|
- }
|
2398
|
|
- else if (step_events_completed < decelerate_after && LA_current_adv_steps < LA_max_adv_steps) {
|
2399
|
|
- LA_steps++;
|
2400
|
|
- LA_current_adv_steps++;
|
2401
|
|
- interval = LA_isr_rate;
|
2402
|
|
- }
|
2403
|
|
- else
|
2404
|
|
- interval = LA_isr_rate = LA_ADV_NEVER;
|
2405
|
|
- }
|
2406
|
|
- else
|
2407
|
|
- interval = LA_ADV_NEVER;
|
2408
|
|
-
|
2409
|
|
- if (!LA_steps) return interval; // Leave pins alone if there are no steps!
|
2410
|
|
-
|
2411
|
|
- DIR_WAIT_BEFORE();
|
2412
|
|
-
|
2413
|
|
- #if ENABLED(MIXING_EXTRUDER)
|
2414
|
|
- // We don't know which steppers will be stepped because LA loop follows,
|
2415
|
|
- // with potentially multiple steps. Set all.
|
2416
|
|
- if (LA_steps > 0) {
|
2417
|
|
- MIXER_STEPPER_LOOP(j) NORM_E_DIR(j);
|
2418
|
|
- count_direction.e = 1;
|
2419
|
|
- }
|
2420
|
|
- else if (LA_steps < 0) {
|
2421
|
|
- MIXER_STEPPER_LOOP(j) REV_E_DIR(j);
|
2422
|
|
- count_direction.e = -1;
|
2423
|
|
- }
|
2424
|
|
- #else
|
2425
|
|
- if (LA_steps > 0) {
|
2426
|
|
- NORM_E_DIR(stepper_extruder);
|
2427
|
|
- count_direction.e = 1;
|
2428
|
|
- }
|
2429
|
|
- else if (LA_steps < 0) {
|
2430
|
|
- REV_E_DIR(stepper_extruder);
|
2431
|
|
- count_direction.e = -1;
|
2432
|
|
- }
|
2433
|
|
- #endif
|
2434
|
|
-
|
2435
|
|
- DIR_WAIT_AFTER();
|
2436
|
|
-
|
2437
|
|
- //const hal_timer_t added_step_ticks = hal_timer_t(ADDED_STEP_TICKS);
|
2438
|
|
-
|
2439
|
|
- // Step E stepper if we have steps
|
2440
|
|
- #if ISR_MULTI_STEPS
|
2441
|
|
- bool firstStep = true;
|
2442
|
|
- USING_TIMED_PULSE();
|
2443
|
|
- #endif
|
2444
|
|
-
|
2445
|
|
- while (LA_steps) {
|
2446
|
|
- #if ISR_MULTI_STEPS
|
2447
|
|
- if (firstStep)
|
2448
|
|
- firstStep = false;
|
2449
|
|
- else
|
2450
|
|
- AWAIT_LOW_PULSE();
|
2451
|
|
- #endif
|
2452
|
|
-
|
|
2466
|
+ void Stepper::advance_isr() {
|
|
2467
|
+ // Apply Bresenham algorithm so that linear advance can piggy back on
|
|
2468
|
+ // the acceleration and speed values calculated in block_phase_isr().
|
|
2469
|
+ // This helps keep LA in sync with, for example, S_CURVE_ACCELERATION.
|
|
2470
|
+ la_delta_error += la_dividend;
|
|
2471
|
+ if (la_delta_error >= 0) {
|
2453
|
2472
|
count_position.e += count_direction.e;
|
|
2473
|
+ la_advance_steps += count_direction.e;
|
|
2474
|
+ la_delta_error -= advance_divisor;
|
2454
|
2475
|
|
2455
|
2476
|
// Set the STEP pulse ON
|
2456
|
2477
|
#if ENABLED(MIXING_EXTRUDER)
|
|
@@ -2461,12 +2482,8 @@ uint32_t Stepper::block_phase_isr() {
|
2461
|
2482
|
|
2462
|
2483
|
// Enforce a minimum duration for STEP pulse ON
|
2463
|
2484
|
#if ISR_PULSE_CONTROL
|
|
2485
|
+ USING_TIMED_PULSE();
|
2464
|
2486
|
START_HIGH_PULSE();
|
2465
|
|
- #endif
|
2466
|
|
-
|
2467
|
|
- LA_steps < 0 ? ++LA_steps : --LA_steps;
|
2468
|
|
-
|
2469
|
|
- #if ISR_PULSE_CONTROL
|
2470
|
2487
|
AWAIT_HIGH_PULSE();
|
2471
|
2488
|
#endif
|
2472
|
2489
|
|
|
@@ -2476,15 +2493,7 @@ uint32_t Stepper::block_phase_isr() {
|
2476
|
2493
|
#else
|
2477
|
2494
|
E_STEP_WRITE(stepper_extruder, INVERT_E_STEP_PIN);
|
2478
|
2495
|
#endif
|
2479
|
|
-
|
2480
|
|
- // For minimum pulse time wait before looping
|
2481
|
|
- // Just wait for the requested pulse duration
|
2482
|
|
- #if ISR_PULSE_CONTROL
|
2483
|
|
- if (LA_steps) START_LOW_PULSE();
|
2484
|
|
- #endif
|
2485
|
|
- } // LA_steps
|
2486
|
|
-
|
2487
|
|
- return interval;
|
|
2496
|
+ }
|
2488
|
2497
|
}
|
2489
|
2498
|
|
2490
|
2499
|
#endif // LIN_ADVANCE
|