Fix timer comments

This commit is contained in:
Scott Lahteine 2016-10-09 10:06:31 -05:00
parent a448cedbc5
commit 3752d9aca8
2 changed files with 39 additions and 10 deletions

View File

@ -311,8 +311,20 @@ void Stepper::set_directions() {
#endif // !ADVANCE && !LIN_ADVANCE #endif // !ADVANCE && !LIN_ADVANCE
} }
// "The Stepper Driver Interrupt" - This timer interrupt is the workhorse. /**
// It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately. * Stepper Driver Interrupt
*
* Directly pulses the stepper motors at high frequency.
* Timer 1 runs at a base frequency of 2MHz, with this ISR using OCR1A compare mode.
*
* OCR1A Frequency
* 1 2 MHz
* 50 40 KHz
* 100 20 KHz - capped max rate
* 200 10 KHz - nominal max rate
* 2000 1 KHz - sleep rate
* 4000 500 Hz - init rate
*/
ISR(TIMER1_COMPA_vect) { Stepper::isr(); } ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
void Stepper::isr() { void Stepper::isr() {
@ -323,7 +335,7 @@ void Stepper::isr() {
if ((cleaning_buffer_counter == 1) && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND)); if ((cleaning_buffer_counter == 1) && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
#endif #endif
cleaning_buffer_counter--; cleaning_buffer_counter--;
OCR1A = 200; OCR1A = 200; // Run at max speed - 10 KHz
return; return;
} }
@ -348,7 +360,7 @@ void Stepper::isr() {
#if ENABLED(Z_LATE_ENABLE) #if ENABLED(Z_LATE_ENABLE)
if (current_block->steps[Z_AXIS] > 0) { if (current_block->steps[Z_AXIS] > 0) {
enable_z(); enable_z();
OCR1A = 2000; //1ms wait OCR1A = 2000; // Run at slow speed - 1 KHz
return; return;
} }
#endif #endif
@ -358,7 +370,7 @@ void Stepper::isr() {
// #endif // #endif
} }
else { else {
OCR1A = 2000; // 1kHz. OCR1A = 2000; // Run at slow speed - 1 KHz
return; return;
} }
} }
@ -903,6 +915,7 @@ void Stepper::init() {
// output mode = 00 (disconnected) // output mode = 00 (disconnected)
TCCR1A &= ~(3 << COM1A0); TCCR1A &= ~(3 << COM1A0);
TCCR1A &= ~(3 << COM1B0); TCCR1A &= ~(3 << COM1B0);
// Set the timer pre-scaler // Set the timer pre-scaler
// Generally we use a divider of 8, resulting in a 2MHz timer // Generally we use a divider of 8, resulting in a 2MHz timer
// frequency on a 16MHz MCU. If you are going to change this, be // frequency on a 16MHz MCU. If you are going to change this, be
@ -910,6 +923,7 @@ void Stepper::init() {
// create_speed_lookuptable.py // create_speed_lookuptable.py
TCCR1B = (TCCR1B & ~(0x07 << CS10)) | (2 << CS10); TCCR1B = (TCCR1B & ~(0x07 << CS10)) | (2 << CS10);
// Init Stepper ISR to 122 Hz for quick starting
OCR1A = 0x4000; OCR1A = 0x4000;
TCNT1 = 0; TCNT1 = 0;
ENABLE_STEPPER_DRIVER_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT();

View File

@ -1371,7 +1371,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 * This ISR uses the compare method so it runs at the base
* frequency (16 MHz / 256 = 62500 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).
* *
* - Manage PWM to all the heaters and fan * - Manage PWM to all the heaters and fan
@ -1485,9 +1485,16 @@ void Temperature::isr() {
#endif #endif
#endif #endif
// 488.28 Hz (or 1:976.56, 2:1953.12, 3:3906.25, 4:7812.5, 5:7812.5 6:15625, 6:15625 7:31250) // SOFT_PWM_SCALE to frequency:
//
// 0: 16000000/64/256/128 = 7.6294 Hz
// 1: / 64 = 15.2588 Hz
// 2: / 32 = 30.5176 Hz
// 3: / 16 = 61.0352 Hz
// 4: / 8 = 122.0703 Hz
// 5: / 4 = 244.1406 Hz
pwm_count += _BV(SOFT_PWM_SCALE); pwm_count += _BV(SOFT_PWM_SCALE);
pwm_count &= 0x7f; pwm_count &= 0x7F;
#else // SLOW_PWM_HEATERS #else // SLOW_PWM_HEATERS
@ -1586,10 +1593,18 @@ void Temperature::isr() {
#endif #endif
#endif //FAN_SOFT_PWM #endif //FAN_SOFT_PWM
// SOFT_PWM_SCALE to frequency:
//
// 0: 16000000/64/256/128 = 7.6294 Hz
// 1: / 64 = 15.2588 Hz
// 2: / 32 = 30.5176 Hz
// 3: / 16 = 61.0352 Hz
// 4: / 8 = 122.0703 Hz
// 5: / 4 = 244.1406 Hz
pwm_count += _BV(SOFT_PWM_SCALE); pwm_count += _BV(SOFT_PWM_SCALE);
pwm_count &= 0x7f; pwm_count &= 0x7F;
// increment slow_pwm_count only every 64 pwm_count circa 65.5ms // increment slow_pwm_count only every 64 pwm_count (e.g., every 8s)
if ((pwm_count % 64) == 0) { if ((pwm_count % 64) == 0) {
slow_pwm_count++; slow_pwm_count++;
slow_pwm_count &= 0x7f; slow_pwm_count &= 0x7f;