Skip to content
This repository
Browse code

Minor prescalar optimization. Changed up some defines.

  • Loading branch information...
commit 4224ab4999bdcad9cff026ab584e17c4a2fe93ff 1 parent 420c7c2
Sonny Jeon chamnit authored

Showing 4 changed files with 27 additions and 28 deletions. Show diff stats Hide diff stats

  1. +7 8 config.h
  2. +2 2 coolant_control.c
  3. +5 5 gcode.c
  4. +13 13 stepper.c
15 config.h
@@ -58,14 +58,13 @@
58 58 #define COOLANT_FLOOD_PORT PORTC
59 59 #define COOLANT_FLOOD_BIT 0 // Uno Analog Pin 0
60 60
61   -#define ENABLE_M7 0 // DISABLED BY DEFAULT: To enable, change to '1' and recompile.
62   -#if ENABLE_M7
  61 +// #define ENABLE_M7 // Mist coolant disabled by default. Uncomment to enable.
  62 +#ifdef ENABLE_M7
63 63 #define COOLANT_MIST_DDR DDRC
64 64 #define COOLANT_MIST_PORT PORTC
65 65 #define COOLANT_MIST_BIT 1 // Uno Analog Pin 1
66 66 #endif
67 67
68   -
69 68 // Define runtime command special characters. These characters are 'picked-off' directly from the
70 69 // serial read data stream and are not passed to the grbl line execution parser. Select characters
71 70 // that do not and must not exist in the streamed g-code program. ASCII control characters may be
@@ -87,7 +86,7 @@
87 86 // entering g-code into grbl, i.e. locating part zero or simple manual machining. If the axes drift,
88 87 // grbl has no way to know this has happened, since stepper motors are open-loop control. Depending
89 88 // on the machine, this parameter may need to be larger or smaller than the default time.
90   -// NOTE: If set to zero, the delay will not be compiled.
  89 +// NOTE: If the define commented, the delay will not be compiled.
91 90 #define STEPPER_IDLE_LOCK_TIME 25 // (milliseconds) - Integer > 0
92 91
93 92 // The temporal resolution of the acceleration management subsystem. Higher number give smoother
@@ -137,7 +136,7 @@
137 136 // As well as, older FTDI FT232RL-based Arduinos(Duemilanove) are known to work with standard
138 137 // terminal programs since their firmware correctly manage these XON/XOFF characters. In any
139 138 // case, please report any successes to grbl administrators!
140   -#define ENABLE_XONXOFF 0 // Boolean. Default disabled.
  139 +// #define ENABLE_XONXOFF // Default disabled. Uncomment to enable.
141 140
142 141 // Creates a delay between the direction pin setting and corresponding step pulse by creating
143 142 // another interrupt (Timer2 compare) to manage it. The main Grbl interrupt (Timer1 compare)
@@ -151,9 +150,9 @@
151 150 // of your successes or difficulties, as we will monitor this and possibly integrate this as a
152 151 // standard feature for future releases. However, we suggest to first try our direction delay
153 152 // hack/solution posted in the Wiki involving inverting the stepper pin mask.
154   -// NOTE: If set greater than zero, step pulse delay will be compiled and enabled. Also, the
155   -// total delay added with the Grbl settings pulse microseconds must not exceed 127 ms.
156   -#define STEP_PULSE_DELAY 0 // Step pulse delay in microseconds. Default disabled.
  153 +// NOTE: Uncomment to enable. The recommended delay should be > 3us but not exceed a total
  154 +// time of 127us when added with the Grbl settings pulse microsecond.
  155 +// #define STEP_PULSE_DELAY 5 // Step pulse delay in microseconds. Default disabled.
