Browse Source

Add an option to specify "pulse" timer

pull/1/head
Scott Lahteine 7 years ago
parent
commit
82ef6b5242
  1. 4
      Marlin/src/HAL/HAL_AVR/HAL_AVR.h
  2. 3
      Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h
  3. 3
      Marlin/src/HAL/HAL_LPC1768/HAL_timers.h
  4. 3
      Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h
  5. 3
      Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h
  6. 18
      Marlin/src/module/stepper.cpp

4
Marlin/src/HAL/HAL_AVR/HAL_AVR.h

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

3
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h

@ -64,6 +64,9 @@ typedef uint32_t hal_timer_t;
#define HAL_STEP_TIMER_ISR void TC3_Handler() #define HAL_STEP_TIMER_ISR void TC3_Handler()
#define HAL_TEMP_TIMER_ISR void TC4_Handler() #define HAL_TEMP_TIMER_ISR void TC4_Handler()
#define PULSE_TIMER_NUM STEP_TIMER_NUM
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Types // Types
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

3
Marlin/src/HAL/HAL_LPC1768/HAL_timers.h

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

3
Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h

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

3
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h

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

18
Marlin/src/module/stepper.cpp

@ -564,7 +564,7 @@ void Stepper::isr() {
* 10µs = 160 or 200 cycles. * 10µs = 160 or 200 cycles.
*/ */
#if EXTRA_CYCLES_XYZE > 20 #if EXTRA_CYCLES_XYZE > 20
hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM); hal_timer_t pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM);
#endif #endif
#if HAS_X_STEP #if HAS_X_STEP
@ -596,8 +596,8 @@ void Stepper::isr() {
// For minimum pulse time wait before stopping pulses // For minimum pulse time wait before stopping pulses
#if EXTRA_CYCLES_XYZE > 20 #if EXTRA_CYCLES_XYZE > 20
while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ } while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM); pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM);
#elif EXTRA_CYCLES_XYZE > 0 #elif EXTRA_CYCLES_XYZE > 0
DELAY_NOPS(EXTRA_CYCLES_XYZE); DELAY_NOPS(EXTRA_CYCLES_XYZE);
#endif #endif
@ -637,7 +637,7 @@ void Stepper::isr() {
// For minimum pulse time wait after stopping pulses also // For minimum pulse time wait after stopping pulses also
#if EXTRA_CYCLES_XYZE > 20 #if EXTRA_CYCLES_XYZE > 20
if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ } if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
#elif EXTRA_CYCLES_XYZE > 0 #elif EXTRA_CYCLES_XYZE > 0
if (i) DELAY_NOPS(EXTRA_CYCLES_XYZE); if (i) DELAY_NOPS(EXTRA_CYCLES_XYZE);
#endif #endif
@ -818,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
hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM); hal_timer_t pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM);
#endif #endif
START_E_PULSE(0); START_E_PULSE(0);
@ -837,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 > (hal_timer_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ } while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM); pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM);
#elif EXTRA_CYCLES_E > 0 #elif EXTRA_CYCLES_E > 0
DELAY_NOPS(EXTRA_CYCLES_E); DELAY_NOPS(EXTRA_CYCLES_E);
#endif #endif
@ -859,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 > (hal_timer_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ } if (i) while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_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
@ -1299,7 +1299,7 @@ void Stepper::report_positions() {
#if EXTRA_CYCLES_BABYSTEP > 20 #if EXTRA_CYCLES_BABYSTEP > 20
#define _SAVE_START const hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM) #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)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (STEPPER_TIMER_PRESCALE)) { /* nada */ } #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
#else #else
#define _SAVE_START NOOP #define _SAVE_START NOOP
#if EXTRA_CYCLES_BABYSTEP > 0 #if EXTRA_CYCLES_BABYSTEP > 0

Loading…
Cancel
Save