delay_us, delay_ms

This commit is contained in:
Todd Fleming
2017-01-07 23:30:48 -05:00
parent dec344fdb0
commit fdf6e31218
8 changed files with 78 additions and 45 deletions

View File

@ -40,6 +40,7 @@
// Define the Grbl system include files. NOTE: Do not alter organization.
#include "config.h"
#include "delay.h"
#include "nuts_bolts.h"
#include "settings.h"
#include "system.h"

View File

@ -88,6 +88,7 @@ volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bit
int main(void)
{
// Initialize system upon power-up.
delay_init(); // Setup delay timer
serial_init(); // Setup serial baud rate and interrupts
settings_init(); // Load Grbl settings from EEPROM
current_init(); // Configure stepper driver current

View File

@ -121,42 +121,11 @@ void delay_sec(float seconds, uint8_t mode)
protocol_exec_rt_system();
if (sys.suspend & SUSPEND_RESTART_RETRACT) { return; } // Bail, if safety door reopens.
}
_delay_ms(DWELL_TIME_STEP); // Delay DWELL_TIME_STEP increment
delay_ms(DWELL_TIME_STEP); // Delay DWELL_TIME_STEP increment
}
}
// Delays variable defined milliseconds. Compiler compatibility fix for _delay_ms(),
// which only accepts constants in future compiler releases.
void delay_ms(uint16_t ms)
{
while ( ms-- ) { _delay_ms(1); }
}
// Delays variable defined microseconds. Compiler compatibility fix for _delay_us(),
// which only accepts constants in future compiler releases. Written to perform more
// efficiently with larger delays, as the counter adds parasitic time in each iteration.
void delay_us(uint32_t us)
{
while (us) {
if (us < 10) {
_delay_us(1);
us--;
} else if (us < 100) {
_delay_us(10);
us -= 10;
} else if (us < 1000) {
_delay_us(100);
us -= 100;
} else {
_delay_ms(1);
us -= 1000;
}
}
}
// Simple hypotenuse computation function.
float hypot_f(float x, float y) { return(sqrt(x*x + y*y)); }

View File

@ -74,12 +74,6 @@ uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr);
// Non-blocking delay function used for general operation and suspend features.
void delay_sec(float seconds, uint8_t mode);
// Delays variable-defined milliseconds. Compiler compatibility fix for _delay_ms().
void delay_ms(uint16_t ms);
// Delays variable-defined microseconds. Compiler compatibility fix for _delay_us().
void delay_us(uint32_t us);
// Computes hypotenuse, avoiding avr-gcc's bloated version and the extra error checking.
float hypot_f(float x, float y);