157 156
158 157 // ---------------------------------------------------------------------------------------
159 158
4 coolant_control.c
@@ -39,7 +39,7 @@ void coolant_init()
39 39
40 40 void coolant_stop()
41 41 {
42   - #if ENABLE_M7
  42 + #ifdef ENABLE_M7
43 43 COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
44 44 #endif
45 45 COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
@@ -53,7 +53,7 @@ void coolant_run(uint8_t mode)
53 53 plan_synchronize(); // Ensure coolant turns on when specified in program.
54 54 if (mode == COOLANT_FLOOD_ENABLE) {
55 55 COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
56   - #if ENABLE_M7
  56 + #ifdef ENABLE_M7
57 57 } else if (mode == COOLANT_MIST_ENABLE) {
58 58 COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
59 59 #endif
10 gcode.c
@@ -216,7 +216,7 @@ uint8_t gc_execute_line(char *line)
216 216 case 3: gc.spindle_direction = 1; break;
217 217 case 4: gc.spindle_direction = -1; break;
218 218 case 5: gc.spindle_direction = 0; break;
219   - #if ENABLE_M7
  219 + #ifdef ENABLE_M7
220 220 case 7: gc.coolant_mode = COOLANT_MIST_ENABLE; break;
221 221 #endif
222 222 case 8: gc.coolant_mode = COOLANT_FLOOD_ENABLE; break;
@@ -578,16 +578,16 @@ static int next_statement(char *letter, double *double_ptr, char *line, uint8_t
578 578 - Evaluation of expressions
579 579 - Variables
580 580 - Multiple home locations
581   - - Multiple coordinate systems (Up to 6 may be added via config.h)
582 581 - Probing
583 582 - Override control
584 583 - Tool changes
585   -
  584 +
  585 + (*) Indicates optional parameter, enabled through config.h and re-compile
586 586 group 0 = {G92.2, G92.3} (Non modal: Cancel and re-enable G92 offsets)
587 587 group 1 = {G38.2, G81 - G89} (Motion modes: straight probe, canned cycles)
588 588 group 6 = {M6} (Tool change)
589   - group 8 = {M7} coolant (M7 mist may be enabled via config.h)
  589 + group 8 = {*M7} enable mist coolant
590 590 group 9 = {M48, M49} enable/disable feed and speed override switches
591   - group 12 = {G55, G56, G57, G58, G59, G59.1, G59.2, G59.3} coordinate system selection
  591 + group 12 = {*G55, *G56, *G57, *G58, *G59, G59.1, G59.2, G59.3} coordinate system selection
592 592 group 13 = {G61, G61.1, G64} path control mode
593 593 */
26 stepper.c
@@ -91,7 +91,7 @@ static void st_wake_up()
91 91 // Initialize stepper output bits
92 92 out_bits = (0) ^ (settings.invert_mask);
93 93 // Initialize step pulse timing from settings. Here to ensure updating after re-writing.
94   - #if STEP_PULSE_DELAY > 0
  94 + #ifdef STEP_PULSE_DELAY
95 95 // Set total step pulse time after direction pin set. Ad hoc computation from oscilloscope.
96 96 step_pulse_time = -(((settings.pulse_microseconds+STEP_PULSE_DELAY-2)*TICKS_PER_MICROSECOND) >> 3);
97 97 // Set delay between direction pin write and step command.
@@ -113,7 +113,7 @@ void st_go_idle()
113 113 TIMSK1 &= ~(1<<OCIE1A);
114 114 // Force stepper dwell to lock axes for a defined amount of time to ensure the axes come to a complete
115 115 // stop and not drift from residual inertial forces at the end of the last movement.
116   - #if STEPPER_IDLE_LOCK_TIME > 0
  116 + #ifdef STEPPER_IDLE_LOCK_TIME
117 117 _delay_ms(STEPPER_IDLE_LOCK_TIME);
118 118 #endif
119 119 // Disable steppers by setting stepper disable
@@ -145,7 +145,7 @@ ISR(TIMER1_COMPA_vect)
145 145 // Set the direction pins a couple of nanoseconds before we step the steppers
146 146 STEPPING_PORT = (STEPPING_PORT & ~DIRECTION_MASK) | (out_bits & DIRECTION_MASK);
147 147 // Then pulse the stepping pins
148   - #if STEP_PULSE_DELAY > 0
  148 + #ifdef STEP_PULSE_DELAY
149 149 step_bits = (STEPPING_PORT & ~STEP_MASK) | out_bits; // Store out_bits to prevent overwriting.
150 150 #else // Normal operation
151 151 STEPPING_PORT = (STEPPING_PORT & ~STEP_MASK) | out_bits;
@@ -314,7 +314,7 @@ ISR(TIMER2_OVF_vect)
314 314 TCCR2B = 0; // Disable Timer2 to prevent re-entering this interrupt when it's not needed.
315 315 }
316 316
317   -#if STEP_PULSE_DELAY > 0
  317 +#ifdef STEP_PULSE_DELAY
318 318 // This interrupt is used only when STEP_PULSE_DELAY is enabled. Here, the step pulse is
319 319 // initiated after the STEP_PULSE_DELAY time period has elapsed. The ISR TIMER2_OVF interrupt
320 320 // will then trigger after the appropriate settings.pulse_microseconds, as in normal operation.
@@ -358,7 +358,7 @@ void st_init()
358 358 TCCR2B = 0; // Disable timer until needed.
359 359 TIMSK2 |= (1<<TOIE2);
360 360
361   - #if STEP_PULSE_DELAY > 0
  361 + #ifdef STEP_PULSE_DELAY
362 362 TIMSK2 |= (1<<OCIE2A); // Enable Timer2 Compare Match A interrupt
363 363 #endif
364 364
@@ -371,36 +371,36 @@ void st_init()
371 371 static uint32_t config_step_timer(uint32_t cycles)
372 372 {
373 373 uint16_t ceiling;
374   - uint16_t prescaler;
  374 + uint8_t prescaler;
375 375 uint32_t actual_cycles;
376 376 if (cycles <= 0xffffL) {
377 377 ceiling = cycles;
378   - prescaler = 0; // prescaler: 0
  378 + prescaler = 1; // prescaler: 0
379 379 actual_cycles = ceiling;
380 380 } else if (cycles <= 0x7ffffL) {
381 381 ceiling = cycles >> 3;
382   - prescaler = 1; // prescaler: 8
  382 + prescaler = 2; // prescaler: 8
383 383 actual_cycles = ceiling * 8L;
384 384 } else if (cycles <= 0x3fffffL) {
385 385 ceiling = cycles >> 6;
386   - prescaler = 2; // prescaler: 64
  386 + prescaler = 3; // prescaler: 64
387 387 actual_cycles = ceiling * 64L;
388 388 } else if (cycles <= 0xffffffL) {
389 389 ceiling = (cycles >> 8);
390   - prescaler = 3; // prescaler: 256
  390 + prescaler = 4; // prescaler: 256
391 391 actual_cycles = ceiling * 256L;
392 392 } else if (cycles <= 0x3ffffffL) {
393 393 ceiling = (cycles >> 10);
394   - prescaler = 4; // prescaler: 1024
  394 + prescaler = 5; // prescaler: 1024
395 395 actual_cycles = ceiling * 1024L;
396 396 } else {
397 397 // Okay, that was slower than we actually go. Just set the slowest speed
398 398 ceiling = 0xffff;
399   - prescaler = 4;
  399 + prescaler = 6;
400 400 actual_cycles = 0xffff * 1024;
401 401 }
402 402 // Set prescaler
403   - TCCR1B = (TCCR1B & ~(0x07<<CS10)) | ((prescaler+1)<<CS10);
  403 + TCCR1B = (TCCR1B & ~(0x07<<CS10)) | (prescaler<<CS10);
404 404 // Set ceiling
405 405 OCR1A = ceiling;
406 406 return(actual_cycles);

0 comments on commit 4224ab4

Please sign in to comment.
Something went wrong with that request. Please try again.