2015-08-17 09:45 AM
Hello everyone !! I have a
http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF260320
and use IAR with .How can I implement
a
delay
with
HAL
in
us (microseconds)
?
Please give us some hints. Best Regards #microseconds #nucleo #hal2015-08-17 10:36 AM
I think this question has been asked multiple times here.
You can't expect the processor to interrupt, and increment a variable at 1 MHz. What you need to do is use a free-running counter, either the TIM or DWT_CYCCNT one to mark brief amounts of time. One millisecond is SystemCoreClock / 1000, one microsecond is SystemCoreClock / 1000000For delays that relate to the CPU clock speed, consider using DWT_CYCCNT
//******************************************************************************
volatile unsigned int *DWT_CYCCNT = (volatile unsigned int *)0xE0001004; //address of the register
volatile unsigned int *DWT_CONTROL = (volatile unsigned int *)0xE0001000; //address of the register
volatile unsigned int *SCB_DEMCR = (volatile unsigned int *)0xE000EDFC; //address of the register
//******************************************************************************
void EnableTiming(void)
{
*SCB_DEMCR = *SCB_DEMCR | 0x01000000;
*DWT_CYCCNT = 0; // reset the counter
*DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter
}
//******************************************************************************
void TimingDelay(unsigned int tick)
{
unsigned int start, current;
start = *DWT_CYCCNT;
do
{
current = *DWT_CYCCNT;
} while((current - start) < tick);
}
//******************************************************************************
2015-08-18 08:53 AM
Fantastic
Clive, it works. Thanks for your help.