Evgeny
The PDB is useful for controlling sampling points but not for software delays.
See example in chapter 3 of http://www.utasker.com/docs/uTasker/uTaskerADC.pdf
For accurate software wait type delays you can use the SYSTICK. Here is the method used in the uTasker project to wait a defined number of microseconds.
extern void fnDelayLoop(unsigned long ulDelay_us)
{
#define CORE_US (CORE_CLOCK/1000000) // the number of core clocks in a us
register unsigned long ulPresentSystick;
register unsigned long ulMatch;
register unsigned long _ulDelay_us = ulDelay_us; // ensure that the compiler puts the variable in a register rather than work with it on the stack
if (_ulDelay_us == 0) { // minimum delay is 1us
_ulDelay_us = 1;
}
(void)SYSTICK_CSR; // clear the SysTick reload flag
ulMatch = (SYSTICK_CURRENT - CORE_US); // next 1us match value (SysTick counts down)
do {
while ((ulPresentSystick = SYSTICK_CURRENT) > ulMatch) { // wait until a us period has expired
if ((SYSTICK_CSR & SYSTICK_COUNTFLAG) != 0) { // if we missed a reload
(void)SYSTICK_CSR;
break; // assume a us period expired
}
}
ulMatch = (ulPresentSystick - CORE_US);
} while (--_ulDelay_us != 0);
}
This assumes that the SYSTICK is running but allows it to be shared with a SYSTICK periodic interrupt.
Regards
Mark