C Language Development Kit/Functions/GetTickCount

From OptiWiki

Jump to: navigation, search
Description This function returns the number of timer ticks that have occured since to start-up of the Operating System. If the timer reaches 65535 ticks it automatically resets back to 0.

This function makes it possible to create multiple timed processes that run simultaneously in an application.

unsigned int GetTickCount(void);
Arguments None
Returns Returns the number of timer ticks that have occured since to start-up of the Operating System.

The duration of 1 timer tick depends on the type of terminal.

  • 1 timer tick on the PHLxxxx takes 10 milliseconds.
  • 1 timer tick on the OPH100x, OPL97xx and DCL153x takes 20 milliseconds.

For example, 1 seconds on an OPH100x, OPL97xx or DCL153x takes 50 timer ticks, while 1 second on a PHLxxx takes 100 timer ticks.

The system timer has a range of 0 to 4294967295, which means the timer can almost run for about 1000 days on a OPH100x, OPL97xx or DCL153x and about 500 days on a PHLxxxx, before it resets to zero.

Remarks The timer tick counter can not be (re)set to a specific value.

The system timer has a range of 0 to 65535, which means the timer will reset to zero about every 22 minutes on a OPH100x, OPL97xx and DCL153x and about every 11 minutes on a PHLxxxx.

If the manual (re)setting of the timer is required or a timer is needed that doesn't reset to zero every 11 or 22 minutes, use the timer of the GetSystemTime() function.

When only 1 timer is needed in your application, it's better to use the starttimer() function.

#include "lib.h"
#include <stdio.h>
#define HIGH_DELAY      13 * 5       //Note that these are prime numbers
#define MEDIUM_DELAY    23 * 5
#define LOW_DELAY       37 * 5
void main( void )
    unsigned long current_time;
    unsigned long next_high_time;
    unsigned long next_medium_time;
    unsigned long next_low_time;
    current_time = GetTickCount();
    next_high_time = current_time + HIGH_DELAY;
    next_medium_time = current_time + MEDIUM_DELAY;
    next_low_time = current_time + LOW_DELAY;
    setfont(SMALL_FONT, NULL);
    printf("\f3 independent\ntimers using\nGetTickCount");
    while( 1 )
        //Detect timer reset after 655535 ticks
        if(current_time > GetTickCount())
            next_high_time = HIGH_DELAY;
            next_medium_time = MEDIUM_DELAY;
            next_low_time = LOW_DELAY;
        current_time = GetTickCount();
            sound( TSTANDARD, VSTANDARD, SLOW, 0);
            next_low_time += LOW_DELAY;
            sound( TSTANDARD, VSTANDARD, SMEDIUM, 0);
            next_medium_time += MEDIUM_DELAY;
            sound( TSTANDARD, VSTANDARD, SHIGH, 0);
            next_high_time += HIGH_DELAY;

Personal tools