AnsweredAssumed Answered

DWT_CYCCNT -- explanation

Question asked by emb_begin on Dec 8, 2015
Latest reply on Dec 8, 2015 by Clive One
Hi 
i have seen the below code on this forum. for example if i wnt to make a delay for 10 seconds then how to calculate the tick value.?
Can anyone help ?.



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)
{
    static int enabled = 0;
    if (!enabled)
    {
        *SCB_DEMCR = *SCB_DEMCR | 0x01000000;
        *DWT_CYCCNT = 0; // reset the counter
        *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter

        enabled = 1;
    }
}

void TimeDelay(unsigned int tick)
{
    unsigned int start, current;
    start = *DWT_CYCCNT;
    do
    {
        current = *DWT_CYCCNT;
    } while((current - start) < tick);
}

Outcomes