Can I use Programmable Delay Block (PDB) as a delay mechanism?
Say instead of
for (i = 0; i < delay; i++) ;
If so -is there some example?
Hi Evgeny Erenburg,
You can use Programmable Delay Block (PDB) as a delay mechanism.
Please download the MCUXpresso SDK_2.4.0 and find the delay_interrupt example.
All these hardware timer is able to achieve it.
Best Regards,
Robin
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thank you. MCUXpresso dosen't support my MK10FN1M0VLQ12.
Unfortunately, at the moment there is no plan to support this part number with SDK libraries.
Best Regards,
Robin
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
Thank you.