123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #ifndef SPEED_LOOKUPTABLE_H
- #define SPEED_LOOKUPTABLE_H
- #include "Marlin.h"
- extern const uint16_t speed_lookuptable_fast[256][2] PROGMEM;
- extern const uint16_t speed_lookuptable_slow[256][2] PROGMEM;
- #ifndef _NO_ASM
- FORCE_INLINE uint16_t MUL8x16R8(uint8_t x, uint16_t y) {
- uint16_t out;
- __asm__ (
-
-
-
-
-
-
-
-
-
-
-
-
-
- "mul %B2, %A1" "\n\t"
- "movw %0, r0" "\n\t"
- "mul %A2, %A1" "\n\t"
- "lsl r0" "\n\t"
- "adc %A0, r1" "\n\t"
- "clr r1" "\n\t"
- "adc %B0, r1" "\n\t"
- : "=&r" (out)
- : "r" (x), "r" (y)
- : "r0", "r1"
- );
- return out;
- }
- FORCE_INLINE uint16_t MUL24x24R24(__uint24 x, __uint24 y) {
- uint16_t out;
- __asm__ (
-
-
-
-
-
-
-
-
-
-
-
-
-
- "clr r26 \n\t"
- "mul %A1, %B2 \n\t"
- "mov r27, r1 \n\t"
- "mul %B1, %C2 \n\t"
- "movw %A0, r0 \n\t"
- "mul %C1, %C2 \n\t"
- "add %B0, r0 \n\t"
- "mul %C1, %B2 \n\t"
- "add %A0, r0 \n\t"
- "adc %B0, r1 \n\t"
- "mul %A1, %C2 \n\t"
- "add r27, r0 \n\t"
- "adc %A0, r1 \n\t"
- "adc %B0, r26 \n\t"
- "mul %B1, %B2 \n\t"
- "add r27, r0 \n\t"
- "adc %A0, r1 \n\t"
- "adc %B0, r26 \n\t"
- "mul %C1, %A2 \n\t"
- "add r27, r0 \n\t"
- "adc %A0, r1 \n\t"
- "adc %B0, r26 \n\t"
- "mul %B1, %A2 \n\t"
- "add r27, r1 \n\t"
- "adc %A0, r26 \n\t"
- "adc %B0, r26 \n\t"
- "lsl r27 \n\t"
- "adc %A0, r26 \n\t"
- "adc %B0, r26 \n\t"
- "clr r1 \n\t"
- : "=&r" (out)
- : "r" (x), "r" (y)
- : "r0", "r1", "r26" , "r27"
- );
- return out;
- }
- #else
- FORCE_INLINE uint16_t MUL8x16R8(uint8_t charIn1, uint16_t intIn2)
- {
- return ((uint32_t)charIn1 * (uint32_t)intIn2) >> 8;
- }
- FORCE_INLINE uint16_t MUL24x24R24(uint32_t longIn1, uint32_t longIn2)
- {
- return ((uint64_t)longIn1 * (uint64_t)longIn2) >> 24;
- }
- #endif
- FORCE_INLINE unsigned short calc_timer(uint16_t step_rate, uint8_t& step_loops) {
- uint16_t timer;
- if(step_rate > MAX_STEP_FREQUENCY) step_rate = MAX_STEP_FREQUENCY;
- if(step_rate > 20000) {
- step_rate = (step_rate >> 2)&0x3fff;
- step_loops = 4;
- }
- else if(step_rate > 10000) {
- step_rate = (step_rate >> 1)&0x7fff;
- step_loops = 2;
- }
- else {
- step_loops = 1;
- }
- if(step_rate < (F_CPU/500000)) step_rate = (F_CPU/500000);
- step_rate -= (F_CPU/500000);
- if(step_rate >= (8*256)){
- unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate>>8)][0];
- unsigned char tmp_step_rate = (step_rate & 0x00ff);
- uint16_t gain = (uint16_t)pgm_read_word_near(table_address+2);
- timer = (unsigned short)pgm_read_word_near(table_address) - MUL8x16R8(tmp_step_rate, gain);
- }
- else {
- unsigned short table_address = (unsigned short)&speed_lookuptable_slow[0][0];
- table_address += ((step_rate)>>1) & 0xfffc;
- timer = (unsigned short)pgm_read_word_near(table_address);
- timer -= (((unsigned short)pgm_read_word_near(table_address+2) * (unsigned char)(step_rate & 0x0007))>>3);
- }
- if(timer < 100) { timer = 100; }
- return timer;
- }
- #endif
|