Dear Alex, thanks for always share your knowleadge.
I found this routine below in assembly in other forum. I don't know how it works but could be used in any SAM D
Do you think I will get a nice acurracy ? So I can save one TC and memory space.
#ifndef F_CPU
#error CPU frequency not defined in sam_gpio.h // Taradov gpio definitions
#endif
#define _CyclesPerDelayLoop 6
#define _LoopCount_ms(ms) (uint32_t)(((F_CPU / 1000UL) * (ms)) / _CyclesPerDelayLoop)
#define _LoopCount_us(us) (uint32_t)(((F_CPU / 1000000UL) * (us)) / _CyclesPerDelayLoop)
#define ddDelay_ms(ms) _ddCycleDelay(_LoopCount_ms(ms))
#define ddDelay_us(us) _ddCycleDelay(_LoopCount_us(us))
inline void _ddCycleDelay(volatile uint32_t count) {
asm volatile (
"mov r0, %0 \n" // Get the loop count
"loop%=: \n" // Loop start label
"DMB \n" // Data Memory Barrier (3 cycles)
"sub r0, #1 \n" // Decrement count (1 cycle)
"bne loop%= \n" // Branch back to loop (2 cycles)
: // Nothing output from assembly
: "r" (count) // Register input for count
: "r0", "cc" // Clobber list
);
}