Advertisement
osnwt

Marlin TCNT patch

May 23rd, 2012
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.88 KB | None | 0 0
  1. diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp
  2. index 85e9bbb..59ab869 100644
  3. --- a/Marlin/stepper.cpp
  4. +++ b/Marlin/stepper.cpp
  5. @@ -58,7 +58,7 @@ static long acceleration_time, deceleration_time;
  6.  //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
  7.  static unsigned short acc_step_rate; // needed for deccelaration start point
  8.  static char step_loops;
  9. -static unsigned short OCR1A_nominal;
  10. +static unsigned short OCR3A_nominal;
  11.  
  12.  volatile long endstops_trigsteps[3]={0,0,0};
  13.  volatile long endstops_stepsTotal,endstops_stepsDone;
  14. @@ -160,8 +160,8 @@ asm volatile ( \
  15.  
  16.  // Some useful constants
  17.  
  18. -#define ENABLE_STEPPER_DRIVER_INTERRUPT()  TIMSK1 |= (1<<OCIE1A)
  19. -#define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
  20. +#define ENABLE_STEPPER_DRIVER_INTERRUPT()  TIMSK3 |= (1<<OCIE3A)
  21. +#define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK3 &= ~(1<<OCIE3A)
  22.  
  23.  
  24.  void checkHitEndstops()
  25. @@ -267,8 +267,8 @@ FORCE_INLINE void trapezoid_generator_reset() {
  26.    // step_rate to timer interval
  27.    acc_step_rate = current_block->initial_rate;
  28.    acceleration_time = calc_timer(acc_step_rate);
  29. -  OCR1A = acceleration_time;
  30. -  OCR1A_nominal = calc_timer(current_block->nominal_rate);
  31. +  OCR3A = acceleration_time;
  32. +  OCR3A_nominal = calc_timer(current_block->nominal_rate);
  33.    
  34.  
  35.    
  36. @@ -286,7 +286,7 @@ FORCE_INLINE void trapezoid_generator_reset() {
  37.  
  38.  // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.  
  39.  // It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
  40. -ISR(TIMER1_COMPA_vect)
  41. +ISR(TIMER3_COMPA_vect)
  42.  {    
  43.    // If there is no current block, attempt to pop one from the buffer
  44.    if (current_block == NULL) {
  45. @@ -304,7 +304,7 @@ ISR(TIMER1_COMPA_vect)
  46.        #ifdef Z_LATE_ENABLE
  47.          if(current_block->steps_z > 0) {
  48.            enable_z();
  49. -          OCR1A = 2000; //1ms wait
  50. +          OCR3A = 2000; //1ms wait
  51.            return;
  52.          }
  53.        #endif
  54. @@ -314,7 +314,7 @@ ISR(TIMER1_COMPA_vect)
  55.  //      #endif
  56.      }
  57.      else {
  58. -        OCR1A=2000; // 1kHz.
  59. +        OCR3A=2000; // 1kHz.
  60.      }    
  61.    }
  62.  
  63. @@ -503,7 +503,7 @@ ISR(TIMER1_COMPA_vect)
  64.  
  65.        // step_rate to timer interval
  66.        timer = calc_timer(acc_step_rate);
  67. -      OCR1A = timer;
  68. +      OCR3A = timer;
  69.        acceleration_time += timer;
  70.        #ifdef ADVANCE
  71.          for(int8_t i=0; i < step_loops; i++) {
  72. @@ -532,7 +532,7 @@ ISR(TIMER1_COMPA_vect)
  73.  
  74.        // step_rate to timer interval
  75.        timer = calc_timer(step_rate);
  76. -      OCR1A = timer;
  77. +      OCR3A = timer;
  78.        deceleration_time += timer;
  79.        #ifdef ADVANCE
  80.          for(int8_t i=0; i < step_loops; i++) {
  81. @@ -545,7 +545,7 @@ ISR(TIMER1_COMPA_vect)
  82.        #endif //ADVANCE
  83.      }
  84.      else {
  85. -      OCR1A = OCR1A_nominal;
  86. +      OCR3A = OCR3A_nominal;
  87.      }
  88.  
  89.      // If current block is finished, reset pointer
  90. @@ -741,24 +741,24 @@ void st_init()
  91.    #endif
  92.    
  93.    // waveform generation = 0100 = CTC
  94. -  TCCR1B &= ~(1<<WGM13);
  95. -  TCCR1B |=  (1<<WGM12);
  96. -  TCCR1A &= ~(1<<WGM11);
  97. -  TCCR1A &= ~(1<<WGM10);
  98. +  TCCR3B &= ~(1<<WGM33);
  99. +  TCCR3B |=  (1<<WGM32);
  100. +  TCCR3A &= ~(1<<WGM31);
  101. +  TCCR3A &= ~(1<<WGM30);
  102.  
  103.    // output mode = 00 (disconnected)
  104. -  TCCR1A &= ~(3<<COM1A0);
  105. -  TCCR1A &= ~(3<<COM1B0);
  106. +  TCCR3A &= ~(3<<COM3A0);
  107. +  TCCR3A &= ~(3<<COM3B0);
  108.    
  109.    // Set the timer pre-scaler
  110.    // Generally we use a divider of 8, resulting in a 2MHz timer
  111.    // frequency on a 16MHz MCU. If you are going to change this, be
  112.    // sure to regenerate speed_lookuptable.h with
  113.    // create_speed_lookuptable.py
  114. -  TCCR1B = (TCCR1B & ~(0x07<<CS10)) | (2<<CS10);
  115. +  TCCR3B = (TCCR3B & ~(0x07<<CS30)) | (2<<CS30);
  116.  
  117. -  OCR1A = 0x4000;
  118. -  TCNT1 = 0;
  119. +  OCR3A = 0x4000;
  120. +  TCNT3 = 0;
  121.    ENABLE_STEPPER_DRIVER_INTERRUPT();  
  122.  
  123.    #ifdef ADVANCE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement