System ticks

February 6, 2013

Examples
Soft timer: In the last article, one of the interfaces I mentioned is the interface to acquire a system clock tick counter for the soft timer. Listing 5 shows the code modified to use the SYSTICK timer service counter. In this example, I use the 1 millisecond update counter. Also, I've commented out the code I showed you in the last article so you can see how the new interface works.


#define __SYSRETRIEVE_CLOCK_C
/****************************************************************************/
/*    FILE: sysRetrieveClock.c                                              */
/*                                                                          */
/*    A general purpose C/C++ timer object                                  */
/*                                                                          */
/*    BY:   Ken Wada                                                        */
/*          Aurora Networks Inc.                                            */
/*          12-January-2010                                                 */
/*                                                                          */
/****************************************************************************/
#include  "h\gptimer.h"

//extern volatile unsigned long my_system_tick;
extern volatile unsigned long  SysTick_1ms;

/****************************************************************************/
/*                            CODE STARTS HERE                              */
/****************************************************************************/
unsigned long sysRetrieveClock (void)
{
//    return (my_system_tick);
    return (SysTick_1ms);
}

Listing 5: An example of how to use the 1 millisecond counter.

One can also get a micro-seconds elapsed count using the SYSTICK interface. Doing this requires one of the interface functions I mentioned earlier in this article. The interface function is:

Retrieving the elapsed microseconds: Many times, a small amount of delay is required in order to synchronize some other process. Usually this can be anything from a small amount of delay required to allow an analog-to-digital converter (ADC) reading to settle or to add some latency to a bit-bang interface. Many times, this delay is implemented via some code as follows:

void sw_delay (int count)
{
    while (count>0)
    {
      --count;
    }
}

There are some issues with this type of delay, some of which are:
  1. The delay can vary from call to call based on interrupts and on some processors cache and pipeline variances.
  2. The count parameter needs to be varied based on the processor timing and system clock settings.

< Previous
Page 4 of 5
Next >

Loading comments...

Parts Search Datasheets.com

KNOWLEDGE CENTER