AVR Libc Home Page | AVR Libc Development Pages | ||||
Main Page | User Manual | Library Reference | FAQ | Alphabetical Index | Example Projects |
関数 | |
void | _delay_ms (double __ms) |
void | _delay_us (double __us) |
#define F_CPU 1000000UL // 1 MHz //#define F_CPU 14.7456E6 #include <util/delay.h>
#define
文を使用する必要はありません。このヘッダファイルの関数は、<util/delay_basic.h>で提供される基本的なbusy-wait関数のラッパーです。これらは、何サイクル待機するかではなく、実際の時間値を指定できる便利な関数になっています。アイディアの背景として、F_CPUマクロで渡されるCPU周波数から必要な遅延サイクル数を計算た浮動小数点表記は、コンパイル時の定数式としてコンパイラの最適化で除去されます。
使用できる関数は、アプリケーションに提供るF_CPUマクロのCPUクロック周波数(Hz)を用いることで、マイクロ秒とミリ秒の遅延を直接指定できるようになります。
void _delay_ms | ( | double | __ms ) |
_delay_loop_2()を使用して、__ms
ミリ秒の遅延を実行します。
F_CPUマクロは、CPUクロック周波数(Hz単位)で定数により定義されるものとします。
可能な最大遅延は、262.14ms / F_CPU(MHz)となります。
When the user request delay which exceed the maximum possible one, _delay_ms() provides a decreased resolution functionality. In this mode _delay_ms() will work with a resolution of 1/10 ms, providing delays up to 6.5535 seconds (independent from CPU frequency). The user will not be informed about decreased resolution.
If the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long) support, maximal possible delay is 4294967.295 ms/ F_CPU in MHz. For values greater than the maximal possible delay, overflows results in no delay i.e., 0ms.
Conversion of __us into clock cycles may not always result in integer. By default, the clock cycles rounded up to next integer. This ensures that the user gets atleast __us microseconds of delay.
Alternatively, user can define __DELAY_ROUND_DOWN__ and __DELAY_ROUND_CLOSEST__ to round down and round to closest integer.
Note: The new implementation of _delay_ms(double __ms) with __builtin_avr_delay_cycles(unsigned long) support is not backward compatible. User can define __DELAY_BACKWARD_COMPATIBLE__ to get a backward compatible delay although this will be deprecated in future.
void _delay_us | ( | double | __us ) |
Perform a delay of __us
microseconds, using _delay_loop_1().
The macro F_CPU is supposed to be defined to a constant defining the CPU clock frequency (in Hertz).
The maximal possible delay is 768 us / F_CPU in MHz.
If the user requests a delay greater than the maximal possible one, _delay_us() will automatically call _delay_ms() instead. The user will not be informed about this case.
If the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long) support, maximal possible delay is 4294967.295 us/ F_CPU in MHz. For values greater than the maximal possible delay, overflow results in no delay i.e., 0us.
Conversion of __us into clock cycles may not always result in integer. By default, the clock cycles rounded up to next integer. This ensures that the user gets atleast __us microseconds of delay.
Alternatively, user can define __DELAY_ROUND_DOWN__ and __DELAY_ROUND_CLOSEST__ to round down and round to closest integer.
Note: The new implementation of _delay_us(double __us) with __builtin_avr_delay_cycles(unsigned long) support is not backward compatible. User can define __DELAY_BACKWARD_COMPATIBLE__ to get a backward compatible delay although this will be deprecated in future.