Add macros for delays by machine cycle

master
Scott Lahteine 8 years ago
parent 4ea447959e
commit e02a5a6371

@ -39,6 +39,46 @@
// Clock speed factor // Clock speed factor
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20 #define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20
// Highly granular delays for step pulses, etc.
#define DELAY_0_NOP NOOP
#define DELAY_1_NOP __asm__("nop\n\t")
#define DELAY_2_NOP DELAY_1_NOP; DELAY_1_NOP
#define DELAY_3_NOP DELAY_1_NOP; DELAY_2_NOP
#define DELAY_4_NOP DELAY_1_NOP; DELAY_3_NOP
#define DELAY_5_NOP DELAY_1_NOP; DELAY_4_NOP
#define DELAY_NOPS(X) \
switch (X) { \
case 20: DELAY_1_NOP; case 19: DELAY_1_NOP; \
case 18: DELAY_1_NOP; case 17: DELAY_1_NOP; \
case 16: DELAY_1_NOP; case 15: DELAY_1_NOP; \
case 14: DELAY_1_NOP; case 13: DELAY_1_NOP; \
case 12: DELAY_1_NOP; case 11: DELAY_1_NOP; \
case 10: DELAY_1_NOP; case 9: DELAY_1_NOP; \
case 8: DELAY_1_NOP; case 7: DELAY_1_NOP; \
case 6: DELAY_1_NOP; case 5: DELAY_1_NOP; \
case 4: DELAY_1_NOP; case 3: DELAY_1_NOP; \
case 2: DELAY_1_NOP; case 1: DELAY_1_NOP; \
}
#define DELAY_10_NOP DELAY_5_NOP; DELAY_5_NOP
#define DELAY_20_NOP DELAY_10_NOP; DELAY_10_NOP
#if CYCLES_PER_MICROSECOND == 16
#define DELAY_1US DELAY_10_NOP; DELAY_5_NOP; DELAY_1_NOP
#else
#define DELAY_1US DELAY_20_NOP
#endif
#define DELAY_2US DELAY_1US; DELAY_1US
#define DELAY_3US DELAY_1US; DELAY_2US
#define DELAY_4US DELAY_1US; DELAY_3US
#define DELAY_5US DELAY_1US; DELAY_4US
#define DELAY_6US DELAY_1US; DELAY_5US
#define DELAY_7US DELAY_1US; DELAY_6US
#define DELAY_8US DELAY_1US; DELAY_7US
#define DELAY_9US DELAY_1US; DELAY_8US
#define DELAY_10US DELAY_1US; DELAY_9US
// Remove compiler warning on an unused variable // Remove compiler warning on an unused variable
#define UNUSED(x) (void) (x) #define UNUSED(x) (void) (x)

@ -82,7 +82,7 @@
// Say which 16 bit timers can be used and in what order // Say which 16 bit timers can be used and in what order
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
//#define _useTimer1 //#define _useTimer1 // Timer 1 is used by the stepper ISR
#define _useTimer3 #define _useTimer3
#define _useTimer4 #define _useTimer4
#if !HAS_MOTOR_CURRENT_PWM #if !HAS_MOTOR_CURRENT_PWM

@ -43,13 +43,6 @@
//set optimization so ARDUINO optimizes this file //set optimization so ARDUINO optimizes this file
#pragma GCC optimize (3) #pragma GCC optimize (3)
#define DELAY_0_NOP NOOP
#define DELAY_1_NOP __asm__("nop\n\t")
#define DELAY_2_NOP __asm__("nop\n\t" "nop\n\t")
#define DELAY_3_NOP __asm__("nop\n\t" "nop\n\t" "nop\n\t")
#define DELAY_4_NOP __asm__("nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t")
// If you want you can define your own set of delays in Configuration.h // If you want you can define your own set of delays in Configuration.h
//#define ST7920_DELAY_1 DELAY_0_NOP //#define ST7920_DELAY_1 DELAY_0_NOP
//#define ST7920_DELAY_2 DELAY_0_NOP //#define ST7920_DELAY_2 DELAY_0_NOP

Loading…
Cancel
Save