parent
b3daf6b5db
commit
4fa65a5c25
|
@ -152,9 +152,10 @@ volatile signed char Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
|
||||||
long Stepper::counter_m[MIXING_STEPPERS];
|
long Stepper::counter_m[MIXING_STEPPERS];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
hal_timer_t Stepper::acc_step_rate; // needed for deceleration start point
|
|
||||||
uint8_t Stepper::step_loops, Stepper::step_loops_nominal;
|
uint8_t Stepper::step_loops, Stepper::step_loops_nominal;
|
||||||
hal_timer_t Stepper::OCR1A_nominal;
|
|
||||||
|
hal_timer_t Stepper::OCR1A_nominal,
|
||||||
|
Stepper::acc_step_rate; // needed for deceleration start point
|
||||||
|
|
||||||
volatile long Stepper::endstops_trigsteps[XYZ];
|
volatile long Stepper::endstops_trigsteps[XYZ];
|
||||||
|
|
||||||
|
@ -557,13 +558,13 @@ void Stepper::isr() {
|
||||||
/**
|
/**
|
||||||
* If a minimum pulse time was specified get the timer 0 value.
|
* If a minimum pulse time was specified get the timer 0 value.
|
||||||
*
|
*
|
||||||
* TCNT0 has an 8x prescaler, so it increments every 8 cycles.
|
* On AVR the TCNT0 timer has an 8x prescaler, so it increments every 8 cycles.
|
||||||
* That's every 0.5µs on 16MHz and every 0.4µs on 20MHz.
|
* That's every 0.5µs on 16MHz and every 0.4µs on 20MHz.
|
||||||
* 20 counts of TCNT0 -by itself- is a good pulse delay.
|
* 20 counts of TCNT0 -by itself- is a good pulse delay.
|
||||||
* 10µs = 160 or 200 cycles.
|
* 10µs = 160 or 200 cycles.
|
||||||
*/
|
*/
|
||||||
#if EXTRA_CYCLES_XYZE > 20
|
#if EXTRA_CYCLES_XYZE > 20
|
||||||
uint32_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
|
hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_X_STEP
|
#if HAS_X_STEP
|
||||||
|
@ -676,12 +677,12 @@ void Stepper::isr() {
|
||||||
NOMORE(acc_step_rate, current_block->nominal_rate);
|
NOMORE(acc_step_rate, current_block->nominal_rate);
|
||||||
|
|
||||||
// step_rate to timer interval
|
// step_rate to timer interval
|
||||||
const hal_timer_t timer = calc_timer(acc_step_rate);
|
const hal_timer_t interval = calc_timer_interval(acc_step_rate);
|
||||||
|
|
||||||
SPLIT(timer); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
|
SPLIT(interval); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
|
||||||
_NEXT_ISR(ocr_val);
|
_NEXT_ISR(ocr_val);
|
||||||
|
|
||||||
acceleration_time += timer;
|
acceleration_time += interval;
|
||||||
|
|
||||||
#if ENABLED(LIN_ADVANCE)
|
#if ENABLED(LIN_ADVANCE)
|
||||||
|
|
||||||
|
@ -693,7 +694,7 @@ void Stepper::isr() {
|
||||||
current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->abs_adv_steps_multiplier8) >> 17;
|
current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->abs_adv_steps_multiplier8) >> 17;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
eISR_Rate = adv_rate(e_steps[TOOL_E_INDEX], timer, step_loops);
|
eISR_Rate = adv_rate(e_steps[TOOL_E_INDEX], interval, step_loops);
|
||||||
|
|
||||||
#endif // LIN_ADVANCE
|
#endif // LIN_ADVANCE
|
||||||
}
|
}
|
||||||
|
@ -713,11 +714,11 @@ void Stepper::isr() {
|
||||||
step_rate = current_block->final_rate;
|
step_rate = current_block->final_rate;
|
||||||
|
|
||||||
// step_rate to timer interval
|
// step_rate to timer interval
|
||||||
const hal_timer_t timer = calc_timer(step_rate);
|
const hal_timer_t interval = calc_timer_interval(step_rate);
|
||||||
|
|
||||||
SPLIT(timer); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
|
SPLIT(interval); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
|
||||||
_NEXT_ISR(ocr_val);
|
_NEXT_ISR(ocr_val);
|
||||||
deceleration_time += timer;
|
deceleration_time += interval;
|
||||||
|
|
||||||
#if ENABLED(LIN_ADVANCE)
|
#if ENABLED(LIN_ADVANCE)
|
||||||
|
|
||||||
|
@ -729,7 +730,7 @@ void Stepper::isr() {
|
||||||
current_estep_rate[TOOL_E_INDEX] = ((uint32_t)step_rate * current_block->abs_adv_steps_multiplier8) >> 17;
|
current_estep_rate[TOOL_E_INDEX] = ((uint32_t)step_rate * current_block->abs_adv_steps_multiplier8) >> 17;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
eISR_Rate = adv_rate(e_steps[TOOL_E_INDEX], timer, step_loops);
|
eISR_Rate = adv_rate(e_steps[TOOL_E_INDEX], interval, step_loops);
|
||||||
|
|
||||||
#endif // LIN_ADVANCE
|
#endif // LIN_ADVANCE
|
||||||
}
|
}
|
||||||
|
@ -817,7 +818,7 @@ void Stepper::isr() {
|
||||||
for (uint8_t i = step_loops; i--;) {
|
for (uint8_t i = step_loops; i--;) {
|
||||||
|
|
||||||
#if EXTRA_CYCLES_E > 20
|
#if EXTRA_CYCLES_E > 20
|
||||||
uint32_t pulse_start = TCNT0;
|
hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
START_E_PULSE(0);
|
START_E_PULSE(0);
|
||||||
|
@ -836,8 +837,8 @@ void Stepper::isr() {
|
||||||
|
|
||||||
// For minimum pulse time wait before stopping pulses
|
// For minimum pulse time wait before stopping pulses
|
||||||
#if EXTRA_CYCLES_E > 20
|
#if EXTRA_CYCLES_E > 20
|
||||||
while (EXTRA_CYCLES_E > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
|
while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ }
|
||||||
pulse_start = TCNT0;
|
pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM);
|
||||||
#elif EXTRA_CYCLES_E > 0
|
#elif EXTRA_CYCLES_E > 0
|
||||||
DELAY_NOPS(EXTRA_CYCLES_E);
|
DELAY_NOPS(EXTRA_CYCLES_E);
|
||||||
#endif
|
#endif
|
||||||
|
@ -858,7 +859,7 @@ void Stepper::isr() {
|
||||||
|
|
||||||
// For minimum pulse time wait before looping
|
// For minimum pulse time wait before looping
|
||||||
#if EXTRA_CYCLES_E > 20
|
#if EXTRA_CYCLES_E > 20
|
||||||
if (i) while (EXTRA_CYCLES_E > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
|
if (i) while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ }
|
||||||
#elif EXTRA_CYCLES_E > 0
|
#elif EXTRA_CYCLES_E > 0
|
||||||
if (i) DELAY_NOPS(EXTRA_CYCLES_E);
|
if (i) DELAY_NOPS(EXTRA_CYCLES_E);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1297,8 +1298,8 @@ void Stepper::report_positions() {
|
||||||
#define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
|
#define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
|
||||||
|
|
||||||
#if EXTRA_CYCLES_BABYSTEP > 20
|
#if EXTRA_CYCLES_BABYSTEP > 20
|
||||||
#define _SAVE_START const uint32_t pulse_start = TCNT0
|
#define _SAVE_START const hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM)
|
||||||
#define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
|
#define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ }
|
||||||
#else
|
#else
|
||||||
#define _SAVE_START NOOP
|
#define _SAVE_START NOOP
|
||||||
#if EXTRA_CYCLES_BABYSTEP > 0
|
#if EXTRA_CYCLES_BABYSTEP > 0
|
||||||
|
|
|
@ -278,7 +278,7 @@ class Stepper {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
FORCE_INLINE static hal_timer_t calc_timer(hal_timer_t step_rate) {
|
FORCE_INLINE static hal_timer_t calc_timer_interval(hal_timer_t step_rate) {
|
||||||
hal_timer_t timer;
|
hal_timer_t timer;
|
||||||
|
|
||||||
NOMORE(step_rate, MAX_STEP_FREQUENCY);
|
NOMORE(step_rate, MAX_STEP_FREQUENCY);
|
||||||
|
@ -359,11 +359,11 @@ class Stepper {
|
||||||
|
|
||||||
deceleration_time = 0;
|
deceleration_time = 0;
|
||||||
// step_rate to timer interval
|
// step_rate to timer interval
|
||||||
OCR1A_nominal = calc_timer(current_block->nominal_rate);
|
OCR1A_nominal = calc_timer_interval(current_block->nominal_rate);
|
||||||
// make a note of the number of step loops required at nominal speed
|
// make a note of the number of step loops required at nominal speed
|
||||||
step_loops_nominal = step_loops;
|
step_loops_nominal = step_loops;
|
||||||
acc_step_rate = current_block->initial_rate;
|
acc_step_rate = current_block->initial_rate;
|
||||||
acceleration_time = calc_timer(acc_step_rate);
|
acceleration_time = calc_timer_interval(acc_step_rate);
|
||||||
_NEXT_ISR(acceleration_time);
|
_NEXT_ISR(acceleration_time);
|
||||||
|
|
||||||
#if ENABLED(LIN_ADVANCE)
|
#if ENABLED(LIN_ADVANCE)
|
||||||
|
|
|
@ -1588,7 +1588,7 @@ void Temperature::set_current_temp_raw() {
|
||||||
/**
|
/**
|
||||||
* Timer 0 is shared with millies so don't change the prescaler.
|
* Timer 0 is shared with millies so don't change the prescaler.
|
||||||
*
|
*
|
||||||
* This ISR uses the compare method so it runs at the base
|
* On AVR this ISR uses the compare method so it runs at the base
|
||||||
* frequency (16 MHz / 64 / 256 = 976.5625 Hz), but at the TCNT0 set
|
* frequency (16 MHz / 64 / 256 = 976.5625 Hz), but at the TCNT0 set
|
||||||
* in OCR0B above (128 or halfway between OVFs).
|
* in OCR0B above (128 or halfway between OVFs).
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue