1 #ifndef SPEED_LOOKUPTABLE_H
2 #define SPEED_LOOKUPTABLE_H
6 extern const uint16_t speed_lookuptable_fast[256][2] PROGMEM;
7 extern const uint16_t speed_lookuptable_slow[256][2] PROGMEM;
12 FORCE_INLINE uint16_t MUL8x16R8(uint8_t x, uint16_t y) {
43 FORCE_INLINE uint16_t MUL24x24R24(__uint24 x, __uint24 y) {
91 :
"r0",
"r1",
"r26" ,
"r27"
98 FORCE_INLINE uint16_t MUL8x16R8(uint8_t charIn1, uint16_t intIn2)
100 return ((uint32_t)charIn1 * (uint32_t)intIn2) >> 8;
103 FORCE_INLINE uint16_t MUL24x24R24(uint32_t longIn1, uint32_t longIn2)
105 return ((uint64_t)longIn1 * (uint64_t)longIn2) >> 24;
111 FORCE_INLINE
unsigned short calc_timer(uint16_t step_rate, uint8_t& step_loops) {
113 if(step_rate > MAX_STEP_FREQUENCY) step_rate = MAX_STEP_FREQUENCY;
115 if(step_rate > 20000) {
116 step_rate = (step_rate >> 2)&0x3fff;
119 else if(step_rate > 10000) {
120 step_rate = (step_rate >> 1)&0x7fff;
127 if(step_rate < (F_CPU/500000)) step_rate = (F_CPU/500000);
128 step_rate -= (F_CPU/500000);
129 if(step_rate >= (8*256)){
130 unsigned short table_address = (
unsigned short)&speed_lookuptable_fast[(
unsigned char)(step_rate>>8)][0];
131 unsigned char tmp_step_rate = (step_rate & 0x00ff);
132 uint16_t gain = (uint16_t)pgm_read_word_near(table_address+2);
133 timer = (
unsigned short)pgm_read_word_near(table_address) - MUL8x16R8(tmp_step_rate, gain);
136 unsigned short table_address = (
unsigned short)&speed_lookuptable_slow[0][0];
137 table_address += ((step_rate)>>1) & 0xfffc;
138 timer = (
unsigned short)pgm_read_word_near(table_address);
139 timer -= (((
unsigned short)pgm_read_word_near(table_address+2) * (
unsigned char)(step_rate & 0x0007))>>3);
141 if(timer < 100) { timer = 100; }