How to implement in-line assembly "for" loop in Arduino for faster delayMicros function -


i'm trying make more precise version of arduino's delaymicroseconds() function, ultimate goal being square-wave generator frequency can varied 100 khz precision of 0.2 khz.

based on resources found online, best attempt:

  __asm__ ("mov eax, $x");   __asm__("beginning:");   __asm__("inc eax");   __asm__("cmp eax, 0x0a");   __asm__("jne beginning");   __asm__("mov $x, eax"); 

i inputted above code arduino ide , hit "verify;" following error messages appeared:

arduino: 1.6.4 (windows 7), board: "arduino uno"  c:\users\212455~1\appdata\local\temp\ccindaw0.s: assembler messages: c:\users\212455~1\appdata\local\temp\ccindaw0.s:46: error: constant value required  c:\users\212455~1\appdata\local\temp\ccindaw0.s:46: error: constant value required c:\users\212455~1\appdata\local\temp\ccindaw0.s:46: error: unknown opcode `x' c:\users\212455~1\appdata\local\temp\ccindaw0.s:54: error: constant value required c:\users\212455~1\appdata\local\temp\ccindaw0.s:58: error: unknown opcode `cmp' c:\users\212455~1\appdata\local\temp\ccindaw0.s:62: error: unknown opcode `jne' c:\users\212455~1\appdata\local\temp\ccindaw0.s:66: error: constant value required c:\users\212455~1\appdata\local\temp\ccindaw0.s:66: error: `,' required c:\users\212455~1\appdata\local\temp\ccindaw0.s:66: error: constant value required c:\users\212455~1\appdata\local\temp\ccindaw0.s:66: error: garbage @ end of line c:\users\212455~1\appdata\local\temp\ccindaw0.s:66: error: unknown opcode `x' error compiling.  report have more information "show verbose output during compilation" enabled in file > preferences. 

what should do?

use _delay_loop_1() and/or _delay_loop_2(), avr-libc. first 1 can count 256 , takes 3 cycles per iteration, maximum of 768 cycles. second 1 counts 65536 , takes 4 cycles per iteration, maximum of 262144 cycles.

if @ header file util/delay_basic.h, see these implemented simple inline assembly (2 instructions each).


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -