delay_us, delay_ms
This commit is contained in:
parent
dec344fdb0
commit
fdf6e31218
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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)); }
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -289,9 +289,9 @@
|
||||
#define PLL1CFG_Val 0x00000023
|
||||
#define CCLKCFG_Val 0x00000003
|
||||
#define USBCLKCFG_Val 0x00000000
|
||||
#define PCLKSEL0_Val 0x00000000
|
||||
#define PCLKSEL1_Val 0x00000000
|
||||
#define PCONP_Val 0x042887DE
|
||||
#define PCLKSEL0_Val 0x00000014
|
||||
#define PCLKSEL1_Val 0x00005000
|
||||
#define PCONP_Val 0x04E887DE
|
||||
#define CLKOUTCFG_Val 0x00000000
|
||||
|
||||
|
||||
@ -321,7 +321,7 @@
|
||||
// </e>
|
||||
*/
|
||||
#define FLASH_SETUP 1
|
||||
#define FLASHCFG_Val 0x0000303A
|
||||
#define FLASHCFG_Val 0x0000503A
|
||||
|
||||
/*
|
||||
//-------- <<< end of configuration section >>> ------------------------------
|
||||
|
32
smoother/delay.cpp
Normal file
32
smoother/delay.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright 2017 Todd Fleming
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
|
||||
#include "delay.h"
|
||||
|
||||
void delay_init()
|
||||
{
|
||||
LPC_TIM3->CTCR = 0; // timer mode
|
||||
LPC_TIM3->PR = 0; // no prescale
|
||||
LPC_TIM3->MCR = 0; // no MR actions
|
||||
LPC_TIM3->CCR = 0; // no capture
|
||||
LPC_TIM3->EMR = 0; // no external match
|
||||
LPC_TIM3->TCR = 0b10; // reset
|
||||
LPC_TIM3->TCR = 0b01; // enable
|
||||
}
|
38
smoother/delay.h
Normal file
38
smoother/delay.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
// Copyright 2017 Todd Fleming
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
|
||||
#include "LPC17xx.h"
|
||||
|
||||
void delay_init();
|
||||
|
||||
inline void delay_us(uint32_t us)
|
||||
{
|
||||
uint32_t start = LPC_TIM3->TC;
|
||||
uint32_t cycles = uint32_t(uint64_t(SystemCoreClock) * us / 1000000);
|
||||
while (LPC_TIM3->TC - start < cycles)
|
||||
;
|
||||
}
|
||||
|
||||
inline void delay_ms(uint32_t ms)
|
||||
{
|
||||
return delay_us(ms * 1000);
|
||||
}
|
@ -1,3 +1 @@
|
||||
#define F_CPU 1000000UL
|
||||
inline void _delay_ms(double) {}
|
||||
inline void _delay_us(double) {}
|
||||
#define F_CPU SystemCoreClock
|
||||
|
Loading…
Reference in New Issue
Block a user