Comparison of various delay methods(转载)
(1) risc_sleep_a_bit(n)
- accuracy within ~13ns when n>20.
- limitation: n < cycles in timer2_period (0.5 second).
(2) "bank3safe"
- accuracy within bank3 WS, ~100ns(byte access)
- usage example:
void foo(void)
{
volatile unsigned int *ptrdelay = (unsigned int *) bank3safe;
.
.
(void) *ptrdelay; /* DW access = ~400ns(4*100) delay */
.
.
}
(3) UTIL_xxx_timer2_end()
- accuracy is similar to risc_sleep_a_bit(), but intended for delays
greater than ~1us.
- usage example:
(please reference SERVO_delay_n_ms() in servos.c or
VFD_schedule_state_change() in microvfd.c)
(4) "glbTimer"
- accuracy within ~200ms - ~500ms depending on frequency of
"glbTimer" checks.
NOTE: pure "for" loops are NOT reliable delay methods because of
cache hit/miss inconsistencies.