counting every 1micro seconds using systick

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

counting every 1micro seconds using systick

1,133 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by black_ghost on Wed Oct 19 23:38:18 MST 2011
Hi everyone i am trying to use the systick timer as a delay functiion. i looked at the examples from the library and found the systick timer counting every 1ms. but i also want to use systick to count every 1us. does anyone have an idea. i am using lpc1769 by the way. i was thinking calling of using another systick handler or dividing by 1E6  again but dont think thats a right approach. 

volatile uint32_t msTicks;

void SysTick_Handler(void)
{
    msTicks++;
}
static void ms_delay(uint32_t delayTicks)
{
    uint32_t currentTicks;
    currentTicks = msTicks;
    while ((msTicks-currentTicks)<delayTicks);
}

int main()
{
    if (SysTick_Config(SystemFrequency / 1000)) // counts every 1ms
    {
    while (1);
    }
}
0 Kudos
Reply
2 Replies

996 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ToBeFrank on Fri Oct 21 15:43:46 MST 2011

Quote: black_ghost
Hi everyone i am trying to use the systick timer as a delay functiion. i looked at the examples from the library and found the systick timer counting every 1ms. but i also want to use systick to count every 1us.



If you want a delay with microsecond resolution, use a timer, not the systick.
0 Kudos
Reply

996 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Fri Oct 21 06:03:03 MST 2011
1us is extremely short if you need to take into account the overhead from the ISR, and any additional processing that you need to do, etc.  At 100 MHz 1us leaves you 100 clock cycles between each 'tick'.  That's not a lot if you need to do anything else.
0 Kudos
Reply